Re: [PATCH] iio: accel: kxsd9: Fix runtime PM leak in kxsd9_write_raw()

From: Jonathan Cameron

Date: Wed Sep 16 2026 - 20:24:27 EST


On Wed, 16 Sep 2026 19:33:47 +0200
Linus Walleij <linusw@xxxxxxxxxx> wrote:

> On Wed, Sep 16, 2026 at 6:12 PM Wentao Liang <vulab@xxxxxxxxxxx> wrote:
>
> > pm_runtime_get_sync() increments the usage counter even on failure, so
> > every successful call must be paired with a put. Rejecting an invalid
> > scale value returned early and skipped the paired
> > pm_runtime_put_autosuspend(), permanently preventing runtime suspend.
> >
> > Fixes: 9a9a369d6178 ("iio: accel: kxsd9: Deploy system and runtime PM")
> > Cc: stable@xxxxxxxxxxxxxxx
>
> It's NOT that important.
Also not the current code...
static int kxsd9_write_raw(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan,
int val,
int val2,
long mask)
{
int ret = -EINVAL;
struct kxsd9_state *st = iio_priv(indio_dev);

pm_runtime_get_sync(st->dev);

if (mask == IIO_CHAN_INFO_SCALE) {
/* Check no integer component */
if (val)
ret = -EINVAL;
else
ret = kxsd9_write_scale(indio_dev, val2);
}

pm_runtime_put_autosuspend(st->dev);

return ret;
}

Which could be improved via the ACQUIRE magic but none the less doesn't
have this bug. Was fixed back in June.

Jonathan



>
> > Signed-off-by: Wentao Liang <vulab@xxxxxxxxxxx>
>
> Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>
>
> Yours,
> Linus Walleij