From: Biren Pandya <birenpandya@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>, linux-iio@vger.kernel.org
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
linux-kernel@vger.kernel.org,
Biren Pandya <birenpandya@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH v4] iio: accel: kxsd9: fix runtime PM leak in write_raw
Date: Sun, 12 Jul 2026 14:01:06 +0530 [thread overview]
Message-ID: <20260712083106.97429-2-birenpandya@gmail.com> (raw)
The kxsd9 driver previously used manual pm_runtime_get_sync() and
pm_runtime_put_autosuspend() calls around the entire kxsd9_write_raw()
function. If the user provides a non-zero integer component for scale,
the function returned -EINVAL directly, leaking the runtime PM usage
counter.
Move the mask and value validation checks before pm_runtime_get_sync()
to ensure the early -EINVAL returns do not leak the usage counter.
Fixes: 9a9a369d6178 ("iio: accel: kxsd9: Deploy system and runtime PM")
Cc: stable@vger.kernel.org
Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
Changes since the reviewed version:
- Reduced to the minimal write_raw() leak fix. Dropped the remove()
rework (no underflow is possible — pm_runtime_put_noidle() floors at 0)
and deferred the PM-macro conversion and style cleanup to a follow-up
series, per Jonathan Cameron and Andy Shevchenko.
drivers/iio/accel/kxsd9.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c
index 4717d80fc24af..1af04cb4bf86a 100644
--- a/drivers/iio/accel/kxsd9.c
+++ b/drivers/iio/accel/kxsd9.c
@@ -139,18 +139,18 @@ static int kxsd9_write_raw(struct iio_dev *indio_dev,
int val2,
long mask)
{
- int ret = -EINVAL;
struct kxsd9_state *st = iio_priv(indio_dev);
+ int ret;
- pm_runtime_get_sync(st->dev);
+ if (mask != IIO_CHAN_INFO_SCALE)
+ return -EINVAL;
- if (mask == IIO_CHAN_INFO_SCALE) {
- /* Check no integer component */
- if (val)
- return -EINVAL;
- ret = kxsd9_write_scale(indio_dev, val2);
- }
+ /* Check no integer component */
+ if (val)
+ return -EINVAL;
+ pm_runtime_get_sync(st->dev);
+ ret = kxsd9_write_scale(indio_dev, val2);
pm_runtime_put_autosuspend(st->dev);
return ret;
--
2.50.1 (Apple Git-155)
next reply other threads:[~2026-07-12 8:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-12 8:31 Biren Pandya [this message]
2026-07-13 1:12 ` [PATCH v4] iio: accel: kxsd9: fix runtime PM leak in write_raw 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=20260712083106.97429-2-birenpandya@gmail.com \
--to=birenpandya@gmail.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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