Skip to contentSkip to conversation

regulator: gpio-regulator: use devm_*

PATCH In review Rob Jones 2 participants 2 messages May 22, 2014

Subsystems (2)
lore
Share & tools
lore

Rob Jones

author
#0 lore raw

PATCH 1/1 regulator: gpio-regulator: use devm_*

Use devm_regulator_register in probe/remove.

---
 drivers/regulator/gpio-regulator.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/regulator/gpio-regulator.c +1 -3
index 989b23b..994a050 100644
@@ -337,7 +337,7 @@ static int gpio_regulator_probe(struct platform_device *pdev)
 			cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
 	}
 
-	drvdata->dev = regulator_register(&drvdata->desc, &cfg);
+	drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc, &cfg);
 	if (IS_ERR(drvdata->dev)) {
 		ret = PTR_ERR(drvdata->dev);
 		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
@@ -364,8 +364,6 @@ static int gpio_regulator_remove(struct platform_device *pdev)
 {
 	struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev);
 
-	regulator_unregister(drvdata->dev);
-
 	gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
 
 	kfree(drvdata->states);
Signature · 1 line
1.7.10.4
#1 lore raw

Hi Rob,

this is racy.

The deallocation of devm_* stuff is done _after_ the driver _remove callback ran, where in the gpio_regulator case it would already have done at least

drivers/regulator/gpio-regulator.c static int gpio_regulator_remove(struct platform_device *pdev) · line 369

Quoted 3 lines
drivers/regulator/gpio-regulator.c +0 -0
 	gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
 
 	kfree(drvdata->states);

before the regulator gets deregistered, thus producing a race condition.

Also Mark's mail address is
Mark Brown <[email protected]>
and
[email protected]
should be included as well.

Heiko

Am Donnerstag, 22. Mai 2014, 15:51:06 schrieb Rob Jones:

Quoted 30 lines

Use devm_regulator_register in probe/remove.

---
 drivers/regulator/gpio-regulator.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/regulator/gpio-regulator.c index 989b23b..994a050 100644

drivers/regulator/gpio-regulator.c +1 -3
@@ -337,7 +337,7 @@ static int gpio_regulator_probe(struct platform_device
 *pdev) cfg.ena_gpio_flags |= GPIOF_OUT_INIT_HIGH;
 	}
 
-	drvdata->dev = regulator_register(&drvdata->desc, &cfg);
+	drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc, &cfg);
 	if (IS_ERR(drvdata->dev)) {
 		ret = PTR_ERR(drvdata->dev);
 		dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
@@ -364,8 +364,6 @@ static int gpio_regulator_remove(struct platform_device
 *pdev) {
 	struct gpio_regulator_data *drvdata = platform_get_drvdata(pdev);
 
-	regulator_unregister(drvdata->dev);
-
 	gpio_free_array(drvdata->gpios, drvdata->nr_gpios);
 
 	kfree(drvdata->states);