Commit e1794aa4 authored by Saravana Kannan's avatar Saravana Kannan Committed by Mark Brown

regulator: core: Add destroy_regulator()

Part of the regulator_get() code is already factored out into
create_regulator(). This patch factors out some of the regulator_put()
code into destroy_regulator() so that create_regulator() has a
corresponding unwind function. Subsequent patches will use this
function.
Signed-off-by: default avatarSaravana Kannan <saravanak@google.com>
Link: https://lore.kernel.org/r/20200716042053.1927676-3-saravanak@google.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent a98bcaa9
...@@ -105,6 +105,7 @@ static int regulator_balance_voltage(struct regulator_dev *rdev, ...@@ -105,6 +105,7 @@ static int regulator_balance_voltage(struct regulator_dev *rdev,
static struct regulator *create_regulator(struct regulator_dev *rdev, static struct regulator *create_regulator(struct regulator_dev *rdev,
struct device *dev, struct device *dev,
const char *supply_name); const char *supply_name);
static void destroy_regulator(struct regulator *regulator);
static void _regulator_put(struct regulator *regulator); static void _regulator_put(struct regulator *regulator);
const char *rdev_get_name(struct regulator_dev *rdev) const char *rdev_get_name(struct regulator_dev *rdev)
...@@ -2034,20 +2035,9 @@ struct regulator *regulator_get_optional(struct device *dev, const char *id) ...@@ -2034,20 +2035,9 @@ struct regulator *regulator_get_optional(struct device *dev, const char *id)
} }
EXPORT_SYMBOL_GPL(regulator_get_optional); EXPORT_SYMBOL_GPL(regulator_get_optional);
/* regulator_list_mutex lock held by regulator_put() */ static void destroy_regulator(struct regulator *regulator)
static void _regulator_put(struct regulator *regulator)
{ {
struct regulator_dev *rdev; struct regulator_dev *rdev = regulator->rdev;
if (IS_ERR_OR_NULL(regulator))
return;
lockdep_assert_held_once(&regulator_list_mutex);
/* Docs say you must disable before calling regulator_put() */
WARN_ON(regulator->enable_count);
rdev = regulator->rdev;
debugfs_remove_recursive(regulator->debugfs); debugfs_remove_recursive(regulator->debugfs);
...@@ -2068,6 +2058,24 @@ static void _regulator_put(struct regulator *regulator) ...@@ -2068,6 +2058,24 @@ static void _regulator_put(struct regulator *regulator)
kfree_const(regulator->supply_name); kfree_const(regulator->supply_name);
kfree(regulator); kfree(regulator);
}
/* regulator_list_mutex lock held by regulator_put() */
static void _regulator_put(struct regulator *regulator)
{
struct regulator_dev *rdev;
if (IS_ERR_OR_NULL(regulator))
return;
lockdep_assert_held_once(&regulator_list_mutex);
/* Docs say you must disable before calling regulator_put() */
WARN_ON(regulator->enable_count);
rdev = regulator->rdev;
destroy_regulator(regulator);
module_put(rdev->owner); module_put(rdev->owner);
put_device(&rdev->dev); put_device(&rdev->dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment