Skip to contentSkip to conversation

regulator: ab8500: use devm_regulator_register()

PATCH Applied Jingoo Han 7 participants 19 messages Dec 6, 2013 – Dec 10, 2013 Voltage and current regulator framework

lore
Share & tools
lore

Jingoo Han

author
#0 lore raw

PATCH 1/6 regulator: ab8500: use devm_regulator_register()

Use devm_regulator_register() to make cleanup paths simpler.

---
 drivers/regulator/ab8500.c |   24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
drivers/regulator/ab8500.c +4 -20
index 0f86695..c625468 100644
@@ -3005,7 +3005,6 @@ static int ab8500_regulator_register(struct platform_device *pdev,
 	struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
 	struct ab8500_regulator_info *info = NULL;
 	struct regulator_config config = { };
-	int err;
 
 	/* assign per-regulator data */
 	info = &abx500_regulator.info[id];
@@ -3027,17 +3026,12 @@ static int ab8500_regulator_register(struct platform_device *pdev,
 	}
 
 	/* register regulator with framework */
-	info->regulator = regulator_register(&info->desc, &config);
+	info->regulator = devm_regulator_register(&pdev->dev, &info->desc,
+						&config);
 	if (IS_ERR(info->regulator)) {
-		err = PTR_ERR(info->regulator);
 		dev_err(&pdev->dev, "failed to register regulator %s\n",
 			info->desc.name);
-		/* when we fail, un-register all earlier regulators */
-		while (--id >= 0) {
-			info = &abx500_regulator.info[id];
-			regulator_unregister(info->regulator);
-		}
-		return err;
+		return PTR_ERR(info->regulator);
 	}
 
 	return 0;
@@ -3086,17 +3080,7 @@ static int ab8500_regulator_probe(struct platform_device *pdev)
 
 static int ab8500_regulator_remove(struct platform_device *pdev)
 {
-	int i, err;
-
-	for (i = 0; i < abx500_regulator.info_size; i++) {
-		struct ab8500_regulator_info *info = NULL;
-		info = &abx500_regulator.info[i];
-
-		dev_vdbg(rdev_get_dev(info->regulator),
-			"%s-remove\n", info->desc.name);
-
-		regulator_unregister(info->regulator);
-	}
+	int err;
 
 	/* remove regulator debug */
 	err = ab8500_regulator_debug_exit(pdev);
Signature · 1 line
1.7.10.4
author
#1 lore raw

PATCH 2/6 regulator: db8500-prcmu: use devm_regulator_register()

Use devm_regulator_register() to make cleanup paths simpler.

---
 drivers/regulator/db8500-prcmu.c |   20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/regulator/db8500-prcmu.c +1 -19
index a53c11a..846acf2 100644
@@ -431,17 +431,11 @@ static int db8500_regulator_register(struct platform_device *pdev,
 	config.of_node = np;
 
 	/* register with the regulator framework */
-	info->rdev = regulator_register(&info->desc, &config);
+	info->rdev = devm_regulator_register(&pdev->dev, &info->desc, &config);
 	if (IS_ERR(info->rdev)) {
 		err = PTR_ERR(info->rdev);
 		dev_err(&pdev->dev, "failed to register %s: err %i\n",
 			info->desc.name, err);
-
-		/* if failing, unregister all earlier regulators */
-		while (--id >= 0) {
-			info = &dbx500_regulator_info[id];
-			regulator_unregister(info->rdev);
-		}
 		return err;
 	}
 
@@ -530,20 +524,8 @@ static int db8500_regulator_probe(struct platform_device *pdev)
 
 static int db8500_regulator_remove(struct platform_device *pdev)
 {
-	int i;
-
 	ux500_regulator_debug_exit();
 
-	for (i = 0; i < ARRAY_SIZE(dbx500_regulator_info); i++) {
-		struct dbx500_regulator_info *info;
-		info = &dbx500_regulator_info[i];
-
-		dev_vdbg(rdev_get_dev(info->rdev),
-			"regulator-%s-remove\n", info->desc.name);
-
-		regulator_unregister(info->rdev);
-	}
-
 	return 0;
 }
 
Signature · 1 line
1.7.10.4
Acked-by Bengt Jonsson on v1 2/6
#2 lore raw

RE: [PATCH 2/6] regulator: db8500-prcmu: use devm_regulator_register()

-----Original Message-----
From: Jingoo Han [mailto:[email protected]]
Sent: den 6 december 2013 08:09
To: 'Mark Brown'
Cc: 'Liam Girdwood'; [email protected]; 'Jingoo Han'; 'Bengt Jonsson'
Subject: [PATCH 2/6] regulator: db8500-prcmu: use devm_regulator_register()

Use devm_regulator_register() to make cleanup paths simpler.

maintainer Applied
#3 lore raw

Re: [PATCH 2/6] regulator: db8500-prcmu: use devm_regulator_register()

In reply to Jingoo Han
Quoted 1 line · Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler.

Applied, thanks.

author
#4 lore raw

PATCH 3/6 regulator: fixed: use devm_regulator_register()

In reply to Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler.

---
 drivers/regulator/fixed.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/regulator/fixed.c +2 -2
index 5ea64b9..f45cc1ac 100644
@@ -186,7 +186,8 @@ static int reg_fixed_voltage_probe(struct platform_device *pdev)
 	cfg.driver_data = drvdata;
 	cfg.of_node = pdev->dev.of_node;
 
-	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);
@@ -212,7 +213,6 @@ static int reg_fixed_voltage_remove(struct platform_device *pdev)
 {
 	struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev);
 
-	regulator_unregister(drvdata->dev);
 	kfree(drvdata->desc.supply_name);
 	kfree(drvdata->desc.name);
 
Signature · 1 line
1.7.10.4
maintainer
#5 lore raw

Re: [PATCH 3/6] regulator: fixed: use devm_regulator_register()

Quoted 1 line · Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler.

This has the same issue as the gpio regulator - it needs a more complete conversion to devm to be safe due to the use of other resources by the regulator while it's running. The conversion looks straightfoward though.

author
#6 lore raw

Re: [PATCH 3/6] regulator: fixed: use devm_regulator_register()

Quoted 7 lines · Mark Brown
Quoted 1 line · Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler.

This has the same issue as the gpio regulator - it needs a more complete conversion to devm to be safe due to the use of other resources by the regulator while it's running. The conversion looks straightfoward though.

OK, I see.
Please ignore this patch.
Thank you for your comment.

Best regards,
Jingoo Han

author
#7 lore raw

PATCH 4/6 regulator: gpio-regulator: use devm_regulator_register()

In reply to Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler.

---
 drivers/regulator/gpio-regulator.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/regulator/gpio-regulator.c +2 -3
index 13ec94d..fb4120b 100644
@@ -324,7 +324,8 @@ 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);
@@ -351,8 +352,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
#8 lore raw

Re: [PATCH 4/6] regulator: gpio-regulator: use devm_regulator_register()

Hi,

Am Freitag, 6. Dezember 2013, 08:10:42 schrieb Jingoo Han:

drivers/regulator/gpio-regulator.c static int gpio_regulator_remove(struct platform_device · line 357

Quoted 9 lines
drivers/regulator/gpio-regulator.c +0 -2
@@ -351,8 +352,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);

I'm not this firm in the core driver/device behaviour, but when looking at __device_release_driver I see that the remove callback runs before devres_release_all, which would effectively free the gpios before the regulator gets unregistered - is this racy with a regulator change at the same time?

Heiko

maintainer
#9 lore raw

Re: [PATCH 4/6] regulator: gpio-regulator: use devm_regulator_register()

Quoted 5 lines · Heiko Stübner

I'm not this firm in the core driver/device behaviour, but when looking at __device_release_driver I see that the remove callback runs before devres_release_all, which would effectively free the gpios before the regulator gets unregistered - is this racy with a regulator change at the same time?

Yes, the rest of the driver really needs to be converted to devm_ at the same time.

author
#10 lore raw

Re: [PATCH 4/6] regulator: gpio-regulator: use devm_regulator_register()

Quoted 10 lines · Mark Brown
Quoted 5 lines · Heiko Stübner

I'm not this firm in the core driver/device behaviour, but when looking at __device_release_driver I see that the remove callback runs before devres_release_all, which would effectively free the gpios before the regulator gets unregistered - is this racy with a regulator change at the same time?

Yes, the rest of the driver really needs to be converted to devm_ at the same time.

The gpios is requested by gpio_request_array(). However, devm_gpio_request_array() is not supported yet, so the rest of the driver cannot be converted to devm_.

Mark Brown,
Please ignore this patch.

Best regards,
Jingoo Han

author
#11 lore raw

PATCH 5/6 regulator: pfuze100: use devm_regulator_register()

In reply to Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler, and remove unnecessary remove().

---
 drivers/regulator/pfuze100-regulator.c |   20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)
drivers/regulator/pfuze100-regulator.c +3 -17
index 032df37..50c1bf8 100644
@@ -408,31 +408,18 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
 		config.driver_data = pfuze_chip;
 		config.of_node = match_of_node(i);
 
-		pfuze_chip->regulators[i] = regulator_register(desc, &config);
+		pfuze_chip->regulators[i] =
+			devm_regulator_register(&client->dev, desc, &config);
 		if (IS_ERR(pfuze_chip->regulators[i])) {
 			dev_err(&client->dev, "register regulator%s failed\n",
 				pfuze100_regulators[i].desc.name);
-			ret = PTR_ERR(pfuze_chip->regulators[i]);
-			while (--i >= 0)
-				regulator_unregister(pfuze_chip->regulators[i]);
-			return ret;
+			return PTR_ERR(pfuze_chip->regulators[i]);
 		}
 	}
 
 	return 0;
 }
 
-static int pfuze100_regulator_remove(struct i2c_client *client)
-{
-	int i;
-	struct pfuze_chip *pfuze_chip = i2c_get_clientdata(client);
-
-	for (i = 0; i < PFUZE100_MAX_REGULATOR; i++)
-		regulator_unregister(pfuze_chip->regulators[i]);
-
-	return 0;
-}
-
 static struct i2c_driver pfuze_driver = {
 	.id_table = pfuze_device_id,
 	.driver = {
@@ -441,7 +428,6 @@ static struct i2c_driver pfuze_driver = {
 		.of_match_table = pfuze_dt_ids,
 	},
 	.probe = pfuze100_regulator_probe,
-	.remove = pfuze100_regulator_remove,
 };
 module_i2c_driver(pfuze_driver);
 
Signature · 1 line
1.7.10.4
Acked-by Robin Gong on v1 5/6
#12 lore raw

RE: [PATCH 5/6] regulator: pfuze100: use devm_regulator_register()

-----Original Message-----
From: Jingoo Han [mailto:[email protected]]
Sent: Friday, December 06, 2013 3:12 PM
To: 'Mark Brown'
Cc: 'Liam Girdwood'; [email protected]; 'Jingoo Han'; Gong Yibin-B38343; 'Axel Lin'; 'Tim Harvey'
Subject: [PATCH 5/6] regulator: pfuze100: use devm_regulator_register()

Use devm_regulator_register() to make cleanup paths simpler, and remove unnecessary remove().

---
 drivers/regulator/pfuze100-regulator.c |   20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)
drivers/regulator/pfuze100-regulator.c +3 -16
index 032df37..50c1bf8 100644
@@ -408,31 +408,18 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
 		config.driver_data = pfuze_chip;
 		config.of_node = match_of_node(i);
 
-		pfuze_chip->regulators[i] = regulator_register(desc, &config);
+		pfuze_chip->regulators[i] =
+			devm_regulator_register(&client->dev, desc, &config);
 		if (IS_ERR(pfuze_chip->regulators[i])) {
 			dev_err(&client->dev, "register regulator%s failed\n",
 				pfuze100_regulators[i].desc.name);
-			ret = PTR_ERR(pfuze_chip->regulators[i]);
-			while (--i >= 0)
-				regulator_unregister(pfuze_chip->regulators[i]);
-			return ret;
+			return PTR_ERR(pfuze_chip->regulators[i]);
 		}
 	}
 
 	return 0;
 }
 
-static int pfuze100_regulator_remove(struct i2c_client *client) -{
-	int i;
-	struct pfuze_chip *pfuze_chip = i2c_get_clientdata(client);
-
-	for (i = 0; i < PFUZE100_MAX_REGULATOR; i++)
-		regulator_unregister(pfuze_chip->regulators[i]);
-
-	return 0;
-}
-
 static struct i2c_driver pfuze_driver = {
 	.id_table = pfuze_device_id,
 	.driver = {
@@ -441,7 +428,6 @@ static struct i2c_driver pfuze_driver = {
 		.of_match_table = pfuze_dt_ids,
 	},
 	.probe = pfuze100_regulator_probe,
-	.remove = pfuze100_regulator_remove,
 };
 module_i2c_driver(pfuze_driver);
 

--
1.7.10.4

maintainer Applied
#13 lore raw

Re: [PATCH 5/6] regulator: pfuze100: use devm_regulator_register()

In reply to Jingoo Han
Quoted 2 lines · Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler, and remove unnecessary remove().

Applied, thanks.

author
#14 lore raw

PATCH 6/6 regulator: stw481x-vmmc: use devm_regulator_register()

In reply to Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler, and remove unnecessary remove().

---
 drivers/regulator/stw481x-vmmc.c |   12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)
drivers/regulator/stw481x-vmmc.c +2 -10
index f78857b..a7e1526 100644
@@ -74,7 +74,8 @@ static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
 	config.init_data = of_get_regulator_init_data(&pdev->dev,
 						      pdev->dev.of_node);
 
-	stw481x->vmmc_regulator = regulator_register(&vmmc_regulator, &config);
+	stw481x->vmmc_regulator = devm_regulator_register(&pdev->dev,
+						&vmmc_regulator, &config);
 	if (IS_ERR(stw481x->vmmc_regulator)) {
 		dev_err(&pdev->dev,
 			"error initializing STw481x VMMC regulator\n");
@@ -85,14 +86,6 @@ static int stw481x_vmmc_regulator_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static int stw481x_vmmc_regulator_remove(struct platform_device *pdev)
-{
-	struct stw481x *stw481x = dev_get_platdata(&pdev->dev);
-
-	regulator_unregister(stw481x->vmmc_regulator);
-	return 0;
-}
-
 static const struct of_device_id stw481x_vmmc_match[] = {
 	{ .compatible = "st,stw481x-vmmc", },
 	{},
@@ -105,7 +98,6 @@ static struct platform_driver stw481x_vmmc_regulator_driver = {
 		.of_match_table = stw481x_vmmc_match,
 	},
 	.probe = stw481x_vmmc_regulator_probe,
-	.remove = stw481x_vmmc_regulator_remove,
 };
 
 module_platform_driver(stw481x_vmmc_regulator_driver);
Signature · 1 line
1.7.10.4
maintainer Applied
#16 lore raw

Re: [PATCH 6/6] regulator: stw481x-vmmc: use devm_regulator_register()

In reply to Jingoo Han
Quoted 2 lines · Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler, and remove unnecessary remove().

Applied, thanks.

Acked-by on v1 1/6
#17 lore raw
In reply to Jingoo Han
Quoted 6 lines · Jingoo Han

Use devm_regulator_register() to make cleanup paths simpler.

---
 drivers/regulator/ab8500.c |   24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
Signature · 4 lines
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog