aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator/core.c
diff options
context:
space:
mode:
authorJon Hunter <jonathanh@nvidia.com>2016-04-21 12:11:59 -0400
committerMark Brown <broonie@kernel.org>2016-04-22 06:38:47 -0400
commitc438b9d017362b65f6b1a9e54f7f35e7f873dc7c (patch)
tree9ba4ac5fe0000d1b1ba483f6772accfd6dde58b8 /drivers/regulator/core.c
parentf89ba3383ee69e2e1473e41ed42614fc7c9d9192 (diff)
regulator: core: Move registration of regulator device
The public functions to acquire a regulator, such as regulator_get(), internally look-up the regulator from the list of regulators that have been registered with the regulator device class. The registration of a new regulator with the regulator device class happens before the regulator has been completely setup. Therefore, it is possible that the regulator could be acquired before it has been setup successfully. To avoid this move the device registration of the regulator to the end of the regulator setup and update the error exit path accordingly. Signed-off-by: Jon Hunter <jonathanh@nvidia.com> Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator/core.c')
-rw-r--r--drivers/regulator/core.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index a17ce6cbbe77..8362a0a5105d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3970,14 +3970,6 @@ regulator_register(const struct regulator_desc *regulator_desc,
3970 if (ret < 0) 3970 if (ret < 0)
3971 goto wash; 3971 goto wash;
3972 3972
3973 ret = device_register(&rdev->dev);
3974 if (ret != 0) {
3975 put_device(&rdev->dev);
3976 goto wash;
3977 }
3978
3979 dev_set_drvdata(&rdev->dev, rdev);
3980
3981 if (init_data && init_data->supply_regulator) 3973 if (init_data && init_data->supply_regulator)
3982 rdev->supply_name = init_data->supply_regulator; 3974 rdev->supply_name = init_data->supply_regulator;
3983 else if (regulator_desc->supply_name) 3975 else if (regulator_desc->supply_name)
@@ -3997,9 +3989,17 @@ regulator_register(const struct regulator_desc *regulator_desc,
3997 } 3989 }
3998 } 3990 }
3999 3991
4000 rdev_init_debugfs(rdev);
4001 mutex_unlock(&regulator_list_mutex); 3992 mutex_unlock(&regulator_list_mutex);
4002 3993
3994 ret = device_register(&rdev->dev);
3995 if (ret != 0) {
3996 put_device(&rdev->dev);
3997 goto unset_supplies;
3998 }
3999
4000 dev_set_drvdata(&rdev->dev, rdev);
4001 rdev_init_debugfs(rdev);
4002
4003 /* try to resolve regulators supply since a new one was registered */ 4003 /* try to resolve regulators supply since a new one was registered */
4004 class_for_each_device(&regulator_class, NULL, NULL, 4004 class_for_each_device(&regulator_class, NULL, NULL,
4005 regulator_register_resolve_supply); 4005 regulator_register_resolve_supply);
@@ -4008,17 +4008,11 @@ regulator_register(const struct regulator_desc *regulator_desc,
4008 4008
4009unset_supplies: 4009unset_supplies:
4010 unset_regulator_supplies(rdev); 4010 unset_regulator_supplies(rdev);
4011 regulator_ena_gpio_free(rdev);
4012 device_unregister(&rdev->dev);
4013 /* device core frees rdev */
4014 goto out;
4015
4016wash: 4011wash:
4017 kfree(rdev->constraints); 4012 kfree(rdev->constraints);
4018 regulator_ena_gpio_free(rdev); 4013 regulator_ena_gpio_free(rdev);
4019clean: 4014clean:
4020 kfree(rdev); 4015 kfree(rdev);
4021out:
4022 mutex_unlock(&regulator_list_mutex); 4016 mutex_unlock(&regulator_list_mutex);
4023 kfree(config); 4017 kfree(config);
4024 return ERR_PTR(ret); 4018 return ERR_PTR(ret);