Skip to content

Commit

Permalink
regulator: Fix deadlock during regulator registration
Browse files Browse the repository at this point in the history
Commit 5e3ca2b ("regulator: Try to resolve regulators supplies on
registration") added a call to regulator_resolve_supply() within
regulator_register() where the regulator_list_mutex is held. This causes
a deadlock to occur on the Tegra114 Dalmore board when the palmas PMIC
is registered because regulator_register_resolve_supply() calls
regulator_dev_lookup() which may try to acquire the regulator_list_mutex
again.

Fix this by releasing the mutex before calling
regulator_register_resolve_supply() and update the error exit path to
ensure the mutex is released on an error.

[Made commit message more legible -- broonie]

Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Jon Hunter authored and Mark Brown committed Mar 30, 2016
1 parent 5e3ca2b commit a215137
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/regulator/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3991,12 +3991,11 @@ regulator_register(const struct regulator_desc *regulator_desc,
}

rdev_init_debugfs(rdev);
mutex_unlock(&regulator_list_mutex);

/* try to resolve regulators supply since a new one was registered */
class_for_each_device(&regulator_class, NULL, NULL,
regulator_register_resolve_supply);
out:
mutex_unlock(&regulator_list_mutex);
kfree(config);
return rdev;

Expand All @@ -4007,15 +4006,16 @@ regulator_register(const struct regulator_desc *regulator_desc,
regulator_ena_gpio_free(rdev);
device_unregister(&rdev->dev);
/* device core frees rdev */
rdev = ERR_PTR(ret);
goto out;

wash:
regulator_ena_gpio_free(rdev);
clean:
kfree(rdev);
rdev = ERR_PTR(ret);
goto out;
out:
mutex_unlock(&regulator_list_mutex);
kfree(config);
return ERR_PTR(ret);
}
EXPORT_SYMBOL_GPL(regulator_register);

Expand Down

0 comments on commit a215137

Please sign in to comment.