aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/regulator/core.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index e225711bb8bc..c13b557a560e 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3581,20 +3581,21 @@ static void rdev_init_debugfs(struct regulator_dev *rdev)
3581 */ 3581 */
3582struct regulator_dev * 3582struct regulator_dev *
3583regulator_register(const struct regulator_desc *regulator_desc, 3583regulator_register(const struct regulator_desc *regulator_desc,
3584 const struct regulator_config *config) 3584 const struct regulator_config *cfg)
3585{ 3585{
3586 const struct regulation_constraints *constraints = NULL; 3586 const struct regulation_constraints *constraints = NULL;
3587 const struct regulator_init_data *init_data; 3587 const struct regulator_init_data *init_data;
3588 struct regulator_config *config = NULL;
3588 static atomic_t regulator_no = ATOMIC_INIT(0); 3589 static atomic_t regulator_no = ATOMIC_INIT(0);
3589 struct regulator_dev *rdev; 3590 struct regulator_dev *rdev;
3590 struct device *dev; 3591 struct device *dev;
3591 int ret, i; 3592 int ret, i;
3592 const char *supply = NULL; 3593 const char *supply = NULL;
3593 3594
3594 if (regulator_desc == NULL || config == NULL) 3595 if (regulator_desc == NULL || cfg == NULL)
3595 return ERR_PTR(-EINVAL); 3596 return ERR_PTR(-EINVAL);
3596 3597
3597 dev = config->dev; 3598 dev = cfg->dev;
3598 WARN_ON(!dev); 3599 WARN_ON(!dev);
3599 3600
3600 if (regulator_desc->name == NULL || regulator_desc->ops == NULL) 3601 if (regulator_desc->name == NULL || regulator_desc->ops == NULL)
@@ -3624,6 +3625,16 @@ regulator_register(const struct regulator_desc *regulator_desc,
3624 if (rdev == NULL) 3625 if (rdev == NULL)
3625 return ERR_PTR(-ENOMEM); 3626 return ERR_PTR(-ENOMEM);
3626 3627
3628 /*
3629 * Duplicate the config so the driver could override it after
3630 * parsing init data.
3631 */
3632 config = kmemdup(cfg, sizeof(*cfg), GFP_KERNEL);
3633 if (config == NULL) {
3634 kfree(rdev);
3635 return ERR_PTR(-ENOMEM);
3636 }
3637
3627 init_data = regulator_of_get_init_data(dev, regulator_desc, 3638 init_data = regulator_of_get_init_data(dev, regulator_desc,
3628 &rdev->dev.of_node); 3639 &rdev->dev.of_node);
3629 if (!init_data) { 3640 if (!init_data) {
@@ -3752,6 +3763,7 @@ add_dev:
3752 rdev_init_debugfs(rdev); 3763 rdev_init_debugfs(rdev);
3753out: 3764out:
3754 mutex_unlock(&regulator_list_mutex); 3765 mutex_unlock(&regulator_list_mutex);
3766 kfree(config);
3755 return rdev; 3767 return rdev;
3756 3768
3757unset_supplies: 3769unset_supplies: