* [PATCH 6.12.y] iio: light: apds9306: fix PM reference leak in apds9306_read_data()
[not found] <2026090952-mollusk-copilot-9a29@gregkh>
@ 2026-11-28 1:50 ` Dickson Wu via B4 Relay
2026-11-29 18:59 ` Sasha Levin
0 siblings, 1 reply; 2+ messages in thread
From: Dickson Wu via B4 Relay @ 2026-11-28 1:50 UTC (permalink / raw)
To: stable; +Cc: Moksh Panicker, Jonathan Cameron, linux-iio
From: Moksh Panicker <mokshpanicker.7@gmail.com>
commit d378fceaafd79e0dc59d3546bda251a3058062c0 upstream.
apds9306_read_data() calls pm_runtime_resume_and_get() but several
error paths return directly without calling pm_runtime_put_autosuspend(),
leaking the runtime PM reference and preventing the device from
autosuspending.
Use PM_RUNTIME_ACQUIRE_AUTOSUSPEND() and PM_RUNTIME_ACQUIRE_ERR() to
automatically handle runtime PM reference release on all return paths.
Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
Signed-off-by: Moksh Panicker <mokshpanicker.7@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
[ adapted to 6.12.y: no PM_RUNTIME_ACQUIRE helpers, goto the put ]
Signed-off-by: Dickson Wu <dickson.wu@certik.com>
---
This failed to apply to 6.12.y, which doesn't have the
PM_RUNTIME_ACQUIRE_AUTOSUSPEND() helpers. Instead every error return
after pm_runtime_resume_and_get() now jumps to the existing
mark_last_busy()/put_autosuspend() at the end, so the usage count is
dropped on all exits.
Tested on 6.12.119: W=1 build of apds9306.o, base vs patched, no new
warnings, and the patched kernel boots under QEMU. No sensor here, so
the read paths were checked in the source.
The backport and the test runs were prepared with AI coding tools
(OpenAI Codex agents, with review by Claude). I went over the result
before signing off.
---
drivers/iio/light/apds9306.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/light/apds9306.c b/drivers/iio/light/apds9306.c
index db648e2cb520..5e483cf4dc15 100644
--- a/drivers/iio/light/apds9306.c
+++ b/drivers/iio/light/apds9306.c
@@ -477,19 +477,21 @@ static int apds9306_read_data(struct apds9306_data *data, int *val, int reg)
ret = regmap_field_read(rf->intg_time, &intg_time_idx);
if (ret)
- return ret;
+ goto out_pm;
ret = regmap_field_read(rf->repeat_rate, &repeat_rate_idx);
if (ret)
- return ret;
+ goto out_pm;
ret = regmap_field_read(rf->int_src, &int_src);
if (ret)
- return ret;
+ goto out_pm;
intg_time = iio_gts_find_int_time_by_sel(&data->gts, intg_time_idx);
- if (intg_time < 0)
- return intg_time;
+ if (intg_time < 0) {
+ ret = intg_time;
+ goto out_pm;
+ }
/* Whichever is greater - integration time period or sampling period. */
delay = max(intg_time, apds9306_repeat_rate_period[repeat_rate_idx]);
@@ -512,7 +514,7 @@ static int apds9306_read_data(struct apds9306_data *data, int *val, int reg)
APDS9306_ALS_INT_STAT_MASK)),
APDS9306_ALS_READ_DATA_DELAY_US, delay * 2);
if (ret)
- return ret;
+ goto out_pm;
/* If we reach here before the interrupt handler we push an event */
if ((status & APDS9306_ALS_INT_STAT_MASK)) {
@@ -532,15 +534,16 @@ static int apds9306_read_data(struct apds9306_data *data, int *val, int reg)
ret = regmap_bulk_read(data->regmap, reg, buff, sizeof(buff));
if (ret) {
dev_err_ratelimited(dev, "read data failed\n");
- return ret;
+ goto out_pm;
}
*val = get_unaligned_le24(&buff);
+out_pm:
pm_runtime_mark_last_busy(data->dev);
pm_runtime_put_autosuspend(data->dev);
- return 0;
+ return ret;
}
static int apds9306_intg_time_get(struct apds9306_data *data, int *val2)
---
base-commit: e2e4b92c2b2a3ae78423cb343951cb5d2241b405
change-id: 20261128-apds9306-612-123c3a7502e1
Best regards,
--
Dickson Wu <dickson.wu@certik.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 6.12.y] iio: light: apds9306: fix PM reference leak in apds9306_read_data()
2026-11-28 1:50 ` [PATCH 6.12.y] iio: light: apds9306: fix PM reference leak in apds9306_read_data() Dickson Wu via B4 Relay
@ 2026-11-29 18:59 ` Sasha Levin
0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2026-11-29 18:59 UTC (permalink / raw)
To: stable
Cc: Sasha Levin, Moksh Panicker, Jonathan Cameron, linux-iio,
Dickson Wu via B4 Relay, Dickson Wu
> [ adapted to 6.12.y: no PM_RUNTIME_ACQUIRE helpers, goto the put ]
Queued for 6.12, thanks.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-29 19:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <2026090952-mollusk-copilot-9a29@gregkh>
2026-11-28 1:50 ` [PATCH 6.12.y] iio: light: apds9306: fix PM reference leak in apds9306_read_data() Dickson Wu via B4 Relay
2026-11-29 18:59 ` Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox