Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Biren Pandya <birenpandya@gmail.com>
Cc: "Linus Walleij" <linusw@kernel.org>,
	"David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 1/4] iio: accel: kxsd9: fix runtime PM imbalance on write_raw() error
Date: Sun, 14 Jun 2026 14:14:08 +0100	[thread overview]
Message-ID: <20260614141408.080a7cae@jic23-huawei> (raw)
In-Reply-To: <20260614071549.81920-2-birenpandya@gmail.com>

On Sun, 14 Jun 2026 12:45:46 +0530
Biren Pandya <birenpandya@gmail.com> wrote:

> kxsd9_write_raw() takes a runtime PM reference with pm_runtime_get_sync()
> but returns -EINVAL directly when a scale with a non-zero integer part is
> requested, skipping the matching pm_runtime_put_autosuspend(). This leaks
> a runtime PM usage-counter reference on every such write, after which the
> device can no longer autosuspend.
> 
> Set the error code and fall through to the existing put instead of
> returning early.
> 
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>
> Assisted-by: Claude:claude-opus-4-8 coccinelle
Good find.  This one is nasty as it is easily triggered from userspace.
So I'm going to pick this up as it stands.  However, if you are interested
in a doing a follow up series that cleans things up further:

- The pm_runtime_get_sync() return value is not checked anywhere in this driver.
  So good to do that.
- The various places in this driver (including this one) where runtime_pm
  is involved would be nicer handled using the relatively new
  PM_RUNTIME_ACQUIRE_AUTOSUSPEND() / PM_RUNTIME_ACQUIRE_ERR()

Probably makes sense to do both of those in one go given they'll be touching
the same code.

Applied to the fixes-togreg branch of iio.git and marked for stable.
Note I'll be rebasing that branch on rc1 before doing a pull request.

Thanks,

Jonathan


> ---
>  drivers/iio/accel/kxsd9.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c
> index 4717d80fc24a..7ac885d94d7f 100644
> --- a/drivers/iio/accel/kxsd9.c
> +++ b/drivers/iio/accel/kxsd9.c
> @@ -147,8 +147,9 @@ static int kxsd9_write_raw(struct iio_dev *indio_dev,
>  	if (mask == IIO_CHAN_INFO_SCALE) {
>  		/* Check no integer component */
>  		if (val)
> -			return -EINVAL;
> -		ret = kxsd9_write_scale(indio_dev, val2);
> +			ret = -EINVAL;
> +		else
> +			ret = kxsd9_write_scale(indio_dev, val2);
>  	}
>  
>  	pm_runtime_put_autosuspend(st->dev);


  reply	other threads:[~2026-06-14 13:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-14  7:15 [PATCH v1 0/4] iio: Fix runtime PM leaks across multiple drivers Biren Pandya
2026-06-14  7:15 ` [PATCH v1 1/4] iio: accel: kxsd9: fix runtime PM imbalance on write_raw() error Biren Pandya
2026-06-14 13:14   ` Jonathan Cameron [this message]
2026-06-14  7:15 ` [PATCH v1 2/4] iio: gyro: mpu3050: fix runtime PM leak when enabling trigger fails Biren Pandya
2026-06-14 13:22   ` Jonathan Cameron
2026-06-14  7:15 ` [PATCH v1 3/4] iio: pressure: mpl115: fix runtime PM leak on read error Biren Pandya
2026-06-14 13:24   ` Jonathan Cameron
2026-06-14  7:15 ` [PATCH v1 4/4] iio: light: gp2ap002: " Biren Pandya
2026-06-14 13:25   ` Jonathan Cameron
2026-06-14 13:31 ` [PATCH v1 0/4] iio: Fix runtime PM leaks across multiple drivers Jonathan Cameron

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=20260614141408.080a7cae@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=birenpandya@gmail.com \
    --cc=dlechner@baylibre.com \
    --cc=linusw@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /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