diff mbox series

[02/10] regulator: arizona-ldo1: Avoid double gpiod_put() on enable GPIO

Message ID 20261104182148.1176116-3-lee@kernel.org
State New
Headers show
Series regulator: Fix teardown races, reference counting, and error handling | expand

Commit Message

Lee Jones Nov. 4, 2026, 6:20 p.m. UTC
Passing config.ena_gpiod to devm_regulator_register() transfers ownership
of the GPIO descriptor to the regulator core, which releases it via
gpiod_put() in regulator_ena_gpio_free() upon registration failure or
when devres unregisters the regulator.

Calling gpiod_put(ldo1->ena_gpiod) in arizona_ldo1_remove() prematurely
frees the enable GPIO while the regulator is still registered and causes
a second gpiod_put() when devm_rdev_release() runs.  Drop the redundant
remove callback and ena_gpiod field so the regulator core manages the
descriptor lifetime exclusively.

Fixes: a9191579ba10 ("regulator: arizona-ldo1: Use correct device to get enable GPIO")
Closes: https://sashiko.dev/#/bug/linux-7988402e-ca08-4bd3-9488-5779d6da0450
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/regulator/arizona-ldo1.c | 16 ----------------
 1 file changed, 16 deletions(-)

Comments

Charles Keepax Nov. 5, 2026, 10:08 a.m. UTC | #1
On Wed, Nov 04, 2026 at 06:20:52PM +0000, Lee Jones wrote:
> Passing config.ena_gpiod to devm_regulator_register() transfers ownership
> of the GPIO descriptor to the regulator core, which releases it via
> gpiod_put() in regulator_ena_gpio_free() upon registration failure or
> when devres unregisters the regulator.
> 
> Calling gpiod_put(ldo1->ena_gpiod) in arizona_ldo1_remove() prematurely
> frees the enable GPIO while the regulator is still registered and causes
> a second gpiod_put() when devm_rdev_release() runs.  Drop the redundant
> remove callback and ena_gpiod field so the regulator core manages the
> descriptor lifetime exclusively.
> 
> Fixes: a9191579ba10 ("regulator: arizona-ldo1: Use correct device to get enable GPIO")
> Closes: https://sashiko.dev/#/bug/linux-7988402e-ca08-4bd3-9488-5779d6da0450
> Cc: stable@vger.kernel.org
> Signed-off-by: Lee Jones <lee@kernel.org>
> ---

Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com>

Thanks,
Charles
diff mbox series

Patch

diff --git a/drivers/regulator/arizona-ldo1.c b/drivers/regulator/arizona-ldo1.c
index 501843996faa..981e047167ea 100644
--- a/drivers/regulator/arizona-ldo1.c
+++ b/drivers/regulator/arizona-ldo1.c
@@ -35,8 +35,6 @@  struct arizona_ldo1 {
 
 	struct regulator_consumer_supply supply;
 	struct regulator_init_data init_data;
-
-	struct gpio_desc *ena_gpiod;
 };
 
 static int arizona_ldo1_hc_set_voltage_sel(struct regulator_dev *rdev,
@@ -262,8 +260,6 @@  static int arizona_ldo1_common_init(struct platform_device *pdev,
 	if (IS_ERR(config.ena_gpiod))
 		return PTR_ERR(config.ena_gpiod);
 
-	ldo1->ena_gpiod = config.ena_gpiod;
-
 	if (pdata->init_data)
 		config.init_data = pdata->init_data;
 	else
@@ -287,8 +283,6 @@  static int arizona_ldo1_common_init(struct platform_device *pdev,
 		return ret;
 	}
 
-	platform_set_drvdata(pdev, ldo1);
-
 	return 0;
 }
 
@@ -339,14 +333,6 @@  static int arizona_ldo1_probe(struct platform_device *pdev)
 	return ret;
 }
 
-static void arizona_ldo1_remove(struct platform_device *pdev)
-{
-	struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
-
-	if (ldo1->ena_gpiod)
-		gpiod_put(ldo1->ena_gpiod);
-}
-
 static int madera_ldo1_probe(struct platform_device *pdev)
 {
 	struct madera *madera = dev_get_drvdata(pdev->dev.parent);
@@ -375,7 +361,6 @@  static int madera_ldo1_probe(struct platform_device *pdev)
 
 static struct platform_driver arizona_ldo1_driver = {
 	.probe = arizona_ldo1_probe,
-	.remove = arizona_ldo1_remove,
 	.driver = {
 		.name = "arizona-ldo1",
 		.probe_type = PROBE_FORCE_SYNCHRONOUS,
@@ -384,7 +369,6 @@  static struct platform_driver arizona_ldo1_driver = {
 
 static struct platform_driver madera_ldo1_driver = {
 	.probe = madera_ldo1_probe,
-	.remove = arizona_ldo1_remove,
 	.driver = {
 		.name = "madera-ldo1",
 		.probe_type = PROBE_FORCE_SYNCHRONOUS,