From: Jonathan Cameron <jic23@kernel.org>
To: Moksh Panicker <mokshpanicker.7@gmail.com>
Cc: dlechner@baylibre.com, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
skhan@linuxfoundation.org
Subject: Re: [PATCH] iio: light: apds9306: fix PM reference leak in apds9306_read_data()
Date: Mon, 27 Jul 2026 03:31:51 +0100 [thread overview]
Message-ID: <20260727033151.0ea0cb9d@jic23-huawei> (raw)
In-Reply-To: <20260725051048.5616-1-mokshpanicker.7@gmail.com>
On Sat, 25 Jul 2026 05:10:48 +0000
Moksh Panicker <mokshpanicker.7@gmail.com> wrote:
> 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.
>
> Add a goto label before pm_runtime_put_autosuspend() and use it on
> all error paths after a successful pm_runtime_resume_and_get().
>
> Fixes: 620d1e6c7a3f ("iio: light: Add support for APDS9306 Light Sensor")
> Cc: stable@vger.kernel.org
> Signed-off-by: Moksh Panicker <mokshpanicker.7@gmail.com>
Good find.
Please look at PM_RUNTIME_ACQUIRE_AUTOSUSPEND() and matching ERR macro.
Using that should simplify this fix quite a bit and generally give us nicer code.
> ---
> 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 5ca4c87524fe..014db7a1787e 100644
> --- a/drivers/iio/light/apds9306.c
> +++ b/drivers/iio/light/apds9306.c
> @@ -475,19 +475,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_put;
>
> ret = regmap_field_read(rf->repeat_rate, &repeat_rate_idx);
> if (ret)
> - return ret;
> + goto out_pm_put;
>
> ret = regmap_field_read(rf->int_src, &int_src);
> if (ret)
> - return ret;
> + goto out_pm_put;
>
> 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_put;
> + }
>
> /* Whichever is greater - integration time period or sampling period. */
> delay = max(intg_time, apds9306_repeat_rate_period[repeat_rate_idx]);
> @@ -510,7 +512,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_put;
>
> /* If we reach here before the interrupt handler we push an event */
> if ((status & APDS9306_ALS_INT_STAT_MASK)) {
> @@ -530,14 +532,15 @@ 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_put;
> }
>
> *val = get_unaligned_le24(&buff);
>
> +out_pm_put:
> pm_runtime_put_autosuspend(data->dev);
>
> - return 0;
> + return ret;
> }
>
> static int apds9306_intg_time_get(struct apds9306_data *data, int *val2)
next prev parent reply other threads:[~2026-07-27 2:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 5:10 Moksh Panicker
2026-07-27 2:31 ` Jonathan Cameron [this message]
2026-08-01 8:53 ` Subhajit Ghosh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260727033151.0ea0cb9d@jic23-huawei \
--to=jic23@kernel.org \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mokshpanicker.7@gmail.com \
--cc=skhan@linuxfoundation.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®