Skip to contentSkip to conversation

iio: light: gp2ap002: Disable regulators on resume failure

PATCH Applied Laxman Acharya Padhya 4 participants 4 messages Jul 4 – Jul 11

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: light: gp2ap002: Disable regulators on resume failure

If enabling VIO fails after VDD has been enabled, runtime resume returns without disabling VDD. Likewise, if device reinitialization fails, both supplies remain enabled. The runtime PM core keeps the device suspended when its resume callback fails, so the supplies must be restored to the suspended state.

Disable the supplies enabled by the callback before returning an error.

Fixes 97d642e23037 ("iio: light: Add a driver for Sharp GP2AP002x00F")
Assisted-by Codex:gpt-5
---
 drivers/iio/light/gp2ap002.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/light/gp2ap002.c +8 -2
index c83f67f..efef332 100644
@@ -669,7 +669,7 @@ static int gp2ap002_runtime_resume(struct device *dev)
 	ret = regulator_enable(gp2ap002->vio);
 	if (ret) {
 		dev_err(dev, "failed to enable VIO regulator in resume path\n");
-		return ret;
+		goto out_disable_vdd;
 	}
 
 	msleep(20);
@@ -677,13 +677,19 @@ static int gp2ap002_runtime_resume(struct device *dev)
 	ret = gp2ap002_init(gp2ap002);
 	if (ret) {
 		dev_err(dev, "re-initialization failed\n");
-		return ret;
+		goto out_disable_vio;
 	}
 
 	/* Re-activate the IRQ */
 	enable_irq(gp2ap002->irq);
 
 	return 0;
+
+out_disable_vio:
+	regulator_disable(gp2ap002->vio);
+out_disable_vdd:
+	regulator_disable(gp2ap002->vdd);
+	return ret;
 }
 
 static DEFINE_RUNTIME_DEV_PM_OPS(gp2ap002_dev_pm_ops, gp2ap002_runtime_suspend,
Signature · 1 line
2.51.2
#1 lore raw
Quoted 7 lines · Laxman Acharya Padhya

If enabling VIO fails after VDD has been enabled, runtime resume returns without disabling VDD. Likewise, if device reinitialization fails, both supplies remain enabled. The runtime PM core keeps the device suspended when its resume callback fails, so the supplies must be restored to the suspended state.

Disable the supplies enabled by the callback before returning an error.

Sounds legit. However, I can't be fully sure. Let's wait for others to look at this and comment.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Laxman Acharya Padhya
Quoted 11 lines · Laxman Acharya Padhya

If enabling VIO fails after VDD has been enabled, runtime resume returns without disabling VDD. Likewise, if device reinitialization fails, both supplies remain enabled. The runtime PM core keeps the device suspended when its resume callback fails, so the supplies must be restored to the suspended state.

Disable the supplies enabled by the callback before returning an error.

Fixes 97d642e23037 ("iio: light: Add a driver for Sharp GP2AP002x00F")
Assisted-by Codex:gpt-5

Looks right.

Yours,
Linus Walleij

#3 lore raw
Quoted 9 lines · On Fri, 10 Jul 2026 19:40:50 +0200 Linus Walleij <[email protected]> wrote:
Quoted 6 lines · Laxman Acharya Padhya

If enabling VIO fails after VDD has been enabled, runtime resume returns without disabling VDD. Likewise, if device reinitialization fails, both supplies remain enabled. The runtime PM core keeps the device suspended when its resume callback fails, so the supplies must be restored to the suspended state.

Quoted 8 lines
Quoted 5 lines

Disable the supplies enabled by the callback before returning an error.

Fixes 97d642e23037 ("iio: light: Add a driver for Sharp GP2AP002x00F")
Assisted-by Codex:gpt-5

Looks right.

Applied, and marked for stable.

Jonathan

Quoted 3 lines

Yours,
Linus Walleij