Skip to contentSkip to conversation

media: i2c: use pm_runtime_resume_and_get() were possible

PATCH In review Mauro Carvalho Chehab 2 participants 32 messages May 6, 2021 – May 7, 2021

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

v5 cover media: i2c: use pm_runtime_resume_and_get() were possible

Dealing with PM runtime (RPM) is different than dealing with other kAPIs used on media, as most pm_runtime_get_*() functions won't return to the the state before the call if an error rises. They, instead, increment an usage_count.

Due to that, there were several bugs on media. Just on this review, we found 24 such errors.

So, let's use pm_runtime_resume_and_get() whenever possible, as it has two advantages over :

1. On errors, it decrements the usage count;
2. It always return zero on success or an error code. This prevents a common error pattern of checking if ret is not zero to identify for errors.

There are however a few places where calls to pm_runtime_get_sync() are kept. On several of those, a comment was added, in order to help preventing trivial patches that could try to change them.

PS.: This series was submitted already together with the fix patches at:

	https://lore.kernel.org/linux-media/[email protected]/

I opted to break it on 3 parts, in order to make easier to review.

This is the second part.

Mauro Carvalho Chehab (30):
media: i2c: ak7375: use pm_runtime_resume_and_get()
media: i2c: dw9714: use pm_runtime_resume_and_get()
media: i2c: dw9768: use pm_runtime_resume_and_get()
media: i2c: dw9807-vcm: use pm_runtime_resume_and_get()
media: i2c: hi556: use pm_runtime_resume_and_get()
media: i2c: imx214: use pm_runtime_resume_and_get()
media: i2c: imx219: use pm_runtime_resume_and_get()
media: i2c: imx258: use pm_runtime_resume_and_get()
media: i2c: imx274: use pm_runtime_resume_and_get()
media: i2c: imx290: use pm_runtime_resume_and_get()
media: i2c: imx319: use pm_runtime_resume_and_get()
media: i2c: imx355: use pm_runtime_resume_and_get()
media: i2c: mt9m001: use pm_runtime_resume_and_get()
media: i2c: ov02a10: use pm_runtime_resume_and_get()
media: i2c: ov13858: use pm_runtime_resume_and_get()
media: i2c: ov2659: use pm_runtime_resume_and_get()
media: i2c: ov2685: use pm_runtime_resume_and_get()
media: i2c: ov2740: use pm_runtime_resume_and_get()
media: i2c: ov5647: use pm_runtime_resume_and_get()
media: i2c: ov5648: use pm_runtime_resume_and_get()
media: i2c: ov5670: use pm_runtime_resume_and_get()
media: i2c: ov5675: use pm_runtime_resume_and_get()
media: i2c: ov5695: use pm_runtime_resume_and_get()
media: i2c: ov7740: use pm_runtime_resume_and_get()
media: i2c: ov8856: use pm_runtime_resume_and_get()
media: i2c: ov8865: use pm_runtime_resume_and_get()
media: i2c: ov9734: use pm_runtime_resume_and_get()
media: i2c: tvp5150: use pm_runtime_resume_and_get()
media: i2c: video-i2c: use pm_runtime_resume_and_get()
media: i2c: ccs-core: use pm_runtime_resume_and_get()

 drivers/media/i2c/ak7375.c       | 10 +---------
 drivers/media/i2c/ccs/ccs-core.c |  7 ++-----
 drivers/media/i2c/dw9714.c       | 10 +---------
 drivers/media/i2c/dw9768.c       | 10 +---------
 drivers/media/i2c/dw9807-vcm.c   | 10 +---------
 drivers/media/i2c/hi556.c        |  3 +--
 drivers/media/i2c/imx214.c       |  6 ++----
 drivers/media/i2c/imx219.c       |  6 ++----
 drivers/media/i2c/imx258.c       |  6 ++----
 drivers/media/i2c/imx274.c       |  3 +--
 drivers/media/i2c/imx290.c       |  6 ++----
 drivers/media/i2c/imx319.c       |  6 ++----
 drivers/media/i2c/imx355.c       |  6 ++----
 drivers/media/i2c/mt9m001.c      |  9 +++++++--
 drivers/media/i2c/ov02a10.c      |  6 ++----
 drivers/media/i2c/ov13858.c      |  6 ++----
 drivers/media/i2c/ov2659.c       |  6 ++----
 drivers/media/i2c/ov2685.c       |  7 +++----
 drivers/media/i2c/ov2740.c       |  6 ++----
 drivers/media/i2c/ov5647.c       |  9 +++++----
 drivers/media/i2c/ov5648.c       |  6 ++----
 drivers/media/i2c/ov5670.c       |  6 ++----
 drivers/media/i2c/ov5675.c       |  3 +--
 drivers/media/i2c/ov5695.c       |  6 ++----
 drivers/media/i2c/ov7740.c       |  6 ++----
 drivers/media/i2c/ov8856.c       |  3 +--
 drivers/media/i2c/ov8865.c       |  6 ++----
 drivers/media/i2c/ov9734.c       |  3 +--
 drivers/media/i2c/tvp5150.c      | 16 +++-------------
 drivers/media/i2c/video-i2c.c    | 12 ++++--------
 30 files changed, 63 insertions(+), 142 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH v5 1/30 media: i2c: ak7375: use pm_runtime_resume_and_get()

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ak7375.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/media/i2c/ak7375.c +1 -9
index e1f94ee0f48f..40b1a4aa846c 100644
@@ -87,15 +87,7 @@ static const struct v4l2_ctrl_ops ak7375_vcm_ctrl_ops = {
 
 static int ak7375_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int ret;
-
-	ret = pm_runtime_get_sync(sd->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return ret;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int ak7375_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
Signature · 1 line
2.30.2
#2 lore raw

PATCH v5 2/30 media: i2c: dw9714: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/dw9714.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/media/i2c/dw9714.c +1 -9
index 3f0b082f863f..c8b4292512dc 100644
@@ -85,15 +85,7 @@ static const struct v4l2_ctrl_ops dw9714_vcm_ctrl_ops = {
 
 static int dw9714_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int rval;
-
-	rval = pm_runtime_get_sync(sd->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return rval;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int dw9714_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
Signature · 1 line
2.30.2
#3 lore raw

PATCH v5 3/30 media: i2c: dw9768: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/dw9768.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/media/i2c/dw9768.c +1 -9
index 8b8cb4b077b5..c086580efac7 100644
@@ -374,15 +374,7 @@ static const struct v4l2_ctrl_ops dw9768_ctrl_ops = {
 
 static int dw9768_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int ret;
-
-	ret = pm_runtime_get_sync(sd->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return ret;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int dw9768_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
Signature · 1 line
2.30.2
#4 lore raw

PATCH v5 4/30 media: i2c: dw9807-vcm: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/dw9807-vcm.c | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)
drivers/media/i2c/dw9807-vcm.c +1 -9
index 438a44b76da8..95e06f13bc9e 100644
@@ -130,15 +130,7 @@ static const struct v4l2_ctrl_ops dw9807_vcm_ctrl_ops = {
 
 static int dw9807_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int rval;
-
-	rval = pm_runtime_get_sync(sd->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return rval;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int dw9807_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
Signature · 1 line
2.30.2
#5 lore raw

PATCH v5 5/30 media: i2c: hi556: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/hi556.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/hi556.c +1 -2
index 6f05c1138e3b..627ccfa34835 100644
@@ -813,9 +813,8 @@ static int hi556_set_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&hi556->mutex);
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&hi556->mutex);
 			return ret;
 		}
Signature · 1 line
2.30.2
#6 lore raw

PATCH v5 6/30 media: i2c: imx214: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/imx214.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx214.c +2 -4
index e8b281e432e8..1a770a530cf5 100644
@@ -776,11 +776,9 @@ static int imx214_s_stream(struct v4l2_subdev *subdev, int enable)
 		return 0;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx214->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(imx214->dev);
+		ret = pm_runtime_resume_and_get(imx214->dev);
+		if (ret < 0)
 			return ret;
-		}
 
 		ret = imx214_start_streaming(imx214);
 		if (ret < 0)
Signature · 1 line
2.30.2
#7 lore raw

PATCH v5 7/30 media: i2c: imx219: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/imx219.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx219.c +2 -4
index 1054ffedaefd..74a0bf9b088b 100644
@@ -1035,11 +1035,9 @@ static int imx219_start_streaming(struct imx219 *imx219)
 	const struct imx219_reg_list *reg_list;
 	int ret;
 
-	ret = pm_runtime_get_sync(&client->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	ret = pm_runtime_resume_and_get(&client->dev);
+	if (ret < 0)
 		return ret;
-	}
 
 	/* Apply default values of current mode */
 	reg_list = &imx219->mode->reg_list;
Signature · 1 line
2.30.2
#8 lore raw

PATCH v5 8/30 media: i2c: imx258: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/imx258.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx258.c +2 -4
index a017ec4e0f50..90529424d5b6 100644
@@ -1039,11 +1039,9 @@ static int imx258_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		/*
 		 * Apply default & customized values
Signature · 1 line
2.30.2
#9 lore raw

PATCH v5 9/30 media: i2c: imx274: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/imx274.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/imx274.c +1 -2
index cdccaab3043a..ee2127436f0b 100644
@@ -1441,9 +1441,8 @@ static int imx274_s_stream(struct v4l2_subdev *sd, int on)
 	mutex_lock(&imx274->lock);
 
 	if (on) {
-		ret = pm_runtime_get_sync(&imx274->client->dev);
+		ret = pm_runtime_resume_and_get(&imx274->client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&imx274->client->dev);
 			mutex_unlock(&imx274->lock);
 			return ret;
 		}
Signature · 1 line
2.30.2
#10 lore raw

PATCH v5 10/30 media: i2c: imx290: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/imx290.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx290.c +2 -4
index 6319a42057d2..06020e648a97 100644
@@ -764,11 +764,9 @@ static int imx290_set_stream(struct v4l2_subdev *sd, int enable)
 	int ret = 0;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx290->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(imx290->dev);
+		ret = pm_runtime_resume_and_get(imx290->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
 
 		ret = imx290_start_streaming(imx290);
 		if (ret) {
Signature · 1 line
2.30.2
#11 lore raw

PATCH v5 11/30 media: i2c: imx319: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/imx319.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx319.c +2 -4
index 38540323a156..4e0a8c9d271f 100644
@@ -2141,11 +2141,9 @@ static int imx319_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		/*
 		 * Apply default & customized values
Signature · 1 line
2.30.2
#12 lore raw

PATCH v5 12/30 media: i2c: imx355: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/imx355.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/imx355.c +2 -4
index ccedcd4c520a..93f13a04439a 100644
@@ -1442,11 +1442,9 @@ static int imx355_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		/*
 		 * Apply default & customized values
Signature · 1 line
2.30.2
#13 lore raw

PATCH v5 13/30 media: i2c: mt9m001: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/mt9m001.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/i2c/mt9m001.c +7 -2
index 3b0ba8ed5233..58c85a3bccf6 100644
@@ -217,9 +217,9 @@ static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable)
 		goto done;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0)
-			goto put_unlock;
+			goto unlock;
 
 		ret = mt9m001_apply_selection(sd);
 		if (ret)
@@ -247,6 +247,7 @@ static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable)
 
 put_unlock:
 	pm_runtime_put(&client->dev);
+unlock:
 	mutex_unlock(&mt9m001->mutex);
 
 	return ret;
@@ -834,6 +835,10 @@ static int mt9m001_remove(struct i2c_client *client)
 {
 	struct mt9m001 *mt9m001 = to_mt9m001(client);
 
+	/*
+	 * As it increments RPM usage_count even on errors, we don't need to
+	 * check the returned code here.
+	 */
 	pm_runtime_get_sync(&client->dev);
 
 	v4l2_async_unregister_subdev(&mt9m001->subdev);
Signature · 1 line
2.30.2
#14 lore raw

PATCH v5 14/30 media: i2c: ov02a10: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov02a10.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov02a10.c +2 -4
index c47b1d45d8fd..a1d7314b20a9 100644
@@ -540,11 +540,9 @@ static int ov02a10_s_stream(struct v4l2_subdev *sd, int on)
 	}
 
 	if (on) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
 
 		ret = __ov02a10_start_stream(ov02a10);
 		if (ret) {
Signature · 1 line
2.30.2
#15 lore raw

PATCH v5 15/30 media: i2c: ov13858: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov13858.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov13858.c +2 -4
index 4a2885ff0cbe..9598c0b19603 100644
@@ -1472,11 +1472,9 @@ static int ov13858_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		/*
 		 * Apply default & customized values
Signature · 1 line
2.30.2
#16 lore raw

PATCH v5 16/30 media: i2c: ov2659: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov2659.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov2659.c +2 -4
index 42f64175a6df..a3c8eae68486 100644
@@ -1186,11 +1186,9 @@ static int ov2659_s_stream(struct v4l2_subdev *sd, int on)
 		goto unlock;
 	}
 
-	ret = pm_runtime_get_sync(&client->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	ret = pm_runtime_resume_and_get(&client->dev);
+	if (ret < 0)
 		goto unlock;
-	}
 
 	ret = ov2659_init(sd, 0);
 	if (!ret)
Signature · 1 line
2.30.2
#17 lore raw

PATCH v5 17/30 media: i2c: ov2685: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov2685.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/media/i2c/ov2685.c +3 -4
index 49a2dcedb347..2f3836dd8eed 100644
@@ -456,11 +456,10 @@ static int ov2685_s_stream(struct v4l2_subdev *sd, int on)
 		goto unlock_and_return;
 
 	if (on) {
-		ret = pm_runtime_get_sync(&ov2685->client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&ov2685->client->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
+
 		ret = __v4l2_ctrl_handler_setup(&ov2685->ctrl_handler);
 		if (ret) {
 			pm_runtime_put(&client->dev);
Signature · 1 line
2.30.2
#18 lore raw

PATCH v5 18/30 media: i2c: ov2740: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov2740.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov2740.c +2 -4
index 0f3f17f3c426..54779f720f9d 100644
@@ -751,9 +751,8 @@ static int ov2740_set_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&ov2740->mutex);
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&ov2740->mutex);
 			return ret;
 		}
@@ -1049,9 +1048,8 @@ static int ov2740_nvmem_read(void *priv, unsigned int off, void *val,
 		goto exit;
 	}
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(dev);
 		goto exit;
 	}
 
Signature · 1 line
2.30.2
#19 lore raw

PATCH v5 19/30 media: i2c: ov5647: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov5647.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5647.c +5 -4
index 1cefa15729ce..38faa74755e3 100644
@@ -882,20 +882,20 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0)
 			goto error_unlock;
 
 		ret = ov5647_stream_on(sd);
 		if (ret < 0) {
 			dev_err(&client->dev, "stream start failed: %d\n", ret);
-			goto error_unlock;
+			goto error_pm;
 		}
 	} else {
 		ret = ov5647_stream_off(sd);
 		if (ret < 0) {
 			dev_err(&client->dev, "stream stop failed: %d\n", ret);
-			goto error_unlock;
+			goto error_pm;
 		}
 		pm_runtime_put(&client->dev);
 	}
@@ -905,8 +905,9 @@ static int ov5647_s_stream(struct v4l2_subdev *sd, int enable)
 
 	return 0;
 
+error_pm:
+	pm_runtime_put(&client->dev);
 error_unlock:
-	pm_runtime_put(&client->dev);
 	mutex_unlock(&sensor->lock);
 
 	return ret;
Signature · 1 line
2.30.2
#20 lore raw

PATCH v5 20/30 media: i2c: ov5648: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov5648.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5648.c +2 -4
index 3ecb4a3e8773..07e64ff0be3f 100644
@@ -2132,11 +2132,9 @@ static int ov5648_s_stream(struct v4l2_subdev *subdev, int enable)
 	int ret;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(sensor->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(sensor->dev);
+		ret = pm_runtime_resume_and_get(sensor->dev);
+		if (ret < 0)
 			return ret;
-		}
 	}
 
 	mutex_lock(&sensor->mutex);
Signature · 1 line
2.30.2
#21 lore raw

PATCH v5 21/30 media: i2c: ov5670: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov5670.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5670.c +2 -4
index dee7df8dd100..182f271f118f 100644
@@ -2347,11 +2347,9 @@ static int ov5670_set_stream(struct v4l2_subdev *sd, int enable)
 		goto unlock_and_return;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
 
 		ret = ov5670_start_streaming(ov5670);
 		if (ret)
Signature · 1 line
2.30.2
#22 lore raw

PATCH v5 22/30 media: i2c: ov5675: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov5675.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ov5675.c +1 -2
index dea32859459a..e7e297a23960 100644
@@ -863,9 +863,8 @@ static int ov5675_set_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&ov5675->mutex);
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&ov5675->mutex);
 			return ret;
 		}
Signature · 1 line
2.30.2
#23 lore raw

PATCH v5 23/30 media: i2c: ov5695: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov5695.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov5695.c +2 -4
index 09bee57a241d..469d941813c6 100644
@@ -946,11 +946,9 @@ static int ov5695_s_stream(struct v4l2_subdev *sd, int on)
 		goto unlock_and_return;
 
 	if (on) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto unlock_and_return;
-		}
 
 		ret = __ov5695_start_stream(ov5695);
 		if (ret) {
Signature · 1 line
2.30.2
#24 lore raw

PATCH v5 24/30 media: i2c: ov7740: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov7740.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov7740.c +2 -4
index 47a9003d29d6..e0ff6506a543 100644
@@ -624,11 +624,9 @@ static int ov7740_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
+		if (ret < 0)
 			goto err_unlock;
-		}
 
 		ret = ov7740_start_streaming(ov7740);
 		if (ret)
Signature · 1 line
2.30.2
#25 lore raw

PATCH v5 25/30 media: i2c: ov8856: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov8856.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ov8856.c +1 -2
index e3af3ea277af..2875f8e4ddcb 100644
@@ -1340,9 +1340,8 @@ static int ov8856_set_stream(struct v4l2_subdev *sd, int enable)
 
 	mutex_lock(&ov8856->mutex);
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&ov8856->mutex);
 			return ret;
 		}
Signature · 1 line
2.30.2
#26 lore raw

PATCH v5 26/30 media: i2c: ov8865: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov8865.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/media/i2c/ov8865.c +2 -4
index 9ecf180635ee..3bf6ee4898a9 100644
@@ -2497,11 +2497,9 @@ static int ov8865_s_stream(struct v4l2_subdev *subdev, int enable)
 	int ret;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(sensor->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(sensor->dev);
+		ret = pm_runtime_resume_and_get(sensor->dev);
+		if (ret < 0)
 			return ret;
-		}
 	}
 
 	mutex_lock(&sensor->mutex);
Signature · 1 line
2.30.2
#27 lore raw

PATCH v5 27/30 media: i2c: ov9734: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ov9734.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/media/i2c/ov9734.c +1 -2
index b7309a551cae..ba156683c533 100644
@@ -644,9 +644,8 @@ static int ov9734_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(&client->dev);
+		ret = pm_runtime_resume_and_get(&client->dev);
 		if (ret < 0) {
-			pm_runtime_put_noidle(&client->dev);
 			mutex_unlock(&ov9734->mutex);
 			return ret;
 		}
Signature · 1 line
2.30.2
#28 lore raw

PATCH v5 28/30 media: i2c: tvp5150: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/tvp5150.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
drivers/media/i2c/tvp5150.c +3 -13
index e26e3f544054..374a9da75e4d 100644
@@ -1448,11 +1448,9 @@ static int tvp5150_s_stream(struct v4l2_subdev *sd, int enable)
 	       TVP5150_MISC_CTL_CLOCK_OE;
 
 	if (enable) {
-		ret = pm_runtime_get_sync(sd->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(sd->dev);
+		ret = pm_runtime_resume_and_get(sd->dev);
+		if (ret < 0)
 			return ret;
-		}
 
 		tvp5150_enable(sd);
 
@@ -1675,15 +1673,7 @@ static int tvp5150_registered(struct v4l2_subdev *sd)
 
 static int tvp5150_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 {
-	int ret;
-
-	ret = pm_runtime_get_sync(sd->dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(sd->dev);
-		return ret;
-	}
-
-	return 0;
+	return pm_runtime_resume_and_get(sd->dev);
 }
 
 static int tvp5150_close(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
Signature · 1 line
2.30.2
#29 lore raw

PATCH v5 29/30 media: i2c: video-i2c: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/video-i2c.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/media/i2c/video-i2c.c +4 -8
index 0465832a4090..de12f38f347c 100644
@@ -286,11 +286,9 @@ static int amg88xx_read(struct device *dev, enum hwmon_sensor_types type,
 	__le16 buf;
 	int tmp;
 
-	tmp = pm_runtime_get_sync(regmap_get_device(data->regmap));
-	if (tmp < 0) {
-		pm_runtime_put_noidle(regmap_get_device(data->regmap));
+	tmp = pm_runtime_resume_and_get(regmap_get_device(data->regmap));
+	if (tmp < 0)
 		return tmp;
-	}
 
 	tmp = regmap_bulk_read(data->regmap, AMG88XX_REG_TTHL, &buf, 2);
 	pm_runtime_mark_last_busy(regmap_get_device(data->regmap));
@@ -512,11 +510,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 	if (data->kthread_vid_cap)
 		return 0;
 
-	ret = pm_runtime_get_sync(dev);
-	if (ret < 0) {
-		pm_runtime_put_noidle(dev);
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret < 0)
 		goto error_del_list;
-	}
 
 	ret = data->chip->setup(data);
 	if (ret)
Signature · 1 line
2.30.2
maintainer Acked-by on v5 29/30
#30 lore raw

Re: [PATCH v5 29/30] media: i2c: video-i2c: use pm_runtime_resume_and_get()

Quoted 7 lines · Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

Quoted 40 lines
---
 drivers/media/i2c/video-i2c.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/media/i2c/video-i2c.c +4 -9
index 0465832a4090..de12f38f347c 100644
@@ -286,11 +286,9 @@ static int amg88xx_read(struct device *dev, enum hwmon_sensor_types type,
        __le16 buf;
        int tmp;
 
-       tmp = pm_runtime_get_sync(regmap_get_device(data->regmap));
-       if (tmp < 0) {
-               pm_runtime_put_noidle(regmap_get_device(data->regmap));
+       tmp = pm_runtime_resume_and_get(regmap_get_device(data->regmap));
+       if (tmp < 0)
                return tmp;
-       }
 
        tmp = regmap_bulk_read(data->regmap, AMG88XX_REG_TTHL, &buf, 2);
        pm_runtime_mark_last_busy(regmap_get_device(data->regmap));
@@ -512,11 +510,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
        if (data->kthread_vid_cap)
                return 0;
 
-       ret = pm_runtime_get_sync(dev);
-       if (ret < 0) {
-               pm_runtime_put_noidle(dev);
+       ret = pm_runtime_resume_and_get(dev);
+       if (ret < 0)
                goto error_del_list;
-       }
 
        ret = data->chip->setup(data);
        if (ret)
--

2.30.2

#31 lore raw

PATCH v5 30/30 media: i2c: ccs-core: use pm_runtime_resume_and_get()

In reply to Mauro Carvalho Chehab

Commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") added pm_runtime_resume_and_get() in order to automatically handle dev->power.usage_count decrement on errors.

Use the new API, in order to cleanup the error check logic.

---
 drivers/media/i2c/ccs/ccs-core.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +2 -5
index 4a848ac2d2cd..a349189a38db 100644
@@ -3101,12 +3101,9 @@ static int __maybe_unused ccs_suspend(struct device *dev)
 	bool streaming = sensor->streaming;
 	int rval;
 
-	rval = pm_runtime_get_sync(dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(dev);
-
+	rval = pm_runtime_resume_and_get(dev);
+	if (rval < 0)
 		return rval;
-	}
 
 	if (sensor->streaming)
 		ccs_stop_streaming(sensor);
Signature · 1 line
2.30.2