linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regulator: gpio-regulator: use devm_*
@ 2014-05-22 14:51 Rob Jones
  2014-05-22 15:24 ` Heiko Stübner
  0 siblings, 1 reply; 2+ messages in thread
From: Rob Jones @ 2014-05-22 14:51 UTC (permalink / raw)
  To: linux-gpio; +Cc: heiko, broonie, ext-roger.quadros, rob.jones

Use devm_regulator_register in probe/remove.

Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
Signed-off-by: Rob Jones <rob.jones@codethink.co.uk>
---
 drivers/regulator/gpio-regulator.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c
index 989b23b..994a050 100644
--- a/drivers/regulator/gpio-regulator.c
+++ b/drivers/regulator/gpio-regulator.c
@@ -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);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] regulator: gpio-regulator: use devm_*
  2014-05-22 14:51 [PATCH] regulator: gpio-regulator: use devm_* Rob Jones
@ 2014-05-22 15:24 ` Heiko Stübner
  0 siblings, 0 replies; 2+ messages in thread
From: Heiko Stübner @ 2014-05-22 15:24 UTC (permalink / raw)
  To: Rob Jones; +Cc: linux-gpio, broonie, ext-roger.quadros

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

>  	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 <broonie@kernel.org>
and
	linux-kernel@vger.kernel.org
should be included as well.


Heiko


Am Donnerstag, 22. Mai 2014, 15:51:06 schrieb Rob Jones:
> Use devm_regulator_register in probe/remove.
> 
> Reviewed-by: Ian Molton <ian.molton@codethink.co.uk>
> Signed-off-by: Rob Jones <rob.jones@codethink.co.uk>
> ---
>  drivers/regulator/gpio-regulator.c |    4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/regulator/gpio-regulator.c
> b/drivers/regulator/gpio-regulator.c index 989b23b..994a050 100644
> --- a/drivers/regulator/gpio-regulator.c
> +++ b/drivers/regulator/gpio-regulator.c
> @@ -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);


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-22 15:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-22 14:51 [PATCH] regulator: gpio-regulator: use devm_* Rob Jones
2014-05-22 15:24 ` Heiko Stübner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).