* [PATCH v4 0/2] iio: gyro: mpu3050: fix pm_runtime error handling
@ 2026-02-16 9:57 Antoniu Miclaus
2026-02-16 9:57 ` [PATCH v4 1/2] iio: gyro: mpu3050-i2c: " Antoniu Miclaus
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Antoniu Miclaus @ 2026-02-16 9:57 UTC (permalink / raw)
To: Linus Walleij, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
Cc: Antoniu Miclaus
Fix pm_runtime error handling across the mpu3050 driver. The existing
code uses pm_runtime_get_sync() without checking return values, allowing
operations to proceed even when the device fails to resume.
Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() and
propagate errors appropriately. Unlike pm_runtime_get_sync(), the usage
count is not incremented on error.
Changes in v4:
- Reword commit messages to correctly attribute the unchecked return
value to the caller rather than pm_runtime_get_sync() itself
- Simplify preenable by collapsing the trailing return statements
Antoniu Miclaus (2):
iio: gyro: mpu3050-i2c: fix pm_runtime error handling
iio: gyro: mpu3050-core: fix pm_runtime error handling
drivers/iio/gyro/mpu3050-core.c | 18 +++++++++++++-----
drivers/iio/gyro/mpu3050-i2c.c | 3 +--
2 files changed, 14 insertions(+), 7 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v4 1/2] iio: gyro: mpu3050-i2c: fix pm_runtime error handling
2026-02-16 9:57 [PATCH v4 0/2] iio: gyro: mpu3050: fix pm_runtime error handling Antoniu Miclaus
@ 2026-02-16 9:57 ` Antoniu Miclaus
2026-02-16 9:57 ` [PATCH v4 2/2] iio: gyro: mpu3050-core: " Antoniu Miclaus
2026-02-20 10:59 ` [PATCH v4 0/2] iio: gyro: mpu3050: " Jonathan Cameron
2 siblings, 0 replies; 4+ messages in thread
From: Antoniu Miclaus @ 2026-02-16 9:57 UTC (permalink / raw)
To: Linus Walleij, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
Cc: Antoniu Miclaus
The return value of pm_runtime_get_sync() is not checked, and the
function always returns success. This allows I2C mux operations to
proceed even when the device fails to resume.
Use pm_runtime_resume_and_get() and propagate its return value to
properly handle resume failures.
Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope")
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
Changes in v4:
- Reword commit message
drivers/iio/gyro/mpu3050-i2c.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/iio/gyro/mpu3050-i2c.c b/drivers/iio/gyro/mpu3050-i2c.c
index 092878f2c886..6549b22e643d 100644
--- a/drivers/iio/gyro/mpu3050-i2c.c
+++ b/drivers/iio/gyro/mpu3050-i2c.c
@@ -19,8 +19,7 @@ static int mpu3050_i2c_bypass_select(struct i2c_mux_core *mux, u32 chan_id)
struct mpu3050 *mpu3050 = i2c_mux_priv(mux);
/* Just power up the device, that is all that is needed */
- pm_runtime_get_sync(mpu3050->dev);
- return 0;
+ return pm_runtime_resume_and_get(mpu3050->dev);
}
static int mpu3050_i2c_bypass_deselect(struct i2c_mux_core *mux, u32 chan_id)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v4 2/2] iio: gyro: mpu3050-core: fix pm_runtime error handling
2026-02-16 9:57 [PATCH v4 0/2] iio: gyro: mpu3050: fix pm_runtime error handling Antoniu Miclaus
2026-02-16 9:57 ` [PATCH v4 1/2] iio: gyro: mpu3050-i2c: " Antoniu Miclaus
@ 2026-02-16 9:57 ` Antoniu Miclaus
2026-02-20 10:59 ` [PATCH v4 0/2] iio: gyro: mpu3050: " Jonathan Cameron
2 siblings, 0 replies; 4+ messages in thread
From: Antoniu Miclaus @ 2026-02-16 9:57 UTC (permalink / raw)
To: Linus Walleij, Jonathan Cameron, David Lechner, Nuno Sá,
Andy Shevchenko, linux-iio, linux-kernel
Cc: Antoniu Miclaus
The return value of pm_runtime_get_sync() is not checked, allowing
the driver to access hardware that may fail to resume. The device
usage count is also unconditionally incremented. Use
pm_runtime_resume_and_get() which propagates errors and avoids
incrementing the usage count on failure.
In preenable, add pm_runtime_put_autosuspend() on set_8khz_samplerate()
failure since postdisable does not run when preenable fails.
Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope")
Reviewed-by: Linus Walleij <linusw@kernel.org>
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
Changes in v4:
- Reword commit message
- Simplify preenable by collapsing the trailing return statements
drivers/iio/gyro/mpu3050-core.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index ee2fcd20545d..317e7b217ec6 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -322,7 +322,9 @@ static int mpu3050_read_raw(struct iio_dev *indio_dev,
}
case IIO_CHAN_INFO_RAW:
/* Resume device */
- pm_runtime_get_sync(mpu3050->dev);
+ ret = pm_runtime_resume_and_get(mpu3050->dev);
+ if (ret)
+ return ret;
mutex_lock(&mpu3050->lock);
ret = mpu3050_set_8khz_samplerate(mpu3050);
@@ -647,14 +649,20 @@ static irqreturn_t mpu3050_trigger_handler(int irq, void *p)
static int mpu3050_buffer_preenable(struct iio_dev *indio_dev)
{
struct mpu3050 *mpu3050 = iio_priv(indio_dev);
+ int ret;
- pm_runtime_get_sync(mpu3050->dev);
+ ret = pm_runtime_resume_and_get(mpu3050->dev);
+ if (ret)
+ return ret;
/* Unless we have OUR trigger active, run at full speed */
- if (!mpu3050->hw_irq_trigger)
- return mpu3050_set_8khz_samplerate(mpu3050);
+ if (!mpu3050->hw_irq_trigger) {
+ ret = mpu3050_set_8khz_samplerate(mpu3050);
+ if (ret)
+ pm_runtime_put_autosuspend(mpu3050->dev);
+ }
- return 0;
+ return ret;
}
static int mpu3050_buffer_postdisable(struct iio_dev *indio_dev)
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v4 0/2] iio: gyro: mpu3050: fix pm_runtime error handling
2026-02-16 9:57 [PATCH v4 0/2] iio: gyro: mpu3050: fix pm_runtime error handling Antoniu Miclaus
2026-02-16 9:57 ` [PATCH v4 1/2] iio: gyro: mpu3050-i2c: " Antoniu Miclaus
2026-02-16 9:57 ` [PATCH v4 2/2] iio: gyro: mpu3050-core: " Antoniu Miclaus
@ 2026-02-20 10:59 ` Jonathan Cameron
2 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2026-02-20 10:59 UTC (permalink / raw)
To: Antoniu Miclaus
Cc: Linus Walleij, David Lechner, Nuno Sá, Andy Shevchenko,
linux-iio, linux-kernel
On Mon, 16 Feb 2026 11:57:54 +0200
Antoniu Miclaus <antoniu.miclaus@analog.com> wrote:
> Fix pm_runtime error handling across the mpu3050 driver. The existing
> code uses pm_runtime_get_sync() without checking return values, allowing
> operations to proceed even when the device fails to resume.
>
> Replace pm_runtime_get_sync() with pm_runtime_resume_and_get() and
> propagate errors appropriately. Unlike pm_runtime_get_sync(), the usage
> count is not incremented on error.
Applied to the fixes-togreg branch of iio.git and marked for
stable. Thanks
Jonathan
>
> Changes in v4:
> - Reword commit messages to correctly attribute the unchecked return
> value to the caller rather than pm_runtime_get_sync() itself
> - Simplify preenable by collapsing the trailing return statements
>
> Antoniu Miclaus (2):
> iio: gyro: mpu3050-i2c: fix pm_runtime error handling
> iio: gyro: mpu3050-core: fix pm_runtime error handling
>
> drivers/iio/gyro/mpu3050-core.c | 18 +++++++++++++-----
> drivers/iio/gyro/mpu3050-i2c.c | 3 +--
> 2 files changed, 14 insertions(+), 7 deletions(-)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-20 10:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-16 9:57 [PATCH v4 0/2] iio: gyro: mpu3050: fix pm_runtime error handling Antoniu Miclaus
2026-02-16 9:57 ` [PATCH v4 1/2] iio: gyro: mpu3050-i2c: " Antoniu Miclaus
2026-02-16 9:57 ` [PATCH v4 2/2] iio: gyro: mpu3050-core: " Antoniu Miclaus
2026-02-20 10:59 ` [PATCH v4 0/2] iio: gyro: mpu3050: " Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox