]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
iio: gyro: mpu3050-core: fix pm_runtime error handling
authorAntoniu Miclaus <antoniu.miclaus@analog.com>
Mon, 16 Feb 2026 09:57:56 +0000 (11:57 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 23 Feb 2026 08:24:39 +0000 (08:24 +0000)
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>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/gyro/mpu3050-core.c

index ee2fcd20545dee025a524e749fbc392ab9049686..317e7b217ec6b0f92f085a67170ba435c9deb263 100644 (file)
@@ -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 @@ out_trigger_unlock:
 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)