Skip to contentSkip to conversation

media: i2c: ov5648: Plug runtime pm counter leak

PATCH In review Pratyush Yadav 2 participants 2 messages May 11, 2021 – May 21, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: i2c: ov5648: Plug runtime pm counter leak

When the stream is being enabled, the runtime pm usage counter is incremented. Then if ov5648_sw_standby() fails, the function returns error without decrementing the counter, leaking it.

---

Hi,

I spotted this when converting OV5640 driver to use runtime PM using this driver as reference. I only have a very surface level understanding of runtime PM system as of now so please review with that in mind.

This patch is only compile-tested since I don't have the hardware with me.

 drivers/media/i2c/ov5648.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/i2c/ov5648.c +5 -1
index 3ecb4a3e8773..6aa2c950f505 100644
@@ -2143,8 +2143,12 @@ static int ov5648_s_stream(struct v4l2_subdev *subdev, int enable)
 	ret = ov5648_sw_standby(sensor, !enable);
 	mutex_unlock(&sensor->mutex);
 
-	if (ret)
+	if (ret) {
+		if (enable)
+			pm_runtime_put(sensor->dev);
+
 		return ret;
+	}
 
 	state->streaming = !!enable;
 

--
2.30.0

#1 lore raw

Hi Pratyush,

Thanks for the patch.

Quoted 24 lines · Pratyush Yadav

When the stream is being enabled, the runtime pm usage counter is incremented. Then if ov5648_sw_standby() fails, the function returns error without decrementing the counter, leaking it.

---

Hi,

I spotted this when converting OV5640 driver to use runtime PM using this driver as reference. I only have a very surface level understanding of runtime PM system as of now so please review with that in mind.

This patch is only compile-tested since I don't have the hardware with me.

 drivers/media/i2c/ov5648.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/i2c/ov5648.c +0 -0
index 3ecb4a3e8773..6aa2c950f505 100644

drivers/media/i2c/ov5648.c static int ov5648_s_stream(struct v4l2_subdev *subdev, int enable) · line 2148

Quoted 7 lines
drivers/media/i2c/ov5648.c +3 -1
@@ -2143,8 +2143,12 @@ static int ov5648_s_stream(struct v4l2_subdev *subdev, int enable)
 	ret = ov5648_sw_standby(sensor, !enable);
 	mutex_unlock(&sensor->mutex);
 
-	if (ret)
+	if (ret) {
+		if (enable)
+			pm_runtime_put(sensor->dev);

The function powers the sensor off at the end if streaming was to be disabled. You could do:

	if (ret || !enable)
		pm_runtime_put(sensor->dev);

drivers/media/i2c/ov5648.c static int ov5648_s_stream(struct v4l2_subdev *subdev, int enable) · line 2153

Quoted 5 lines
drivers/media/i2c/ov5648.c +2 -0
+
 		return ret;
+	}
 
 	state->streaming = !!enable;

state->streaming is assigned when not holding the lock. Could you address that at the same time?

Signature · 3 lines
Kind regards,

Sakari Ailus