mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: gyro: mpu3050: Fix runtime PM refcount leak in trigger enable path
@ 2026-10-30  8:43 laixiangwu
  2026-11-01  0:04 ` Jonathan Cameron
  0 siblings, 1 reply; 6+ messages in thread
From: laixiangwu @ 2026-10-30  8:43 UTC (permalink / raw)
  To: Linus Walleij, Jonathan Cameron
  Cc: David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel, laixiangwu

mpu3050_drdy_trigger_set_state() calls pm_runtime_get_sync() when
enabling the data ready trigger, but all five error returns in the
enable path return directly without the matching
pm_runtime_put_autosuspend(). The disable path, in contrast, drops
the reference correctly.

As a result, a failed trigger enable leaves the runtime PM usage
counter incremented and the sensor can never runtime suspend. It also
leaves hw_irq_trigger set to true, claiming the hardware IRQ is in
use when it is not.

Add an error label that drops the runtime PM reference and clears
hw_irq_trigger, and check the return value of pm_runtime_get_sync()
like the rest of the driver does.

Fixes: 3904b28efb2c ("iio: gyro: Add driver for the MPU-3050 gyroscope")
Signed-off-by: laixiangwu <laixiangwu@cmss.chinamobile.com>
---
 drivers/iio/gyro/mpu3050-core.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/gyro/mpu3050-core.c b/drivers/iio/gyro/mpu3050-core.c
index 07c0f9011..9c6d5ba82 100644
--- a/drivers/iio/gyro/mpu3050-core.c
+++ b/drivers/iio/gyro/mpu3050-core.c
@@ -988,20 +988,24 @@ static int mpu3050_drdy_trigger_set_state(struct iio_trigger *trig,
 		return 0;
 	} else {
 		/* Else we're enabling the trigger from this point */
-		pm_runtime_get_sync(mpu3050->dev);
+		ret = pm_runtime_get_sync(mpu3050->dev);
+		if (ret < 0) {
+			pm_runtime_put_noidle(mpu3050->dev);
+			return ret;
+		}
 		mpu3050->hw_irq_trigger = true;
 
 		/* Disable all things in the FIFO */
 		ret = regmap_write(mpu3050->map, MPU3050_FIFO_EN, 0);
 		if (ret)
-			return ret;
+			goto err_put_pm;
 
 		/* Reset and enable the FIFO */
 		ret = regmap_set_bits(mpu3050->map, MPU3050_USR_CTRL,
 				      MPU3050_USR_CTRL_FIFO_EN |
 				      MPU3050_USR_CTRL_FIFO_RST);
 		if (ret)
-			return ret;
+			goto err_put_pm;
 
 		mpu3050->pending_fifo_footer = false;
 
@@ -1013,12 +1017,12 @@ static int mpu3050_drdy_trigger_set_state(struct iio_trigger *trig,
 				   MPU3050_FIFO_EN_GYRO_ZOUT |
 				   MPU3050_FIFO_EN_FOOTER);
 		if (ret)
-			return ret;
+			goto err_put_pm;
 
 		/* Configure the sample engine */
 		ret = mpu3050_start_sampling(mpu3050);
 		if (ret)
-			return ret;
+			goto err_put_pm;
 
 		/* Clear IRQ flag */
 		ret = regmap_read(mpu3050->map, MPU3050_INT_STATUS, &val);
@@ -1037,10 +1041,16 @@ static int mpu3050_drdy_trigger_set_state(struct iio_trigger *trig,
 
 		ret = regmap_write(mpu3050->map, MPU3050_INT_CFG, val);
 		if (ret)
-			return ret;
+			goto err_put_pm;
 	}
 
 	return 0;
+
+err_put_pm:
+	pm_runtime_put_autosuspend(mpu3050->dev);
+	mpu3050->hw_irq_trigger = false;
+
+	return ret;
 }
 
 static const struct iio_trigger_ops mpu3050_trigger_ops = {
-- 
2.50.1.windows.1




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-01  9:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-30  8:43 [PATCH] iio: gyro: mpu3050: Fix runtime PM refcount leak in trigger enable path laixiangwu
2026-11-01  0:04 ` Jonathan Cameron
2026-11-01  9:23   ` [PATCH v2 0/2] " laixiangwu
2026-11-01  9:23     ` [PATCH v2 1/2] iio: gyro: mpu3050: Split data ready trigger enable/disable into helpers laixiangwu
2026-11-01  9:23     ` [PATCH v2 2/2] iio: gyro: mpu3050: Fix runtime PM refcount leak in trigger enable path laixiangwu
2026-11-01  9:25   ` [PATCH] " laixiangwu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®