Re: [PATCH] iio: accel: kxsd9: Fix runtime PM error handling and scoping
From: Andy Shevchenko
Date: Tue Jun 16 2026 - 04:44:17 EST
On Tue, Jun 16, 2026 at 01:33:30AM +0530, Biren Pandya 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.
> - 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.
...
> void kxsd9_common_remove(struct device *dev)
> {
> struct iio_dev *indio_dev = dev_get_drvdata(dev);
> struct kxsd9_state *st = iio_priv(indio_dev);
> + int ret;
>
> iio_triggered_buffer_cleanup(indio_dev);
> iio_device_unregister(indio_dev);
> - pm_runtime_get_sync(dev);
> - pm_runtime_put_noidle(dev);
> +
> + ret = pm_runtime_resume_and_get(dev);
> pm_runtime_disable(dev);
> - kxsd9_power_down(st);
> + if (ret >= 0) {
Use standard pattern.
> + kxsd9_power_down(st);
> + pm_runtime_put_noidle(dev);
> + }
> }
--
With Best Regards,
Andy Shevchenko