From: Jonathan Cameron <jic23@kernel.org>
To: Biren Pandya <birenpandya@gmail.com>
Cc: linux-iio@vger.kernel.org,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Sakari Ailus" <sakari.ailus@linux.intel.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: accel: kxsd9: Fix runtime PM error handling and scoping
Date: Sun, 21 Jun 2026 18:41:38 +0100 [thread overview]
Message-ID: <20260621184138.39540fda@jic23-huawei> (raw)
In-Reply-To: <20260615200330.33207-1-birenpandya@gmail.com>
On Tue, 16 Jun 2026 01:33:30 +0530
Biren Pandya <birenpandya@gmail.com> wrote:
> The kxsd9 driver uses pm_runtime_get_sync() in multiple places without
> checking its return value, which can lead to silent failures. It also
> relies on manual pm_runtime_put_autosuspend() calls in various return
> paths, which is prone to memory leaks if a return path is missed.
>
> Fix the runtime PM handling by using the new scoped guards and proper
> error checking:
> - In kxsd9_write_raw() and kxsd9_read_raw(), use the scoped
> PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND() macro to safely automate
> cleanup on function return, while maintaining the behavior of
> waking up a suspended device via pm_runtime_resume_and_get().
> This allows us to cleanly remove all manual puts and error gotos.
Somewhere here mention that one of the puts was missing.
> - In kxsd9_buffer_preenable(), replace pm_runtime_get_sync() with
> pm_runtime_resume_and_get() to safely check for errors and handle
> usage-counter unwinding on failure.
> - In kxsd9_common_remove(), replace pm_runtime_get_sync() with
> pm_runtime_resume_and_get() and only invoke kxsd9_power_down()
> if the resume succeeds. This prevents unbalanced regulator disable
> warnings and bus timeouts if the device is already suspended.
>
> Signed-off-by: Biren Pandya <birenpandya@gmail.com>
Given this fixes a path, needs a Fixes tag.
Otherwise, what Andy said.
> ---
> drivers/iio/accel/kxsd9.c | 50 +++++++++++++++++++--------------------
> 1 file changed, 24 insertions(+), 26 deletions(-)
>
> diff --git a/drivers/iio/accel/kxsd9.c b/drivers/iio/accel/kxsd9.c
> index 4717d80fc24a..f23d1660e6da 100644
> --- a/drivers/iio/accel/kxsd9.c
> +++ b/drivers/iio/accel/kxsd9.c
> @@ -139,68 +139,63 @@ 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);
>
> - pm_runtime_get_sync(st->dev);
> + PM_RUNTIME_ACQUIRE_IF_ENABLED_AUTOSUSPEND(st->dev, pm);
> + if (PM_RUNTIME_ACQUIRE_ERR(&pm))
> + return PM_RUNTIME_ACQUIRE_ERR(&pm);
>
> if (mask == IIO_CHAN_INFO_SCALE) {
> /* Check no integer component */
> if (val)
> return -EINVAL;
This one is a real fix that needed addressing as it exits
with an error code leaving the power on.
> - ret = kxsd9_write_scale(indio_dev, val2);
> + return kxsd9_write_scale(indio_dev, val2);
> }
>
> - pm_runtime_put_autosuspend(st->dev);
> -
> - return ret;
> + return -EINVAL;
> }
prev parent reply other threads:[~2026-06-21 17:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 20:03 [PATCH] iio: accel: kxsd9: Fix runtime PM error handling and scoping Biren Pandya
2026-06-16 8:44 ` Andy Shevchenko
2026-06-21 17:41 ` Jonathan Cameron [this message]
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=20260621184138.39540fda@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=birenpandya@gmail.com \
--cc=dlechner@baylibre.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=sakari.ailus@linux.intel.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