Re: [PATCH] iio: light: ltrf216a: fix runtime PM reference leak in error path
From: Andy Shevchenko
Date: Mon Jul 13 2026 - 08:42:52 EST
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