Re: [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path
Andy Shevchenko <[email protected]> Mon, 13 Jul 2026 15:36:51 +0300
| Newsgroups | dev.linux.lists.linux-kernel-mentees,org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel |
|---|---|
| Organization | Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo |
| Message-ID | <[email protected]> |
On Mon, Jul 13, 2026 at 07:58:29AM +0530, Vidhu Sarwal wrote:
> ltrf216a_get_lux() acquires a runtime PM reference by calling
> ltrf216a_set_power_state(data, true). However, if
> ltrf216a_read_data() fails, the function returns immediately without
> dropping the reference.
>
> This leaves the runtime PM usage count unbalanced, preventing the device
> from autosuspending after a failed read.
>
> Fix this by releasing the runtime PM reference before returning from the
> error path.
...
> static int ltrf216a_get_lux(struct ltrf216a_data *data)
> greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
> - if (greendata < 0)
> + if (greendata < 0) {
> + ltrf216a_set_power_state(data, false);
> return greendata;
> + }
>
> ltrf216a_set_power_state(data, false);
Wouldn't be simpler to do
greendata = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
ltrf216a_set_power_state(data, false);
if (greendata < 0)
return greendata;
?
Not insisting on this. Up to Jonathan and others to decide.
--
With Best Regards,
Andy Shevchenko