Skip to contentSkip to conversation

Fix some PM runtime issues at the media subsystem

PATCH In review Mauro Carvalho Chehab 9 participants 73 messages May 5, 2021 – Sep 13, 2021

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

cover Fix some PM runtime issues at the media subsystem

As part of an effort to cleanup pm_runtime*get* calls, I detected a number of issues at the media subsystem.

Most of the patches here were submitted previously at:

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

This series contain just the bug fixes and other related issues that are present with the current code on media.

It address the points from the existing reviews. I also did my own set of reviews, in order to avoid regressions.

Changes from v4 of the previous changeset:

- reworked i2c/css RPM get logic;
- dropped two patches that could cause regressions;
- am437x: keep using pm_runtime_get_sync on suspend/resume;
- atmel: fix the returned code and add a print on failures at start streaming;
- simplify some checks for return code > 0;
- mdk-vcodec: properly handle RPM errors at device on logic;
- venus: rework venus_sys_error_handler() logic;
- sti/delta: fix an issue at the error checking logic.

Mauro Carvalho Chehab (25):
staging: media: rkvdec: fix pm_runtime_get_sync() usage count
staging: media: imx7-mipi-csis: fix pm_runtime_get_sync() usage count
media: venus: Rework error fail recover logic
media: s5p_cec: decrement usage count if disabled
media: i2c: ccs-core: return the right error code at suspend
media: i2c: imx334: fix the pm runtime get logic
media: exynos-gsc: don't resume at remove time
media: atmel: properly get pm_runtime
media: hantro: do a PM resume earlier
media: marvel-ccic: fix some issues when getting pm_runtime
media: mdk-mdp: fix pm_runtime_get_sync() usage count
media: rcar_fdp1: simplify error check logic at fdp_open()
media: rcar_fdp1: fix pm_runtime_get_sync() usage count
media: renesas-ceu: Properly check for PM errors
media: s5p: fix pm_runtime_get_sync() usage count
media: am437x: fix pm_runtime_get_sync() usage count
media: sh_vou: fix pm_runtime_get_sync() usage count
media: mtk-vcodec: fix PM runtime get logic
media: s5p-jpeg: fix pm_runtime_get_sync() usage count
media: sti/delta: use pm_runtime_resume_and_get()
media: sunxi: fix pm_runtime_get_sync() usage count
media: sti/bdisp: fix pm_runtime_get_sync() usage count
media: exynos4-is: fix pm_runtime_get_sync() usage count
media: exynos-gsc: fix pm_runtime_get_sync() usage count
media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

 drivers/media/cec/platform/s5p/s5p_cec.c      |  7 ++-
 drivers/media/i2c/ccs/ccs-core.c              | 41 ++++++++-----
 drivers/media/i2c/imx334.c                    |  7 ++-
 drivers/media/platform/am437x/am437x-vpfe.c   | 15 ++++-
 drivers/media/platform/atmel/atmel-isc-base.c | 30 +++++++---
 drivers/media/platform/atmel/atmel-isi.c      | 19 ++++--
 drivers/media/platform/exynos-gsc/gsc-core.c  | 11 ++--
 drivers/media/platform/exynos-gsc/gsc-m2m.c   |  4 +-
 .../media/platform/exynos4-is/fimc-capture.c  |  6 +-
 drivers/media/platform/exynos4-is/fimc-is.c   |  4 +-
 .../platform/exynos4-is/fimc-isp-video.c      |  3 +-
 drivers/media/platform/exynos4-is/fimc-isp.c  |  7 +--
 drivers/media/platform/exynos4-is/fimc-lite.c |  5 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c  |  5 +-
 drivers/media/platform/exynos4-is/media-dev.c |  9 +--
 drivers/media/platform/exynos4-is/mipi-csis.c | 10 ++--
 .../media/platform/marvell-ccic/mcam-core.c   |  9 ++-
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c  |  6 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  |  4 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.c   |  8 ++-
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.h   |  2 +-
 drivers/media/platform/qcom/venus/core.c      | 59 +++++++++++++++----
 drivers/media/platform/rcar_fdp1.c            | 28 ++++++---
 drivers/media/platform/renesas-ceu.c          |  4 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c   |  5 +-
 drivers/media/platform/sh_vou.c               |  6 +-
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c |  7 ++-
 drivers/media/platform/sti/delta/delta-v4l2.c |  8 +--
 .../sunxi/sun8i-rotate/sun8i_rotate.c         |  2 +-
 drivers/staging/media/hantro/hantro_drv.c     |  7 ++-
 drivers/staging/media/imx/imx7-mipi-csis.c    |  7 +--
 drivers/staging/media/rkvdec/rkvdec.c         |  2 +-
 32 files changed, 220 insertions(+), 127 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/25 staging: media: rkvdec: fix pm_runtime_get_sync() usage count

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

---
 drivers/staging/media/rkvdec/rkvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/rkvdec/rkvdec.c +1 -1
index d821661d30f3..8c17615f3a7a 100644
@@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
 	if (WARN_ON(!desc))
 		return;
 
-	ret = pm_runtime_get_sync(rkvdec->dev);
+	ret = pm_runtime_resume_and_get(rkvdec->dev);
 	if (ret < 0) {
 		rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
 		return;
Signature · 1 line
2.30.2
Reviewed-by on v1 1/25
#2 lore raw

Re: [PATCH 01/25] staging: media: rkvdec: fix pm_runtime_get_sync() usage count

Quoted 9 lines · On Wed, 5 May 2021 11:41:51 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

(I'll do tags per patch as there are some open ones and it would be odd to say - "excluding xxxx" in reply to the cover letter)

Quoted 17 lines
---
 drivers/staging/media/rkvdec/rkvdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/rkvdec/rkvdec.c +1 -1
index d821661d30f3..8c17615f3a7a 100644
@@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
 	if (WARN_ON(!desc))
 		return;
 
-	ret = pm_runtime_get_sync(rkvdec->dev);
+	ret = pm_runtime_resume_and_get(rkvdec->dev);
 	if (ret < 0) {
 		rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
 		return;
#3 lore raw

PATCH 2/25 staging: media: imx7-mipi-csis: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/media/imx/imx7-mipi-csis.c +3 -4
index 025fdc488bd6..1dc680d94a46 100644
@@ -695,11 +695,10 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 
 		mipi_csis_clear_counters(state);
 
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			goto done;
Signature · 1 line
2.30.2
#4 lore raw

Re: [PATCH 02/25] staging: media: imx7-mipi-csis: fix pm_runtime_get_sync() usage count

Quoted 9 lines · On Wed, 5 May 2021 11:41:52 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Not a fix as far as I can see, just a cleanup - so perhaps not this set?

Jonathan

Quoted 23 lines
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/media/imx/imx7-mipi-csis.c +3 -4
index 025fdc488bd6..1dc680d94a46 100644
@@ -695,11 +695,10 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 
 		mipi_csis_clear_counters(state);
 
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			goto done;
#5 lore raw

Re: [PATCH 02/25] staging: media: imx7-mipi-csis: fix pm_runtime_get_sync() usage count

Em Wed, 5 May 2021 12:06:52 +0100
Jonathan Cameron <[email protected]> escreveu:

Quoted 10 lines
Quoted 7 lines · On Wed, 5 May 2021 11:41:52 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 4 lines
Quoted 2 lines

Not a fix as far as I can see, just a cleanup - so perhaps not this set?

Yeah, will move it to the non-error patch pile and change the comments.

Quoted 16 lines

Jonathan

Quoted 12 lines
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/media/imx/imx7-mipi-csis.c +0 -0
index 025fdc488bd6..1dc680d94a46 100644
@@ -695,11 +695,10 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 
 		mipi_csis_clear_counters(state);
 
Quoted 12 lines

drivers/staging/media/imx/imx7-mipi-csis.c static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable) · line 704

Quoted 11 lines
drivers/staging/media/imx/imx7-mipi-csis.c +3 -4
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			goto done;  

Thanks,
Mauro

#6 lore raw

Re: [PATCH 02/25] staging: media: imx7-mipi-csis: fix pm_runtime_get_sync() usage count

In reply to Jonathan Cameron

Hi,

Quoted 10 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 5 May 2021 11:41:52 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 4 lines
Quoted 2 lines

Not a fix as far as I can see, just a cleanup - so perhaps not this set?

yes, the original changelog of this patch, that I acked, made it clear it was a cleanup:

"
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. "

This one above is new, but I saw Mauro is going change it.

------
Cheers,
Rui

Quoted 27 lines

Jonathan

Quoted 23 lines
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/staging/media/imx/imx7-mipi-csis.c +3 -4
index 025fdc488bd6..1dc680d94a46 100644
@@ -695,11 +695,10 @@ static int mipi_csis_s_stream(struct v4l2_subdev *mipi_sd, int enable)
 
 		mipi_csis_clear_counters(state);
 
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		ret = v4l2_subdev_call(state->src_sd, core, s_power, 1);
 		if (ret < 0 && ret != -ENOIOCTLCMD)
 			goto done;
#7 lore raw

Re: [PATCH 02/25] staging: media: imx7-mipi-csis: fix pm_runtime_get_sync() usage count

Em Wed, 05 May 2021 14:56:40 +0100
"Rui Miguel Silva" <[email protected]> escreveu:

Quoted 27 lines

Hi,

Quoted 10 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 5 May 2021 11:41:52 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 4 lines
Quoted 2 lines

Not a fix as far as I can see, just a cleanup - so perhaps not this set?

yes, the original changelog of this patch, that I acked, made it clear it was a cleanup:

"
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.

Quoted 4 lines

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

This one above is new, but I saw Mauro is going change it.

Yes, I'll change the subject/description to the
"use pm_runtime_resume_and_get()" one on this patch, as there's no issue to be fixed here, just a cleanup ;-)

Sorry for the mess. I did lots of rebase on ~80 patch series over the last couple of days, based on the reviews (and my own internal reviews)...

See, the current patchset has ~80 patches with ~30% contained fixes. It shows that writing a balanced PM runtime code is not so trivial ;-)

Thanks,
Mauro

#8 lore raw

PATCH 3/25 media: venus: Rework error fail recover logic

In reply to Mauro Carvalho Chehab

The Venus code has a sort of watchdog that attempts to recover from IP errors, implemented as a delayed work job, which calls venus_sys_error_handler().

Right now, it has several issues:

1. It assumes that PM runtime resume never fails

2. It internally runs two while() loops that also assume that PM runtime will never fail to go idle:

	while (pm_runtime_active(core->dev_dec) || pm_runtime_active(core->dev_enc))
		msleep(10);

...

	while (core->pmdomains[0] && pm_runtime_active(core->pmdomains[0]))
		usleep_range(1000, 1500);

3. It uses an OR to merge all return codes and then report to the user

4. If the hardware never recovers, it keeps running on every 10ms, flooding the syslog with 2 messages (so, up to 200 messages per second).

Rework the code, in order to prevent that, by:

1. check the return code from PM runtime resume;
2. don't let the while() loops run forever;
3. store the failed event;
4. use warn ratelimited when it fails to recover.

Fixes af2c3834c8ca ("[media] media: venus: adding core part and helper functions")
---
 drivers/media/platform/qcom/venus/core.c | 59 +++++++++++++++++++-----
 1 file changed, 47 insertions(+), 12 deletions(-)
drivers/media/platform/qcom/venus/core.c +47 -12
index 54bac7ec14c5..4d0482743c0a 100644
@@ -78,22 +78,32 @@ static const struct hfi_core_ops venus_core_ops = {
 	.event_notify = venus_event_notify,
 };
 
+#define RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS 10
+
 static void venus_sys_error_handler(struct work_struct *work)
 {
 	struct venus_core *core =
 			container_of(work, struct venus_core, work.work);
-	int ret = 0;
+	int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
+	bool failed = false;
+	const char *err_msg = "";
 
-	pm_runtime_get_sync(core->dev);
+	ret = pm_runtime_get_sync(core->dev);
+	if (ret < 0) {
+		err_msg = "resume runtime PM\n";
+		max_attempts = 0;
+		failed = true;
+	}
 
 	hfi_core_deinit(core, true);
 
-	dev_warn(core->dev, "system error has occurred, starting recovery!\n");
-
 	mutex_lock(&core->lock);
 
-	while (pm_runtime_active(core->dev_dec) || pm_runtime_active(core->dev_enc))
+	for (i = 0; i < max_attempts; i++) {
+		if (!pm_runtime_active(core->dev_dec) && !pm_runtime_active(core->dev_enc))
+			break;
 		msleep(10);
+	}
 
 	venus_shutdown(core);
 
@@ -101,31 +111,56 @@ static void venus_sys_error_handler(struct work_struct *work)
 
 	pm_runtime_put_sync(core->dev);
 
-	while (core->pmdomains[0] && pm_runtime_active(core->pmdomains[0]))
+	for (i = 0; i < max_attempts; i++) {
+		if (!core->pmdomains[0] || !pm_runtime_active(core->pmdomains[0]))
+			break;
 		usleep_range(1000, 1500);
+	}
 
 	hfi_reinit(core);
 
-	pm_runtime_get_sync(core->dev);
+	ret = pm_runtime_get_sync(core->dev);
+	if (ret < 0) {
+		err_msg = "resume runtime PM\n";
+		max_attempts = 0;
+		failed = true;
+	}
 
-	ret |= venus_boot(core);
-	ret |= hfi_core_resume(core, true);
+	ret = venus_boot(core);
+	if (ret && !failed) {
+		err_msg = "boot Venus\n";
+		failed = true;
+	}
+
+	ret = hfi_core_resume(core, true);
+	if (ret && !failed) {
+		err_msg = "resume HFI\n";
+		failed = true;
+	}
 
 	enable_irq(core->irq);
 
 	mutex_unlock(&core->lock);
 
-	ret |= hfi_core_init(core);
+	ret = hfi_core_init(core);
+	if (ret && !failed) {
+		err_msg = "init HFI\n";
+		failed = true;
+	}
 
 	pm_runtime_put_sync(core->dev);
 
-	if (ret) {
+	if (failed) {
 		disable_irq_nosync(core->irq);
-		dev_warn(core->dev, "recovery failed (%d)\n", ret);
+		dev_warn_ratelimited(core->dev,
+				     "System error has occurred, recovery failed to %s\n",
+				     err_msg);
 		schedule_delayed_work(&core->work, msecs_to_jiffies(10));
 		return;
 	}
 
+	dev_warn(core->dev, "system error has occurred (recovered)\n");
+
 	mutex_lock(&core->lock);
 	core->sys_error = false;
 	mutex_unlock(&core->lock);
Signature · 1 line
2.30.2
Reviewed-by on v1 3/25
#9 lore raw

Re: [PATCH 03/25] media: venus: Rework error fail recover logic

Quoted 27 lines · On Wed, 5 May 2021 11:41:53 +0200 Mauro Carvalho Chehab…

The Venus code has a sort of watchdog that attempts to recover from IP errors, implemented as a delayed work job, which calls venus_sys_error_handler().

Right now, it has several issues:

1. It assumes that PM runtime resume never fails

2. It internally runs two while() loops that also assume that PM runtime will never fail to go idle:

	while (pm_runtime_active(core->dev_dec) || pm_runtime_active(core->dev_enc))
		msleep(10);

...

	while (core->pmdomains[0] && pm_runtime_active(core->pmdomains[0]))
		usleep_range(1000, 1500);

3. It uses an OR to merge all return codes and then report to the user

4. If the hardware never recovers, it keeps running on every 10ms, flooding the syslog with 2 messages (so, up to 200 messages per second).

Rework the code, in order to prevent that, by:

Quoted 7 lines

1. check the return code from PM runtime resume;
2. don't let the while() loops run forever;
3. store the failed event;
4. use warn ratelimited when it fails to recover.

Fixes af2c3834c8ca ("[media] media: venus: adding core part and helper functions")

Trivial comments inline, otherwise based on no knowledge at all of the actual hardware, the fix looks sane.

Quoted 17 lines
---
 drivers/media/platform/qcom/venus/core.c | 59 +++++++++++++++++++-----
 1 file changed, 47 insertions(+), 12 deletions(-)
drivers/media/platform/qcom/venus/core.c +2 -0
index 54bac7ec14c5..4d0482743c0a 100644
@@ -78,22 +78,32 @@ static const struct hfi_core_ops venus_core_ops = {
 	.event_notify = venus_event_notify,
 };
 
+#define RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS 10
+
 static void venus_sys_error_handler(struct work_struct *work)
 {
 	struct venus_core *core =

drivers/media/platform/qcom/venus/core.c static const struct hfi_core_ops venus_core_ops = { · line 93

Quoted 10 lines
drivers/media/platform/qcom/venus/core.c +6 -2
 			container_of(work, struct venus_core, work.work);
-	int ret = 0;
+	int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
+	bool failed = false;
+	const char *err_msg = "";
 
-	pm_runtime_get_sync(core->dev);
+	ret = pm_runtime_get_sync(core->dev);
+	if (ret < 0) {
+		err_msg = "resume runtime PM\n";

Will end up with two newlines I think as %s\n" later.

Quoted 27 lines
drivers/media/platform/qcom/venus/core.c +10 -4
+		max_attempts = 0;
+		failed = true;
+	}
 
 	hfi_core_deinit(core, true);
 
-	dev_warn(core->dev, "system error has occurred, starting recovery!\n");
-
 	mutex_lock(&core->lock);
 
-	while (pm_runtime_active(core->dev_dec) || pm_runtime_active(core->dev_enc))
+	for (i = 0; i < max_attempts; i++) {
+		if (!pm_runtime_active(core->dev_dec) && !pm_runtime_active(core->dev_enc))
+			break;
 		msleep(10);
+	}
 
 	venus_shutdown(core);
 
@@ -101,31 +111,56 @@ static void venus_sys_error_handler(struct work_struct *work)
 
 	pm_runtime_put_sync(core->dev);
 
-	while (core->pmdomains[0] && pm_runtime_active(core->pmdomains[0]))
+	for (i = 0; i < max_attempts; i++) {
+		if (!core->pmdomains[0] || !pm_runtime_active(core->pmdomains[0]))
+			break;

drivers/media/platform/qcom/venus/core.c static void venus_sys_error_handler(struct work_struct *work) · line 125

Quoted 10 lines
drivers/media/platform/qcom/venus/core.c +5 -1
 		usleep_range(1000, 1500);
+	}
 
 	hfi_reinit(core);
 
-	pm_runtime_get_sync(core->dev);
+	ret = pm_runtime_get_sync(core->dev);
+	if (ret < 0) {
+		err_msg = "resume runtime PM\n";
+		max_attempts = 0;

This is after the last use of max_attempts, so no point in setting it to zero.

Quoted 46 lines
drivers/media/platform/qcom/venus/core.c +24 -5
+		failed = true;
+	}
 
-	ret |= venus_boot(core);
-	ret |= hfi_core_resume(core, true);
+	ret = venus_boot(core);
+	if (ret && !failed) {
+		err_msg = "boot Venus\n";
+		failed = true;
+	}
+
+	ret = hfi_core_resume(core, true);
+	if (ret && !failed) {
+		err_msg = "resume HFI\n";
+		failed = true;
+	}
 
 	enable_irq(core->irq);
 
 	mutex_unlock(&core->lock);
 
-	ret |= hfi_core_init(core);
+	ret = hfi_core_init(core);
+	if (ret && !failed) {
+		err_msg = "init HFI\n";
+		failed = true;
+	}
 
 	pm_runtime_put_sync(core->dev);
 
-	if (ret) {
+	if (failed) {
 		disable_irq_nosync(core->irq);
-		dev_warn(core->dev, "recovery failed (%d)\n", ret);
+		dev_warn_ratelimited(core->dev,
+				     "System error has occurred, recovery failed to %s\n",
+				     err_msg);
 		schedule_delayed_work(&core->work, msecs_to_jiffies(10));
 		return;
 	}
 
+	dev_warn(core->dev, "system error has occurred (recovered)\n");
+
 	mutex_lock(&core->lock);
 	core->sys_error = false;
 	mutex_unlock(&core->lock);
#10 lore raw

PATCH 4/25 media: s5p_cec: decrement usage count if disabled

In reply to Mauro Carvalho Chehab

There's a bug at s5p_cec_adap_enable(): if called to disable the device, it should call pm_runtime_put() instead of pm_runtime_disable(), as the goal here is to decrement the usage_count and not to disable PM runtime.

Fixes 1bcbf6f4b6b0 ("[media] cec: s5p-cec: Add s5p-cec driver")
---
 drivers/media/cec/platform/s5p/s5p_cec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/cec/platform/s5p/s5p_cec.c +1 -1
index 2a3e7ffefe0a..3c7c4c3c798c 100644
@@ -51,7 +51,7 @@ static int s5p_cec_adap_enable(struct cec_adapter *adap, bool enable)
 	} else {
 		s5p_cec_mask_tx_interrupts(cec);
 		s5p_cec_mask_rx_interrupts(cec);
-		pm_runtime_disable(cec->dev);
+		pm_runtime_put(cec->dev);
 	}
 
 	return 0;
Signature · 1 line
2.30.2
Reviewed-by on v1 4/25
#11 lore raw

Re: [PATCH 04/25] media: s5p_cec: decrement usage count if disabled

Quoted 8 lines · On Wed, 5 May 2021 11:41:54 +0200 Mauro Carvalho Chehab…

There's a bug at s5p_cec_adap_enable(): if called to disable the device, it should call pm_runtime_put() instead of pm_runtime_disable(), as the goal here is to decrement the usage_count and not to disable PM runtime.

Fixes 1bcbf6f4b6b0 ("[media] cec: s5p-cec: Add s5p-cec driver")
Quoted 17 lines
---
 drivers/media/cec/platform/s5p/s5p_cec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/cec/platform/s5p/s5p_cec.c +1 -1
index 2a3e7ffefe0a..3c7c4c3c798c 100644
@@ -51,7 +51,7 @@ static int s5p_cec_adap_enable(struct cec_adapter *adap, bool enable)
 	} else {
 		s5p_cec_mask_tx_interrupts(cec);
 		s5p_cec_mask_rx_interrupts(cec);
-		pm_runtime_disable(cec->dev);
+		pm_runtime_put(cec->dev);
 	}
 
 	return 0;
#12 lore raw

PATCH 5/25 media: i2c: ccs-core: return the right error code at suspend

In reply to Mauro Carvalho Chehab

If pm_runtime resume logic fails, return the error code provided by it, instead of -EAGAIN, as, depending on what caused it to fail, it may not be something that would be recovered.

Fixes cbba45d43631 ("[media] smiapp: Use runtime PM")
---
 drivers/media/i2c/ccs/ccs-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs/ccs-core.c +1 -1
index 9dc3f45da3dc..b05f409014b2 100644
@@ -3093,7 +3093,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)
 	if (rval < 0) {
 		pm_runtime_put_noidle(dev);
 
-		return -EAGAIN;
+		return rval;
 	}
 
 	if (sensor->streaming)
Signature · 1 line
2.30.2
Reviewed-by on v1 5/25
#13 lore raw

Re: [PATCH 05/25] media: i2c: ccs-core: return the right error code at suspend

Quoted 7 lines · On Wed, 5 May 2021 11:41:55 +0200 Mauro Carvalho Chehab…

If pm_runtime resume logic fails, return the error code provided by it, instead of -EAGAIN, as, depending on what caused it to fail, it may not be something that would be recovered.

Fixes cbba45d43631 ("[media] smiapp: Use runtime PM")
Quoted 17 lines
---
 drivers/media/i2c/ccs/ccs-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/ccs/ccs-core.c +1 -1
index 9dc3f45da3dc..b05f409014b2 100644
@@ -3093,7 +3093,7 @@ static int __maybe_unused ccs_suspend(struct device *dev)
 	if (rval < 0) {
 		pm_runtime_put_noidle(dev);
 
-		return -EAGAIN;
+		return rval;
 	}
 
 	if (sensor->streaming)
maintainer Acked-by on v1 5/25
#14 lore raw

Re: [PATCH 05/25] media: i2c: ccs-core: return the right error code at suspend

In reply to Mauro Carvalho Chehab
Quoted 7 lines · Mauro Carvalho Chehab

If pm_runtime resume logic fails, return the error code provided by it, instead of -EAGAIN, as, depending on what caused it to fail, it may not be something that would be recovered.

Fixes cbba45d43631 ("[media] smiapp: Use runtime PM")
Signature · 1 line
Sakari Ailus
#15 lore raw

PATCH 6/25 media: i2c: imx334: fix the pm runtime get logic

In reply to Mauro Carvalho Chehab

The PM runtime get logic is currently broken, as it checks if ret is zero instead of checking if it is an error code, as reported by Dan Carpenter.

While here, use the pm_runtime_resume_and_get() as added by:
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. As a bonus, such function
always return zero on success.

It should also be noticed that a fail of pm_runtime_get_sync() would potentially result in a spurious runtime_suspend(), instead of using pm_runtime_put_noidle().

---
 drivers/media/i2c/imx334.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/imx334.c +4 -3
index 047aa7658d21..23f28606e570 100644
@@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx334->dev);
-		if (ret)
-			goto error_power_off;
+		ret = pm_runtime_resume_and_get(imx334->dev);
+		if (ret < 0)
+			goto error_unlock;
 
 		ret = imx334_start_streaming(imx334);
 		if (ret)
@@ -737,6 +737,7 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 
 error_power_off:
 	pm_runtime_put(imx334->dev);
+error_unlock:
 	mutex_unlock(&imx334->mutex);
 
 	return ret;
Signature · 1 line
2.30.2
#16 lore raw

Re: [PATCH 06/25] media: i2c: imx334: fix the pm runtime get logic

Quoted 10 lines · On Wed, 5 May 2021 11:41:56 +0200 Mauro Carvalho Chehab…

The PM runtime get logic is currently broken, as it checks if ret is zero instead of checking if it is an error code, as reported by Dan Carpenter.

While here, use the pm_runtime_resume_and_get() as added by:
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. As a bonus, such function
always return zero on success.

Quoted 3 lines

It should also be noticed that a fail of pm_runtime_get_sync() would potentially result in a spurious runtime_suspend(), instead of using pm_runtime_put_noidle().

Irony here is that pm_runtime_resume_and_get() returns <= 0 so with that function change, you can stick with if (ret) and still be correct.

So only one of the two changes is needed to fix the bug.

J

Quoted 33 lines
---
 drivers/media/i2c/imx334.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/imx334.c +4 -3
index 047aa7658d21..23f28606e570 100644
@@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx334->dev);
-		if (ret)
-			goto error_power_off;
+		ret = pm_runtime_resume_and_get(imx334->dev);
+		if (ret < 0)
+			goto error_unlock;
 
 		ret = imx334_start_streaming(imx334);
 		if (ret)
@@ -737,6 +737,7 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 
 error_power_off:
 	pm_runtime_put(imx334->dev);
+error_unlock:
 	mutex_unlock(&imx334->mutex);
 
 	return ret;
#17 lore raw

Re: [PATCH 06/25] media: i2c: imx334: fix the pm runtime get logic

Em Wed, 5 May 2021 12:10:40 +0100
Jonathan Cameron <[email protected]> escreveu:

Quoted 13 lines
Quoted 10 lines · On Wed, 5 May 2021 11:41:56 +0200 Mauro Carvalho Chehab…

The PM runtime get logic is currently broken, as it checks if ret is zero instead of checking if it is an error code, as reported by Dan Carpenter.

While here, use the pm_runtime_resume_and_get() as added by:
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. As a bonus, such function
always return zero on success.

Quoted 8 lines
Quoted 3 lines

It should also be noticed that a fail of pm_runtime_get_sync() would potentially result in a spurious runtime_suspend(), instead of using pm_runtime_put_noidle().

Irony here is that pm_runtime_resume_and_get() returns <= 0 so with that function change, you can stick with if (ret) and still be correct.

So only one of the two changes is needed to fix the bug.

Yeah, I noticed ;-)

On media, almost all devices have I2C bus(es), and I2C send/receive functions return positive values. So, a good practice is to check for errors with:

	if (ret < 0)

That's why I opted to keep both changes here ;-)

Regards,
Mauro

Quoted 29 lines

J

Quoted 27 lines
---
 drivers/media/i2c/imx334.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/imx334.c +3 -3
index 047aa7658d21..23f28606e570 100644
@@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx334->dev);
-		if (ret)
-			goto error_power_off;
+		ret = pm_runtime_resume_and_get(imx334->dev);
+		if (ret < 0)
+			goto error_unlock;
 
 		ret = imx334_start_streaming(imx334);
 		if (ret)
@@ -737,6 +737,7 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 
Quoted 7 lines

drivers/media/i2c/imx334.c static int imx334_set_stream(struct v4l2_subdev *sd, int enable) · line 743

Quoted 6 lines
drivers/media/i2c/imx334.c +1 -0
 error_power_off:
 	pm_runtime_put(imx334->dev);
+error_unlock:
 	mutex_unlock(&imx334->mutex);
 
 	return ret;  

Thanks,
Mauro

Reviewed-by
#18 lore raw

Re: [PATCH 06/25] media: i2c: imx334: fix the pm runtime get logic

Quoted 25 lines · On Wed, 5 May 2021 13:24:26 +0200 Mauro Carvalho Chehab…

Em Wed, 5 May 2021 12:10:40 +0100
Jonathan Cameron <[email protected]> escreveu:

Quoted 13 lines
Quoted 10 lines · On Wed, 5 May 2021 11:41:56 +0200 Mauro Carvalho Chehab…

The PM runtime get logic is currently broken, as it checks if ret is zero instead of checking if it is an error code, as reported by Dan Carpenter.

While here, use the pm_runtime_resume_and_get() as added by:
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. As a bonus, such function
always return zero on success.

Quoted 8 lines
Quoted 3 lines

It should also be noticed that a fail of pm_runtime_get_sync() would potentially result in a spurious runtime_suspend(), instead of using pm_runtime_put_noidle().

Irony here is that pm_runtime_resume_and_get() returns <= 0 so with that function change, you can stick with if (ret) and still be correct.

So only one of the two changes is needed to fix the bug.

Quoted 8 lines

Yeah, I noticed ;-)

On media, almost all devices have I2C bus(es), and I2C send/receive functions return positive values. So, a good practice is to check for errors with:

	if (ret < 0)

That's why I opted to keep both changes here ;-)

Fair enough.

Quoted 45 lines

Regards,
Mauro

Quoted 29 lines

J

Quoted 27 lines
---
 drivers/media/i2c/imx334.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/i2c/imx334.c +3 -3
index 047aa7658d21..23f28606e570 100644
@@ -717,9 +717,9 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 	}
 
 	if (enable) {
-		ret = pm_runtime_get_sync(imx334->dev);
-		if (ret)
-			goto error_power_off;
+		ret = pm_runtime_resume_and_get(imx334->dev);
+		if (ret < 0)
+			goto error_unlock;
 
 		ret = imx334_start_streaming(imx334);
 		if (ret)
@@ -737,6 +737,7 @@ static int imx334_set_stream(struct v4l2_subdev *sd, int enable)
 
Quoted 7 lines

drivers/media/i2c/imx334.c static int imx334_set_stream(struct v4l2_subdev *sd, int enable) · line 743

Quoted 6 lines
drivers/media/i2c/imx334.c +1 -0
 error_power_off:
 	pm_runtime_put(imx334->dev);
+error_unlock:
 	mutex_unlock(&imx334->mutex);
 
 	return ret;    

Thanks,
Mauro

#19 lore raw

PATCH 7/25 media: exynos-gsc: don't resume at remove time

In reply to Mauro Carvalho Chehab

Calling pm_runtime_get_sync() at driver's removal time is not needed, as this will resume PM runtime. Also, the PM runtime code at pm_runtime_disable() already calls it, if it detects the need.

So, change the logic in order to disable PM runtime earlier.

---
 drivers/media/platform/exynos-gsc/gsc-core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/media/platform/exynos-gsc/gsc-core.c +6 -5
index 9f41c2e7097a..f49f3322f835 100644
@@ -1210,18 +1210,19 @@ static int gsc_remove(struct platform_device *pdev)
 	struct gsc_dev *gsc = platform_get_drvdata(pdev);
 	int i;
 
-	pm_runtime_get_sync(&pdev->dev);
-
 	gsc_unregister_m2m_device(gsc);
 	v4l2_device_unregister(&gsc->v4l2_dev);
 
 	vb2_dma_contig_clear_max_seg_size(&pdev->dev);
-	for (i = 0; i < gsc->num_clocks; i++)
-		clk_disable_unprepare(gsc->clock[i]);
 
-	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		for (i = 0; i < gsc->num_clocks; i++)
+			clk_disable_unprepare(gsc->clock[i]);
+
+	pm_runtime_set_suspended(&pdev->dev);
+
 	dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
 	return 0;
 }
Signature · 1 line
2.30.2
Reviewed-by on v1 7/25
#20 lore raw

Re: [PATCH 07/25] media: exynos-gsc: don't resume at remove time

Quoted 9 lines · On Wed, 5 May 2021 11:41:57 +0200 Mauro Carvalho Chehab…

Calling pm_runtime_get_sync() at driver's removal time is not needed, as this will resume PM runtime. Also, the PM runtime code at pm_runtime_disable() already calls it, if it detects the need.

So, change the logic in order to disable PM runtime earlier.

Seems sensible and a lot more along the lines of what I'd expect to see than was originally here.

Quoted 33 lines
---
 drivers/media/platform/exynos-gsc/gsc-core.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/media/platform/exynos-gsc/gsc-core.c +6 -5
index 9f41c2e7097a..f49f3322f835 100644
@@ -1210,18 +1210,19 @@ static int gsc_remove(struct platform_device *pdev)
 	struct gsc_dev *gsc = platform_get_drvdata(pdev);
 	int i;
 
-	pm_runtime_get_sync(&pdev->dev);
-
 	gsc_unregister_m2m_device(gsc);
 	v4l2_device_unregister(&gsc->v4l2_dev);
 
 	vb2_dma_contig_clear_max_seg_size(&pdev->dev);
-	for (i = 0; i < gsc->num_clocks; i++)
-		clk_disable_unprepare(gsc->clock[i]);
 
-	pm_runtime_put_noidle(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		for (i = 0; i < gsc->num_clocks; i++)
+			clk_disable_unprepare(gsc->clock[i]);
+
+	pm_runtime_set_suspended(&pdev->dev);
+
 	dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
 	return 0;
 }
#21 lore raw

PATCH 8/25 media: atmel: properly get pm_runtime

In reply to Mauro Carvalho Chehab

There are several issues in the way the atmel driver handles pm_runtime_get_sync():

- it doesn't check return codes;
- it doesn't properly decrement the usage_count on all places;
- it starts streaming even if pm_runtime_get_sync() fails.
- while it tries to get pm_runtime at the clock enable logic, it doesn't check if the operation was suceeded.

Replace all occurrences of it to use the new kAPI:
pm_runtime_resume_and_get(), which ensures that, if the return code is not negative, the usage_count was incremented.

With that, add additional checks when this is called, in order to ensure that errors will be properly addressed.

---
 drivers/media/platform/atmel/atmel-isc-base.c | 30 ++++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++---
 2 files changed, 38 insertions(+), 11 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +23 -7
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
 static int isc_clk_prepare(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return ret;
+	}
 
 	return isc_wait_clk_stable(hw);
 }
@@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
 	u32 status;
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return 0;
+	}
 
 	regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
 
@@ -807,7 +815,12 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 		goto err_start_stream;
 	}
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0) {
+		v4l2_err(&isc->v4l2_dev, "RPM resume failed in subdev %d\n",
+			 ret);
+		goto err_pm_get;
+	}
 
 	ret = isc_configure(isc);
 	if (unlikely(ret))
@@ -838,7 +851,7 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 err_configure:
 	pm_runtime_put_sync(isc->dev);
-
+err_pm_get:
 	v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
 
 err_start_stream:
@@ -1809,6 +1822,7 @@ static void isc_awb_work(struct work_struct *w)
 	u32 baysel;
 	unsigned long flags;
 	u32 min, max;
+	int ret;
 
 	/* streaming is not active anymore */
 	if (isc->stop)
@@ -1831,7 +1845,9 @@ static void isc_awb_work(struct work_struct *w)
 	ctrls->hist_id = hist_id;
 	baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0)
+		return;
 
 	/*
 	 * only update if we have all the required histograms and controls
drivers/media/platform/atmel/atmel-isi.c +15 -4
index e392b3efe363..5b1dd358f2e6 100644
@@ -422,7 +422,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 	struct frame_buffer *buf, *node;
 	int ret;
 
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	/* Enable stream on the sub device */
 	ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
@@ -782,9 +784,10 @@ static int isi_enum_frameintervals(struct file *file, void *fh,
 	return 0;
 }
 
-static void isi_camera_set_bus_param(struct atmel_isi *isi)
+static int isi_camera_set_bus_param(struct atmel_isi *isi)
 {
 	u32 cfg1 = 0;
+	int ret;
 
 	/* set bus param for ISI */
 	if (isi->pdata.hsync_act_low)
@@ -801,12 +804,16 @@ static void isi_camera_set_bus_param(struct atmel_isi *isi)
 	cfg1 |= ISI_CFG1_THMASK_BEATS_16;
 
 	/* Enable PM and peripheral clock before operate isi registers */
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
 	isi_writel(isi, ISI_CFG1, cfg1);
 
 	pm_runtime_put(isi->dev);
+
+	return 0;
 }
 
 /* -----------------------------------------------------------------------*/
@@ -1085,7 +1092,11 @@ static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
 		dev_err(isi->dev, "No supported mediabus format found\n");
 		return ret;
 	}
-	isi_camera_set_bus_param(isi);
+	ret = isi_camera_set_bus_param(isi);
+	if (ret) {
+		dev_err(isi->dev, "Can't wake up device\n");
+		return ret;
+	}
 
 	ret = isi_set_default_fmt(isi);
 	if (ret) {
Signature · 1 line
2.30.2
#22 lore raw

Re: [PATCH 08/25] media: atmel: properly get pm_runtime

Quoted 9 lines · On Wed, 5 May 2021 11:41:58 +0200 Mauro Carvalho Chehab…

There are several issues in the way the atmel driver handles pm_runtime_get_sync():

- it doesn't check return codes;
- it doesn't properly decrement the usage_count on all places;
- it starts streaming even if pm_runtime_get_sync() fails.
- while it tries to get pm_runtime at the clock enable logic, it doesn't check if the operation was suceeded.

Quoted 8 lines

Replace all occurrences of it to use the new kAPI:
pm_runtime_resume_and_get(), which ensures that, if the return code is not negative, the usage_count was incremented.

With that, add additional checks when this is called, in order to ensure that errors will be properly addressed.

Hi Mauro, I don't know media enough to know what is the right answer but in some of this series, a failure in pm_runtime_resume_and_get() leads to a bunch of buffer cleanup (patch 22 being an example) and in others return happens without doing that cleanup.

It might be both are safe, or I'm missing something else, but I'm certainly not confident enough to give any tags on this one as a result of that mismatch.

Quoted 88 lines
---
 drivers/media/platform/atmel/atmel-isc-base.c | 30 ++++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++---
 2 files changed, 38 insertions(+), 11 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +23 -7
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
 static int isc_clk_prepare(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return ret;
+	}
 
 	return isc_wait_clk_stable(hw);
 }
@@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
 {
 	struct isc_clk *isc_clk = to_isc_clk(hw);
 	u32 status;
+	int ret;
 
-	if (isc_clk->id == ISC_ISPCK)
-		pm_runtime_get_sync(isc_clk->dev);
+	if (isc_clk->id == ISC_ISPCK) {
+		ret = pm_runtime_resume_and_get(isc_clk->dev);
+		if (ret < 0)
+			return 0;
+	}
 
 	regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
 
@@ -807,7 +815,12 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 		goto err_start_stream;
 	}
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0) {
+		v4l2_err(&isc->v4l2_dev, "RPM resume failed in subdev %d\n",
+			 ret);
+		goto err_pm_get;
+	}
 
 	ret = isc_configure(isc);
 	if (unlikely(ret))
@@ -838,7 +851,7 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 err_configure:
 	pm_runtime_put_sync(isc->dev);
-
+err_pm_get:
 	v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
 
 err_start_stream:
@@ -1809,6 +1822,7 @@ static void isc_awb_work(struct work_struct *w)
 	u32 baysel;
 	unsigned long flags;
 	u32 min, max;
+	int ret;
 
 	/* streaming is not active anymore */
 	if (isc->stop)
@@ -1831,7 +1845,9 @@ static void isc_awb_work(struct work_struct *w)
 	ctrls->hist_id = hist_id;
 	baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
 
-	pm_runtime_get_sync(isc->dev);
+	ret = pm_runtime_resume_and_get(isc->dev);
+	if (ret < 0)
+		return;
 
 	/*
 	 * only update if we have all the required histograms and controls
drivers/media/platform/atmel/atmel-isi.c +0 -0
index e392b3efe363..5b1dd358f2e6 100644

drivers/media/platform/atmel/atmel-isi.c static int start_streaming(struct vb2_queue *vq, unsigned int count) · line 427

Quoted 7 lines
drivers/media/platform/atmel/atmel-isi.c +3 -1
@@ -422,7 +422,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
 	struct frame_buffer *buf, *node;
 	int ret;
 
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;

This is the case I'm referring to above.

Quoted 46 lines
drivers/media/platform/atmel/atmel-isi.c +12 -3
 	/* Enable stream on the sub device */
 	ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
@@ -782,9 +784,10 @@ static int isi_enum_frameintervals(struct file *file, void *fh,
 	return 0;
 }
 
-static void isi_camera_set_bus_param(struct atmel_isi *isi)
+static int isi_camera_set_bus_param(struct atmel_isi *isi)
 {
 	u32 cfg1 = 0;
+	int ret;
 
 	/* set bus param for ISI */
 	if (isi->pdata.hsync_act_low)
@@ -801,12 +804,16 @@ static void isi_camera_set_bus_param(struct atmel_isi *isi)
 	cfg1 |= ISI_CFG1_THMASK_BEATS_16;
 
 	/* Enable PM and peripheral clock before operate isi registers */
-	pm_runtime_get_sync(isi->dev);
+	ret = pm_runtime_resume_and_get(isi->dev);
+	if (ret < 0)
+		return ret;
 
 	isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
 	isi_writel(isi, ISI_CFG1, cfg1);
 
 	pm_runtime_put(isi->dev);
+
+	return 0;
 }
 
 /* -----------------------------------------------------------------------*/
@@ -1085,7 +1092,11 @@ static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
 		dev_err(isi->dev, "No supported mediabus format found\n");
 		return ret;
 	}
-	isi_camera_set_bus_param(isi);
+	ret = isi_camera_set_bus_param(isi);
+	if (ret) {
+		dev_err(isi->dev, "Can't wake up device\n");
+		return ret;
+	}
 
 	ret = isi_set_default_fmt(isi);
 	if (ret) {
#23 lore raw

Re: [PATCH 08/25] media: atmel: properly get pm_runtime

Quoted 46 lines · Jonathan Cameron
Quoted 9 lines · On Wed, 5 May 2021 11:41:58 +0200 Mauro Carvalho Chehab…

There are several issues in the way the atmel driver handles pm_runtime_get_sync():

- it doesn't check return codes;
- it doesn't properly decrement the usage_count on all places;
- it starts streaming even if pm_runtime_get_sync() fails.
- while it tries to get pm_runtime at the clock enable logic, it doesn't check if the operation was suceeded.

Quoted 8 lines

Replace all occurrences of it to use the new kAPI:
pm_runtime_resume_and_get(), which ensures that, if the return code is not negative, the usage_count was incremented.

With that, add additional checks when this is called, in order to ensure that errors will be properly addressed.

Hi Mauro, I don't know media enough to know what is the right answer but in some of this series, a failure in pm_runtime_resume_and_get() leads to a bunch of buffer cleanup (patch 22 being an example) and in others return happens without doing that cleanup.

It might be both are safe, or I'm missing something else, but I'm certainly not confident enough to give any tags on this one as a result of that mismatch.

Quoted 15 lines
---
  drivers/media/platform/atmel/atmel-isc-base.c | 30 ++++++++++++++-----
  drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++---
  2 files changed, 38 insertions(+), 11 deletions(-)
drivers/media/platform/atmel/atmel-isc-base.c +1 -0
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
  static int isc_clk_prepare(struct clk_hw *hw)
  {
       struct isc_clk *isc_clk = to_isc_clk(hw);
+     int ret;
 
Quoted 7 lines

drivers/media/platform/atmel/atmel-isc-base.c static int isc_wait_clk_stable(struct clk_hw *hw) · line 303

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c +5 -2
-     if (isc_clk->id == ISC_ISPCK)
-             pm_runtime_get_sync(isc_clk->dev);
+     if (isc_clk->id == ISC_ISPCK) {
+             ret = pm_runtime_resume_and_get(isc_clk->dev);
+             if (ret < 0)
+                     return ret;
+     }

Hi Mauro,

With this patch, the ISC is broken on latest media tree. It looks like pm_runtime_resume_and_get for the ISC_ISPCK clock returns -ENOACCESS and thus, the probe of the driver fails:

atmel-sama5d2-isc f0008000.isc: failed to enable ispck: -13
atmel-sama5d2-isc: probe of f0008000.isc failed with error -13

Could you point out how I could fix this ? Maybe the isc_clk->dev is not properly handled/initialized in some other part of the code ?

Thanks !
Eugen

Quoted 122 lines
Quoted 66 lines
drivers/media/platform/atmel/atmel-isc-base.c +17 -5
       return isc_wait_clk_stable(hw);
  }
@@ -353,9 +357,13 @@ static int isc_clk_is_enabled(struct clk_hw *hw)
  {
       struct isc_clk *isc_clk = to_isc_clk(hw);
       u32 status;
+     int ret;
 
-     if (isc_clk->id == ISC_ISPCK)
-             pm_runtime_get_sync(isc_clk->dev);
+     if (isc_clk->id == ISC_ISPCK) {
+             ret = pm_runtime_resume_and_get(isc_clk->dev);
+             if (ret < 0)
+                     return 0;
+     }
 
       regmap_read(isc_clk->regmap, ISC_CLKSR, &status);
 
@@ -807,7 +815,12 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
               goto err_start_stream;
       }
 
-     pm_runtime_get_sync(isc->dev);
+     ret = pm_runtime_resume_and_get(isc->dev);
+     if (ret < 0) {
+             v4l2_err(&isc->v4l2_dev, "RPM resume failed in subdev %d\n",
+                      ret);
+             goto err_pm_get;
+     }
 
       ret = isc_configure(isc);
       if (unlikely(ret))
@@ -838,7 +851,7 @@ static int isc_start_streaming(struct vb2_queue *vq, unsigned int count)
 
  err_configure:
       pm_runtime_put_sync(isc->dev);
-
+err_pm_get:
       v4l2_subdev_call(isc->current_subdev->sd, video, s_stream, 0);
 
  err_start_stream:
@@ -1809,6 +1822,7 @@ static void isc_awb_work(struct work_struct *w)
       u32 baysel;
       unsigned long flags;
       u32 min, max;
+     int ret;
 
       /* streaming is not active anymore */
       if (isc->stop)
@@ -1831,7 +1845,9 @@ static void isc_awb_work(struct work_struct *w)
       ctrls->hist_id = hist_id;
       baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
 
-     pm_runtime_get_sync(isc->dev);
+     ret = pm_runtime_resume_and_get(isc->dev);
+     if (ret < 0)
+             return;
 
       /*
        * only update if we have all the required histograms and controls
drivers/media/platform/atmel/atmel-isi.c +0 -0
index e392b3efe363..5b1dd358f2e6 100644

drivers/media/platform/atmel/atmel-isi.c static int start_streaming(struct vb2_queue *vq, unsigned int count) · line 427

Quoted 7 lines
drivers/media/platform/atmel/atmel-isi.c +3 -1
@@ -422,7 +422,9 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
       struct frame_buffer *buf, *node;
       int ret;
 
-     pm_runtime_get_sync(isi->dev);
+     ret = pm_runtime_resume_and_get(isi->dev);
+     if (ret < 0)
+             return ret;

This is the case I'm referring to above.

Quoted 46 lines
drivers/media/platform/atmel/atmel-isi.c +12 -3
       /* Enable stream on the sub device */
       ret = v4l2_subdev_call(isi->entity.subdev, video, s_stream, 1);
@@ -782,9 +784,10 @@ static int isi_enum_frameintervals(struct file *file, void *fh,
       return 0;
  }
 
-static void isi_camera_set_bus_param(struct atmel_isi *isi)
+static int isi_camera_set_bus_param(struct atmel_isi *isi)
  {
       u32 cfg1 = 0;
+     int ret;
 
       /* set bus param for ISI */
       if (isi->pdata.hsync_act_low)
@@ -801,12 +804,16 @@ static void isi_camera_set_bus_param(struct atmel_isi *isi)
       cfg1 |= ISI_CFG1_THMASK_BEATS_16;
 
       /* Enable PM and peripheral clock before operate isi registers */
-     pm_runtime_get_sync(isi->dev);
+     ret = pm_runtime_resume_and_get(isi->dev);
+     if (ret < 0)
+             return ret;
 
       isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
       isi_writel(isi, ISI_CFG1, cfg1);
 
       pm_runtime_put(isi->dev);
+
+     return 0;
  }
 
  /* -----------------------------------------------------------------------*/
@@ -1085,7 +1092,11 @@ static int isi_graph_notify_complete(struct v4l2_async_notifier *notifier)
               dev_err(isi->dev, "No supported mediabus format found\n");
               return ret;
       }
-     isi_camera_set_bus_param(isi);
+     ret = isi_camera_set_bus_param(isi);
+     if (ret) {
+             dev_err(isi->dev, "Can't wake up device\n");
+             return ret;
+     }
 
       ret = isi_set_default_fmt(isi);
       if (ret) {
#24 lore raw

Re: [PATCH 08/25] media: atmel: properly get pm_runtime

Em Thu, 10 Jun 2021 09:04:07 +0000
<[email protected]> escreveu:

Quoted 24 lines
Quoted 10 lines
Quoted 10 lines
drivers/media/platform/atmel/atmel-isc-base.c +1 -0
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
  static int isc_clk_prepare(struct clk_hw *hw)
  {
       struct isc_clk *isc_clk = to_isc_clk(hw);
+     int ret;
 
Quoted 7 lines

drivers/media/platform/atmel/atmel-isc-base.c static int isc_wait_clk_stable(struct clk_hw *hw) · line 303

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c +5 -2
-     if (isc_clk->id == ISC_ISPCK)
-             pm_runtime_get_sync(isc_clk->dev);
+     if (isc_clk->id == ISC_ISPCK) {
+             ret = pm_runtime_resume_and_get(isc_clk->dev);
+             if (ret < 0)
+                     return ret;
+     }  

Hi Mauro,

With this patch, the ISC is broken on latest media tree. It looks like pm_runtime_resume_and_get for the ISC_ISPCK clock returns -ENOACCESS and thus, the probe of the driver fails:

Quoted 6 lines

atmel-sama5d2-isc f0008000.isc: failed to enable ispck: -13
atmel-sama5d2-isc: probe of f0008000.isc failed with error -13

Could you point out how I could fix this ? Maybe the isc_clk->dev is not properly handled/initialized in some other part of the code ?

Looking at RPM implementation:

	static int rpm_resume(struct device *dev, int rpmflags)
	{
...
        if (dev->power.runtime_error)
                retval = -EINVAL;
        else if (dev->power.disable_depth == 1 && dev->power.is_suspended
            && dev->power.runtime_status == RPM_ACTIVE)
                retval = 1;
        else if (dev->power.disable_depth > 0)
                retval = -EACCES;

...

It sounds that RPM is disabled for this clock. Did you call pm_runtime_enable() before calling isc_clk_prepare()?

Thanks,
Mauro

#25 lore raw

Re: [PATCH 08/25] media: atmel: properly get pm_runtime

Quoted 48 lines · Mauro Carvalho Chehab

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Em Thu, 10 Jun 2021 09:04:07 +0000
<[email protected]> escreveu:

Quoted 24 lines
Quoted 10 lines
Quoted 10 lines
drivers/media/platform/atmel/atmel-isc-base.c +1 -0
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
   static int isc_clk_prepare(struct clk_hw *hw)
   {
        struct isc_clk *isc_clk = to_isc_clk(hw);
+     int ret;
 
Quoted 7 lines

drivers/media/platform/atmel/atmel-isc-base.c static int isc_wait_clk_stable(struct clk_hw *hw) · line 303

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c +5 -2
-     if (isc_clk->id == ISC_ISPCK)
-             pm_runtime_get_sync(isc_clk->dev);
+     if (isc_clk->id == ISC_ISPCK) {
+             ret = pm_runtime_resume_and_get(isc_clk->dev);
+             if (ret < 0)
+                     return ret;
+     }

Hi Mauro,

With this patch, the ISC is broken on latest media tree. It looks like pm_runtime_resume_and_get for the ISC_ISPCK clock returns -ENOACCESS and thus, the probe of the driver fails:

Quoted 6 lines

atmel-sama5d2-isc f0008000.isc: failed to enable ispck: -13
atmel-sama5d2-isc: probe of f0008000.isc failed with error -13

Could you point out how I could fix this ? Maybe the isc_clk->dev is not properly handled/initialized in some other part of the code ?

Looking at RPM implementation:

static int rpm_resume(struct device *dev, int rpmflags) {
...

         if (dev->power.runtime_error)
                 retval = -EINVAL;
         else if (dev->power.disable_depth == 1 && dev->power.is_suspended
             && dev->power.runtime_status == RPM_ACTIVE)
                 retval = 1;
         else if (dev->power.disable_depth > 0)
                 retval = -EACCES;
Quoted 8 lines

...

It sounds that RPM is disabled for this clock. Did you call pm_runtime_enable() before calling isc_clk_prepare()?

Thanks,
Mauro

I tried to call pm_runtime_enable for the clk at clk_init time, but doing that makes the runtime for the ISC fail like this:

atmel-sama5d2-isc f0008000.isc: Unbalanced pm_runtime_enable!

#26 lore raw

Re: [PATCH 08/25] media: atmel: properly get pm_runtime

Em Thu, 10 Jun 2021 12:00:42 +0000
<[email protected]> escreveu:

Quoted 54 lines · Mauro Carvalho Chehab
Quoted 53 lines

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Em Thu, 10 Jun 2021 09:04:07 +0000
<[email protected]> escreveu:

Quoted 24 lines
Quoted 10 lines
Quoted 10 lines
drivers/media/platform/atmel/atmel-isc-base.c +1 -0
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
   static int isc_clk_prepare(struct clk_hw *hw)
   {
        struct isc_clk *isc_clk = to_isc_clk(hw);
+     int ret;
 
Quoted 7 lines

drivers/media/platform/atmel/atmel-isc-base.c static int isc_wait_clk_stable(struct clk_hw *hw) · line 303

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c +5 -2
-     if (isc_clk->id == ISC_ISPCK)
-             pm_runtime_get_sync(isc_clk->dev);
+     if (isc_clk->id == ISC_ISPCK) {
+             ret = pm_runtime_resume_and_get(isc_clk->dev);
+             if (ret < 0)
+                     return ret;
+     }  

Hi Mauro,

With this patch, the ISC is broken on latest media tree. It looks like pm_runtime_resume_and_get for the ISC_ISPCK clock returns -ENOACCESS and thus, the probe of the driver fails:

Quoted 6 lines

atmel-sama5d2-isc f0008000.isc: failed to enable ispck: -13
atmel-sama5d2-isc: probe of f0008000.isc failed with error -13

Could you point out how I could fix this ? Maybe the isc_clk->dev is not properly handled/initialized in some other part of the code ?

Looking at RPM implementation:

static int rpm_resume(struct device *dev, int rpmflags) {
...

         if (dev->power.runtime_error)
                 retval = -EINVAL;
         else if (dev->power.disable_depth == 1 && dev->power.is_suspended
             && dev->power.runtime_status == RPM_ACTIVE)
                 retval = 1;
         else if (dev->power.disable_depth > 0)
                 retval = -EACCES;

...

It sounds that RPM is disabled for this clock. Did you call pm_runtime_enable() before calling isc_clk_prepare()?

Quoted 8 lines
Quoted 3 lines

Thanks,
Mauro

I tried to call pm_runtime_enable for the clk at clk_init time, but doing that makes the runtime for the ISC fail like this:

atmel-sama5d2-isc f0008000.isc: Unbalanced pm_runtime_enable!

Making RPM balanced is complex ;-)

Yet, clearly there's something weird at the PM code. I mean, ignoring a -ENOACCESS error like the original code sounds wrong, as it basically means that pm_runtime_get_sync() were doing nothing (except by incrementing a refcount).

Some drivers call clk_prepare()/clk_unprepare() at their .prepare/.unprepare ops. Those functions internally call RPM get logic recursively, to ensure that the RPM state of the parents are also at the right state.

Thanks,
Mauro

#27 lore raw

Re: [PATCH 08/25] media: atmel: properly get pm_runtime

In reply to [email protected]

Hi Eugen,

Em Thu, 10 Jun 2021 12:00:42 +0000
<[email protected]> escreveu:

Quoted 26 lines · Mauro Carvalho Chehab
Quoted 25 lines

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Em Thu, 10 Jun 2021 09:04:07 +0000
<[email protected]> escreveu:

Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/media/platform/atmel/atmel-isc-base.c +1 -0
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
   static int isc_clk_prepare(struct clk_hw *hw)
   {
        struct isc_clk *isc_clk = to_isc_clk(hw);
+     int ret;
 
Quoted 7 lines

drivers/media/platform/atmel/atmel-isc-base.c static int isc_wait_clk_stable(struct clk_hw *hw) · line 303

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c +5 -2
-     if (isc_clk->id == ISC_ISPCK)
-             pm_runtime_get_sync(isc_clk->dev);
+     if (isc_clk->id == ISC_ISPCK) {
+             ret = pm_runtime_resume_and_get(isc_clk->dev);
+             if (ret < 0)
+                     return ret;
+     }  

Hi Mauro,

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

With this patch, the ISC is broken on latest media tree. It looks like pm_runtime_resume_and_get for the ISC_ISPCK clock returns -ENOACCESS and thus, the probe of the driver fails:

atmel-sama5d2-isc f0008000.isc: failed to enable ispck: -13
atmel-sama5d2-isc: probe of f0008000.isc failed with error -13

What's the current status of this issue?

If the bug still happens, we need a fix for it.

We might revert this patch, but this would just be masking some other hidden bug.

Regards,
Mauro

Quoted 22 lines
Quoted 22 lines
Quoted 4 lines

Could you point out how I could fix this ? Maybe the isc_clk->dev is not properly handled/initialized in some other part of the code ?

Looking at RPM implementation:

static int rpm_resume(struct device *dev, int rpmflags) {
...

         if (dev->power.runtime_error)
                 retval = -EINVAL;
         else if (dev->power.disable_depth == 1 && dev->power.is_suspended
             && dev->power.runtime_status == RPM_ACTIVE)
                 retval = 1;
         else if (dev->power.disable_depth > 0)
                 retval = -EACCES;

...

It sounds that RPM is disabled for this clock. Did you call pm_runtime_enable() before calling isc_clk_prepare()?

Quoted 8 lines
Quoted 3 lines

Thanks,
Mauro

I tried to call pm_runtime_enable for the clk at clk_init time, but doing that makes the runtime for the ISC fail like this:

atmel-sama5d2-isc f0008000.isc: Unbalanced pm_runtime_enable!

Thanks,
Mauro

#28 lore raw

Re: [PATCH 08/25] media: atmel: properly get pm_runtime

Quoted 31 lines · Mauro Carvalho Chehab

Hi Eugen,

Em Thu, 10 Jun 2021 12:00:42 +0000
<[email protected]> escreveu:

Quoted 26 lines · Mauro Carvalho Chehab
Quoted 25 lines

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Em Thu, 10 Jun 2021 09:04:07 +0000
<[email protected]> escreveu:

Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/media/platform/atmel/atmel-isc-base.c +1 -0
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
    static int isc_clk_prepare(struct clk_hw *hw)
    {
         struct isc_clk *isc_clk = to_isc_clk(hw);
+     int ret;
 
Quoted 7 lines

drivers/media/platform/atmel/atmel-isc-base.c static int isc_wait_clk_stable(struct clk_hw *hw) · line 303

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c +5 -2
-     if (isc_clk->id == ISC_ISPCK)
-             pm_runtime_get_sync(isc_clk->dev);
+     if (isc_clk->id == ISC_ISPCK) {
+             ret = pm_runtime_resume_and_get(isc_clk->dev);
+             if (ret < 0)
+                     return ret;
+     }

Hi Mauro,

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

With this patch, the ISC is broken on latest media tree. It looks like pm_runtime_resume_and_get for the ISC_ISPCK clock returns -ENOACCESS and thus, the probe of the driver fails:

atmel-sama5d2-isc f0008000.isc: failed to enable ispck: -13
atmel-sama5d2-isc: probe of f0008000.isc failed with error -13

What's the current status of this issue?

Hi Mauro,

Currently, as far as I know, the ISC is broken in 5.14 and current Linux master. I plan to investigate this issue this week (or the next...), together with some other things. I want to tryout the PM part of the driver to see where is the problem.
When I come up with a fix or patch, I will send it on the mailing list. If you have any ideas that I can try meanwhile, feel free to contact me to send a patch that I can test.

Eugen

Quoted 47 lines

If the bug still happens, we need a fix for it.

We might revert this patch, but this would just be masking some other hidden bug.

Regards,
Mauro

Quoted 22 lines
Quoted 22 lines
Quoted 4 lines

Could you point out how I could fix this ? Maybe the isc_clk->dev is not properly handled/initialized in some other part of the code ?

Looking at RPM implementation:

static int rpm_resume(struct device *dev, int rpmflags) {
...

          if (dev->power.runtime_error)
                  retval = -EINVAL;
          else if (dev->power.disable_depth == 1 && dev->power.is_suspended
              && dev->power.runtime_status == RPM_ACTIVE)
                  retval = 1;
          else if (dev->power.disable_depth > 0)
                  retval = -EACCES;

...

It sounds that RPM is disabled for this clock. Did you call pm_runtime_enable() before calling isc_clk_prepare()?

Quoted 8 lines
Quoted 3 lines

Thanks,
Mauro

I tried to call pm_runtime_enable for the clk at clk_init time, but doing that makes the runtime for the ISC fail like this:

atmel-sama5d2-isc f0008000.isc: Unbalanced pm_runtime_enable!

Thanks,
Mauro

#29 lore raw

Re: [PATCH 08/25] media: atmel: properly get pm_runtime

Quoted 43 lines · On 9/6/21 11:13 AM, Eugen Hristev - M18282 wrote:
Quoted 31 lines · Mauro Carvalho Chehab

Hi Eugen,

Em Thu, 10 Jun 2021 12:00:42 +0000
<[email protected]> escreveu:

Quoted 26 lines · Mauro Carvalho Chehab
Quoted 25 lines

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Em Thu, 10 Jun 2021 09:04:07 +0000
<[email protected]> escreveu:

Quoted 20 lines
Quoted 10 lines
Quoted 10 lines
drivers/media/platform/atmel/atmel-isc-base.c +1 -0
index fe3ec8d0eaee..ce8e1351fa53 100644
@@ -294,9 +294,13 @@ static int isc_wait_clk_stable(struct clk_hw *hw)
     static int isc_clk_prepare(struct clk_hw *hw)
     {
          struct isc_clk *isc_clk = to_isc_clk(hw);
+     int ret;
 
Quoted 7 lines

drivers/media/platform/atmel/atmel-isc-base.c static int isc_wait_clk_stable(struct clk_hw *hw) · line 303

Quoted 7 lines
drivers/media/platform/atmel/atmel-isc-base.c +5 -2
-     if (isc_clk->id == ISC_ISPCK)
-             pm_runtime_get_sync(isc_clk->dev);
+     if (isc_clk->id == ISC_ISPCK) {
+             ret = pm_runtime_resume_and_get(isc_clk->dev);
+             if (ret < 0)
+                     return ret;
+     }

Hi Mauro,

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

With this patch, the ISC is broken on latest media tree. It looks like pm_runtime_resume_and_get for the ISC_ISPCK clock returns -ENOACCESS and thus, the probe of the driver fails:

atmel-sama5d2-isc f0008000.isc: failed to enable ispck: -13
atmel-sama5d2-isc: probe of f0008000.isc failed with error -13

What's the current status of this issue?

Hi Mauro,

Quoted 9 lines

Currently, as far as I know, the ISC is broken in 5.14 and current Linux master. I plan to investigate this issue this week (or the next...), together with some other things. I want to tryout the PM part of the driver to see where is the problem.
When I come up with a fix or patch, I will send it on the mailing list. If you have any ideas that I can try meanwhile, feel free to contact me to send a patch that I can test.

Hi Mauro,

Regarding this issue, I sent a patch on the ML that should solve it.

https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/

Eugen

Quoted 51 lines

Eugen

Quoted 47 lines

If the bug still happens, we need a fix for it.

We might revert this patch, but this would just be masking some other hidden bug.

Regards,
Mauro

Quoted 22 lines
Quoted 22 lines
Quoted 4 lines

Could you point out how I could fix this ? Maybe the isc_clk->dev is not properly handled/initialized in some other part of the code ?

Looking at RPM implementation:

static int rpm_resume(struct device *dev, int rpmflags) {
...

           if (dev->power.runtime_error)
                   retval = -EINVAL;
           else if (dev->power.disable_depth == 1 && dev->power.is_suspended
               && dev->power.runtime_status == RPM_ACTIVE)
                   retval = 1;
           else if (dev->power.disable_depth > 0)
                   retval = -EACCES;

...

It sounds that RPM is disabled for this clock. Did you call pm_runtime_enable() before calling isc_clk_prepare()?

Quoted 8 lines
Quoted 3 lines

Thanks,
Mauro

I tried to call pm_runtime_enable for the clk at clk_init time, but doing that makes the runtime for the ISC fail like this:

atmel-sama5d2-isc f0008000.isc: Unbalanced pm_runtime_enable!

Thanks,
Mauro

#30 lore raw

PATCH 9/25 media: hantro: do a PM resume earlier

In reply to Mauro Carvalho Chehab

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume, it would be better to detect it beforehand.

So, change the order inside device_run().

Fixes 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
---
 drivers/staging/media/hantro/hantro_drv.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/media/hantro/hantro_drv.c +4 -3
index 595e82a82728..4387edaa1d0d 100644
@@ -152,13 +152,14 @@ static void device_run(void *priv)
 	src = hantro_get_src_buf(ctx);
 	dst = hantro_get_dst_buf(ctx);
 
-	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
-	if (ret)
-		goto err_cancel_job;
 	ret = pm_runtime_get_sync(ctx->dev->dev);
 	if (ret < 0)
 		goto err_cancel_job;
 
+	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
+	if (ret)
+		goto err_cancel_job;
+
 	v4l2_m2m_buf_copy_metadata(src, dst, true);
 
 	ctx->codec_ops->run(ctx);
Signature · 1 line
2.30.2
#31 lore raw

Re: [PATCH 09/25] media: hantro: do a PM resume earlier

Quoted 11 lines · On Wed, 5 May 2021 11:41:59 +0200 Mauro Carvalho Chehab…

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume, it would be better to detect it beforehand.

So, change the order inside device_run().

Fixes 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")

Does this move not result in a potential call of clk_bulk_disable() for clocks that aren't enabled?

Quoted 26 lines
---
 drivers/staging/media/hantro/hantro_drv.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/media/hantro/hantro_drv.c +4 -3
index 595e82a82728..4387edaa1d0d 100644
@@ -152,13 +152,14 @@ static void device_run(void *priv)
 	src = hantro_get_src_buf(ctx);
 	dst = hantro_get_dst_buf(ctx);
 
-	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
-	if (ret)
-		goto err_cancel_job;
 	ret = pm_runtime_get_sync(ctx->dev->dev);
 	if (ret < 0)
 		goto err_cancel_job;
 
+	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
+	if (ret)
+		goto err_cancel_job;
+
 	v4l2_m2m_buf_copy_metadata(src, dst, true);
 
 	ctx->codec_ops->run(ctx);
#32 lore raw

Re: [PATCH 09/25] media: hantro: do a PM resume earlier

In reply to Mauro Carvalho Chehab

Hi Mauro,

Thanks for working on this.

Quoted 11 lines · Mauro Carvalho Chehab

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume, it would be better to detect it beforehand.

So, change the order inside device_run().

Fixes 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")

It seems this is wrong now, as this series doesn't have

https://lore.kernel.org/linux-media/803c39fafdd62efc6f9e4d99a372af2c6955143b.1619621413.git.mchehab+huawei@kernel.org/

I don't fully understand why all the back and forth happening on this series, but the former Hantro patches looked good (despite perhaps unclear commit messages).

Any issues just squashing these two commits from "[PATCH v4 00/79] Address some issues with PM runtime at media subsystem":

media: hantro: use pm_runtime_resume_and_get()
media: hantro: do a PM resume earlier

?

Thanks,
Ezequiel

Quoted 25 lines

 drivers/staging/media/hantro/hantro_drv.c | 7 ++++---

 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/staging/media/hantro/hantro_drv.c +0 -0
index 595e82a82728..4387edaa1d0d 100644
@@ -152,13 +152,14 @@ static void device_run(void *priv)
         src = hantro_get_src_buf(ctx);
         dst = hantro_get_dst_buf(ctx);


-       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks); -       if (ret)
-               goto err_cancel_job;
        ret = pm_runtime_get_sync(ctx->dev->dev);
        if (ret < 0)
                goto err_cancel_job;

+       ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks); +       if (ret)
+               goto err_cancel_job;
+
        v4l2_m2m_buf_copy_metadata(src, dst, true);

        ctx->codec_ops->run(ctx);

#33 lore raw

Re: [PATCH 09/25] media: hantro: do a PM resume earlier

Em Wed, 05 May 2021 10:22:03 -0300 Ezequiel Garcia <[email protected]> escreveu:

Quoted 17 lines

Hi Mauro,

Thanks for working on this.

Quoted 11 lines · Mauro Carvalho Chehab

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume, it would be better to detect it beforehand.

So, change the order inside device_run().

Fixes 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
Quoted 7 lines

It seems this is wrong now, as this series doesn't have

https://lore.kernel.org/linux-media/803c39fafdd62efc6f9e4d99a372af2c6955143b.1619621413.git.mchehab+huawei@kernel.org/

I don't fully understand why all the back and forth happening on this series, but the former Hantro patches looked good (despite perhaps unclear commit messages).

There was a request to break the original /79 series into smaller ones, to make easier for reviewers. So, I opted to split it into (probably) 3 series:

1. Fixes (this series);
2. "use pm_runtime_resume_and_get" for the I2C drivers;
3. "use pm_runtime_resume_and_get" for remaining ones.

Before flooding everybody's email's with series (2) and (3), better to focus at the fixes first. I'll probably send the other two series by tomorrow.

Quoted 4 lines

Any issues just squashing these two commits from "[PATCH v4 00/79] Address some issues with PM runtime at media subsystem":

media: hantro: use pm_runtime_resume_and_get()
media: hantro: do a PM resume earlier

The problem is that pm_runtime_resume_and_get() was added only recently (Kernel v5.10).

So, I opted to place the fix patches before the changes, as this way, most (all?) patches can be easily be backported to legacy Kernels as needed.

Thanks,
Mauro

#34 lore raw

Re: [PATCH 09/25] media: hantro: do a PM resume earlier

Quoted 45 lines · Mauro Carvalho Chehab

Em Wed, 05 May 2021 10:22:03 -0300 Ezequiel Garcia <[email protected]> escreveu:

Quoted 17 lines

Hi Mauro,

Thanks for working on this.

Quoted 11 lines · Mauro Carvalho Chehab

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume, it would be better to detect it beforehand.

So, change the order inside device_run().

Fixes 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
Quoted 7 lines

It seems this is wrong now, as this series doesn't have

https://lore.kernel.org/linux-media/803c39fafdd62efc6f9e4d99a372af2c6955143b.1619621413.git.mchehab+huawei@kernel.org/

I don't fully understand why all the back and forth happening on this series, but the former Hantro patches looked good (despite perhaps unclear commit messages).

There was a request to break the original /79 series into smaller ones, to make easier for reviewers. So, I opted to split it into (probably) 3 series:

1. Fixes (this series);
2. "use pm_runtime_resume_and_get" for the I2C drivers;
3. "use pm_runtime_resume_and_get" for remaining ones.

Before flooding everybody's email's with series (2) and (3), better to focus at the fixes first. I'll probably send the other two series by tomorrow.

Quoted 4 lines

Any issues just squashing these two commits from "[PATCH v4 00/79] Address some issues with PM runtime at media subsystem":

  media: hantro: use pm_runtime_resume_and_get()
  media: hantro: do a PM resume earlier

Quoted 7 lines

The problem is that pm_runtime_resume_and_get() was added only recently (Kernel v5.10).

So, I opted to place the fix patches before the changes, as this way, most (all?) patches can be easily be backported to legacy Kernels as needed.

Got it.

Maybe the better fix would be the squash of [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get() and [PATCH v4 79/79] media: hantro: do a PM resume earlier but keeping pm_runtime_get_sync.

And then you can replace the pm_runtime_get_sync with pm_runtime_resume_and_get.

Thanks,
Ezequiel

author Reviewed-by Ezequiel Garcia
#35 lore raw

Re: [PATCH 09/25] media: hantro: do a PM resume earlier

Em Wed, 05 May 2021 11:01:35 -0300 Ezequiel Garcia <[email protected]> escreveu:

Quoted 54 lines · Mauro Carvalho Chehab
Quoted 45 lines

Em Wed, 05 May 2021 10:22:03 -0300 Ezequiel Garcia <[email protected]> escreveu:

Quoted 17 lines

Hi Mauro,

Thanks for working on this.

Quoted 11 lines · Mauro Carvalho Chehab

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume, it would be better to detect it beforehand.

So, change the order inside device_run().

Fixes 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
Quoted 7 lines

It seems this is wrong now, as this series doesn't have

https://lore.kernel.org/linux-media/803c39fafdd62efc6f9e4d99a372af2c6955143b.1619621413.git.mchehab+huawei@kernel.org/

I don't fully understand why all the back and forth happening on this series, but the former Hantro patches looked good (despite perhaps unclear commit messages).

There was a request to break the original /79 series into smaller ones, to make easier for reviewers. So, I opted to split it into (probably) 3 series:

1. Fixes (this series);
2. "use pm_runtime_resume_and_get" for the I2C drivers;
3. "use pm_runtime_resume_and_get" for remaining ones.

Before flooding everybody's email's with series (2) and (3), better to focus at the fixes first. I'll probably send the other two series by tomorrow.

Quoted 4 lines

Any issues just squashing these two commits from "[PATCH v4 00/79] Address some issues with PM runtime at media subsystem":

  media: hantro: use pm_runtime_resume_and_get()
  media: hantro: do a PM resume earlier

Quoted 7 lines

The problem is that pm_runtime_resume_and_get() was added only recently (Kernel v5.10).

So, I opted to place the fix patches before the changes, as this way, most (all?) patches can be easily be backported to legacy Kernels as needed.

Quoted 6 lines

Got it.

Maybe the better fix would be the squash of [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get() and [PATCH v4 79/79] media: hantro: do a PM resume earlier but keeping pm_runtime_get_sync.

And then you can replace the pm_runtime_get_sync with pm_runtime_resume_and_get.

Works for me. So, the fixes patch will be the enclosed one, right?

Btw, I agree with Jonathan that the best would be to also move this:

	clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);

out of hantro_job_finish_no_pm(), as, when an error happens at device_run(), the clock lines won't be enabled at the first place.

Quoted 2 lines

Thanks,
Ezequiel

Thanks,
Mauro

[PATCH] media: hantro: do a PM resume earlier

The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.

Well, if for some reason the pm_runtime can not resume, it would be better to detect it beforehand.

So, change the order inside device_run().

Fixes 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
drivers/staging/media/hantro/hantro_drv.c +20 -9
index 595e82a82728..bdb57fb56f47 100644
@@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
 	return hantro_get_dec_buf_addr(ctx, buf);
 }
 
-static void hantro_job_finish(struct hantro_dev *vpu,
-			      struct hantro_ctx *ctx,
-			      enum vb2_buffer_state result)
+static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
+				    struct hantro_ctx *ctx,
+				    enum vb2_buffer_state result)
 {
 	struct vb2_v4l2_buffer *src, *dst;
 
-	pm_runtime_mark_last_busy(vpu->dev);
-	pm_runtime_put_autosuspend(vpu->dev);
 	clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
 
 	src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
@@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
 					 result);
 }
 
+static void hantro_job_finish(struct hantro_dev *vpu,
+			      struct hantro_ctx *ctx,
+			      enum vb2_buffer_state result)
+{
+	pm_runtime_mark_last_busy(vpu->dev);
+	pm_runtime_put_autosuspend(vpu->dev);
+
+	hantro_job_finish_no_pm(vpu, ctx, result);
+}
+
 void hantro_irq_done(struct hantro_dev *vpu,
 		     enum vb2_buffer_state result)
 {
@@ -152,12 +160,15 @@ static void device_run(void *priv)
 	src = hantro_get_src_buf(ctx);
 	dst = hantro_get_dst_buf(ctx);
 
+	ret = pm_runtime_get_sync(ctx->dev->dev);
+	if (ret < 0) {
+		pm_runtime_put_noidle(ctx->dev->dev);
+		goto err_cancel_job;
+	}
+
 	ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
 	if (ret)
 		goto err_cancel_job;
-	ret = pm_runtime_get_sync(ctx->dev->dev);
-	if (ret < 0)
-		goto err_cancel_job;
 
 	v4l2_m2m_buf_copy_metadata(src, dst, true);
 
@@ -165,7 +176,7 @@ static void device_run(void *priv)
 	return;
 
 err_cancel_job:
-	hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
+	hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
 }
 
 static struct v4l2_m2m_ops vpu_m2m_ops = {
#36 lore raw

PATCH 10/25 media: marvel-ccic: fix some issues when getting pm_runtime

In reply to Mauro Carvalho Chehab

Calling pm_runtime_get_sync() is bad, since even when it returns an error, pm_runtime_put*() should be called. So, use instead pm_runtime_resume_and_get().

While here, ensure that the error condition will be checked during clock enable an media open() calls.

---
 drivers/media/platform/marvell-ccic/mcam-core.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/media/platform/marvell-ccic/mcam-core.c +7 -2
index 141bf5d97a04..ea87110d9073 100644
@@ -918,6 +918,7 @@ static int mclk_enable(struct clk_hw *hw)
 	struct mcam_camera *cam = container_of(hw, struct mcam_camera, mclk_hw);
 	int mclk_src;
 	int mclk_div;
+	int ret;
 
 	/*
 	 * Clock the sensor appropriately.  Controller clock should
@@ -931,7 +932,9 @@ static int mclk_enable(struct clk_hw *hw)
 		mclk_div = 2;
 	}
 
-	pm_runtime_get_sync(cam->dev);
+	ret = pm_runtime_resume_and_get(cam->dev);
+	if (ret < 0)
+		return ret;
 	clk_enable(cam->clk[0]);
 	mcam_reg_write(cam, REG_CLKCTRL, (mclk_src << 29) | mclk_div);
 	mcam_ctlr_power_up(cam);
@@ -1611,7 +1614,9 @@ static int mcam_v4l_open(struct file *filp)
 		ret = sensor_call(cam, core, s_power, 1);
 		if (ret)
 			goto out;
-		pm_runtime_get_sync(cam->dev);
+		ret = pm_runtime_resume_and_get(cam->dev);
+		if (ret < 0)
+			goto out;
 		__mcam_cam_reset(cam);
 		mcam_set_config_needed(cam, 1);
 	}
Signature · 1 line
2.30.2
#37 lore raw

PATCH 11/25 media: mdk-mdp: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

While here, fix the return contition of mtk_mdp_m2m_start_streaming(), as it doesn't make any sense to return 0 if the PM runtime failed to resume.

---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c +3 -3
index ace4528cdc5e..f14779e7596e 100644
@@ -391,12 +391,12 @@ static int mtk_mdp_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct mtk_mdp_ctx *ctx = q->drv_priv;
 	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->mdp_dev->pdev->dev);
+	ret = pm_runtime_resume_and_get(&ctx->mdp_dev->pdev->dev);
 	if (ret < 0)
-		mtk_mdp_dbg(1, "[%d] pm_runtime_get_sync failed:%d",
+		mtk_mdp_dbg(1, "[%d] pm_runtime_resume_and_get failed:%d",
 			    ctx->id, ret);
 
-	return 0;
+	return ret;
 }
 
 static void *mtk_mdp_m2m_buf_remove(struct mtk_mdp_ctx *ctx,
Signature · 1 line
2.30.2
#38 lore raw

PATCH 12/25 media: rcar_fdp1: simplify error check logic at fdp_open()

In reply to Mauro Carvalho Chehab

Avoid some code duplication by moving the common error path logit at fdp_open().

---
 drivers/media/platform/rcar_fdp1.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/media/platform/rcar_fdp1.c +8 -7
index 01c1fbb97bf6..d26413fa5205 100644
@@ -2117,9 +2117,7 @@ static int fdp1_open(struct file *file)
 
 	if (ctx->hdl.error) {
 		ret = ctx->hdl.error;
-		v4l2_ctrl_handler_free(&ctx->hdl);
-		kfree(ctx);
-		goto done;
+		goto error_ctx;
 	}
 
 	ctx->fh.ctrl_handler = &ctx->hdl;
@@ -2133,10 +2131,7 @@ static int fdp1_open(struct file *file)
 
 	if (IS_ERR(ctx->fh.m2m_ctx)) {
 		ret = PTR_ERR(ctx->fh.m2m_ctx);
-
-		v4l2_ctrl_handler_free(&ctx->hdl);
-		kfree(ctx);
-		goto done;
+		goto error_ctx;
 	}
 
 	/* Perform any power management required */
@@ -2147,6 +2142,12 @@ static int fdp1_open(struct file *file)
 	dprintk(fdp1, "Created instance: %p, m2m_ctx: %p\n",
 		ctx, ctx->fh.m2m_ctx);
 
+	mutex_unlock(&fdp1->dev_mutex);
+	return 0;
+
+error_ctx:
+	v4l2_ctrl_handler_free(&ctx->hdl);
+	kfree(ctx);
 done:
 	mutex_unlock(&fdp1->dev_mutex);
 	return ret;
Signature · 1 line
2.30.2
#39 lore raw

Re: [PATCH 12/25] media: rcar_fdp1: simplify error check logic at fdp_open()

Hello!

Quoted 2 lines · Mauro Carvalho Chehab

Avoid some code duplication by moving the common error path logit at fdp_open().

Logic?

Quoted 1 line

[...]

MBR, Sergei

#40 lore raw

PATCH 13/25 media: rcar_fdp1: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Also, right now, the driver is ignoring any troubles when trying to do PM resume. So, add the proper error handling for the code.

---
 drivers/media/platform/rcar_fdp1.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/media/platform/rcar_fdp1.c +11 -2
index d26413fa5205..89aac60066d9 100644
@@ -2135,7 +2135,9 @@ static int fdp1_open(struct file *file)
 	}
 
 	/* Perform any power management required */
-	pm_runtime_get_sync(fdp1->dev);
+	ret = pm_runtime_resume_and_get(fdp1->dev);
+	if (ret < 0)
+		goto error_pm;
 
 	v4l2_fh_add(&ctx->fh);
 
@@ -2145,6 +2147,8 @@ static int fdp1_open(struct file *file)
 	mutex_unlock(&fdp1->dev_mutex);
 	return 0;
 
+error_pm:
+       v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
 error_ctx:
 	v4l2_ctrl_handler_free(&ctx->hdl);
 	kfree(ctx);
@@ -2352,7 +2356,9 @@ static int fdp1_probe(struct platform_device *pdev)
 
 	/* Power up the cells to read HW */
 	pm_runtime_enable(&pdev->dev);
-	pm_runtime_get_sync(fdp1->dev);
+	ret = pm_runtime_resume_and_get(fdp1->dev);
+	if (ret < 0)
+		goto disable_pm;
 
 	hw_version = fdp1_read(fdp1, FD1_IP_INTDATA);
 	switch (hw_version) {
@@ -2381,6 +2387,9 @@ static int fdp1_probe(struct platform_device *pdev)
 
 	return 0;
 
+disable_pm:
+	pm_runtime_disable(fdp1->dev);
+
 release_m2m:
 	v4l2_m2m_release(fdp1->m2m_dev);
 
Signature · 1 line
2.30.2
Reviewed-by on v1 13/25
#41 lore raw

Re: [PATCH 13/25] media: rcar_fdp1: fix pm_runtime_get_sync() usage count

Quoted 7 lines · On Wed, 5 May 2021 11:42:03 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 5 lines

Also, right now, the driver is ignoring any troubles when trying to do PM resume. So, add the proper error handling for the code.

Quoted 49 lines
---
 drivers/media/platform/rcar_fdp1.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/media/platform/rcar_fdp1.c +11 -2
index d26413fa5205..89aac60066d9 100644
@@ -2135,7 +2135,9 @@ static int fdp1_open(struct file *file)
 	}
 
 	/* Perform any power management required */
-	pm_runtime_get_sync(fdp1->dev);
+	ret = pm_runtime_resume_and_get(fdp1->dev);
+	if (ret < 0)
+		goto error_pm;
 
 	v4l2_fh_add(&ctx->fh);
 
@@ -2145,6 +2147,8 @@ static int fdp1_open(struct file *file)
 	mutex_unlock(&fdp1->dev_mutex);
 	return 0;
 
+error_pm:
+       v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
 error_ctx:
 	v4l2_ctrl_handler_free(&ctx->hdl);
 	kfree(ctx);
@@ -2352,7 +2356,9 @@ static int fdp1_probe(struct platform_device *pdev)
 
 	/* Power up the cells to read HW */
 	pm_runtime_enable(&pdev->dev);
-	pm_runtime_get_sync(fdp1->dev);
+	ret = pm_runtime_resume_and_get(fdp1->dev);
+	if (ret < 0)
+		goto disable_pm;
 
 	hw_version = fdp1_read(fdp1, FD1_IP_INTDATA);
 	switch (hw_version) {
@@ -2381,6 +2387,9 @@ static int fdp1_probe(struct platform_device *pdev)
 
 	return 0;
 
+disable_pm:
+	pm_runtime_disable(fdp1->dev);
+
 release_m2m:
 	v4l2_m2m_release(fdp1->m2m_dev);
 
#42 lore raw

PATCH 14/25 media: renesas-ceu: Properly check for PM errors

In reply to Mauro Carvalho Chehab

Right now, the driver just assumes that PM runtime resume worked, but it may fail.

Well, the pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

So, using it is tricky. Let's replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") and return an error if something bad happens.

This should ensure that the PM runtime usage_count will be properly decremented if an error happens at open time.

---
 drivers/media/platform/renesas-ceu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/renesas-ceu.c +2 -2
index cd137101d41e..17f01b6e3fe0 100644
@@ -1099,10 +1099,10 @@ static int ceu_open(struct file *file)
 
 	mutex_lock(&ceudev->mlock);
 	/* Causes soft-reset and sensor power on on first open */
-	pm_runtime_get_sync(ceudev->dev);
+	ret = pm_runtime_resume_and_get(ceudev->dev);
 	mutex_unlock(&ceudev->mlock);
 
-	return 0;
+	return ret;
 }
 
 static int ceu_release(struct file *file)
Signature · 1 line
2.30.2
Acked-by on v1 14/25
#43 lore raw

Re: [PATCH 14/25] media: renesas-ceu: Properly check for PM errors

Hi Mauro,

Quoted 11 lines · Mauro Carvalho Chehab

Right now, the driver just assumes that PM runtime resume worked, but it may fail.

Well, the pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

So, using it is tricky. Let's replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") and return an error if something bad happens.

Quoted 5 lines

This should ensure that the PM runtime usage_count will be properly decremented if an error happens at open time.

Looks good!

Thanks
j

Quoted 24 lines
---
 drivers/media/platform/renesas-ceu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/platform/renesas-ceu.c +2 -3
index cd137101d41e..17f01b6e3fe0 100644
@@ -1099,10 +1099,10 @@ static int ceu_open(struct file *file)
 
 	mutex_lock(&ceudev->mlock);
 	/* Causes soft-reset and sensor power on on first open */
-	pm_runtime_get_sync(ceudev->dev);
+	ret = pm_runtime_resume_and_get(ceudev->dev);
 	mutex_unlock(&ceudev->mlock);
 
-	return 0;
+	return ret;
 }
 
 static int ceu_release(struct file *file)
--

2.30.2

#44 lore raw

PATCH 15/25 media: s5p: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

While here, check if the PM runtime error was caught at s5p_cec_adap_enable().

---
 drivers/media/cec/platform/s5p/s5p_cec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/cec/platform/s5p/s5p_cec.c +4 -1
index 3c7c4c3c798c..028a09a7531e 100644
@@ -35,10 +35,13 @@ MODULE_PARM_DESC(debug, "debug level (0-2)");
 
 static int s5p_cec_adap_enable(struct cec_adapter *adap, bool enable)
 {
+	int ret;
 	struct s5p_cec_dev *cec = cec_get_drvdata(adap);
 
 	if (enable) {
-		pm_runtime_get_sync(cec->dev);
+		ret = pm_runtime_resume_and_get(cec->dev);
+		if (ret < 0)
+			return ret;
 
 		s5p_cec_reset(cec);
 
Signature · 1 line
2.30.2
Reviewed-by on v1 15/25
#45 lore raw

Re: [PATCH 15/25] media: s5p: fix pm_runtime_get_sync() usage count

Quoted 7 lines · On Wed, 5 May 2021 11:42:05 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 6 lines

While here, check if the PM runtime error was caught at s5p_cec_adap_enable().

Quoted 23 lines
---
 drivers/media/cec/platform/s5p/s5p_cec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/cec/platform/s5p/s5p_cec.c +4 -1
index 3c7c4c3c798c..028a09a7531e 100644
@@ -35,10 +35,13 @@ MODULE_PARM_DESC(debug, "debug level (0-2)");
 
 static int s5p_cec_adap_enable(struct cec_adapter *adap, bool enable)
 {
+	int ret;
 	struct s5p_cec_dev *cec = cec_get_drvdata(adap);
 
 	if (enable) {
-		pm_runtime_get_sync(cec->dev);
+		ret = pm_runtime_resume_and_get(cec->dev);
+		if (ret < 0)
+			return ret;
 
 		s5p_cec_reset(cec);
 
#46 lore raw

PATCH 16/25 media: am437x: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

While here, ensure that the driver will check if PM runtime resumed at vpfe_initialize_device().

---
 drivers/media/platform/am437x/am437x-vpfe.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/media/platform/am437x/am437x-vpfe.c +13 -2
index 6cdc77dda0e4..1c9cb9e05fdf 100644
@@ -1021,7 +1021,9 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe)
 	if (ret)
 		return ret;
 
-	pm_runtime_get_sync(vpfe->pdev);
+	ret = pm_runtime_resume_and_get(vpfe->pdev);
+	if (ret < 0)
+		return ret;
 
 	vpfe_config_enable(&vpfe->ccdc, 1);
 
@@ -2443,7 +2445,11 @@ static int vpfe_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 
 	/* for now just enable it here instead of waiting for the open */
-	pm_runtime_get_sync(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
+	if (ret < 0) {
+		vpfe_err(vpfe, "Unable to resume device.\n");
+		goto probe_out_v4l2_unregister;
+	}
 
 	vpfe_ccdc_config_defaults(ccdc);
 
@@ -2530,6 +2536,11 @@ static int vpfe_suspend(struct device *dev)
 
 	/* only do full suspend if streaming has started */
 	if (vb2_start_streaming_called(&vpfe->buffer_queue)) {
+		/*
+		 * ignore RPM resume errors here, as it is already too late.
+		 * A check like that should happen earlier, either at
+		 * open() or just before start streaming.
+		 */
 		pm_runtime_get_sync(dev);
 		vpfe_config_enable(ccdc, 1);
 
Signature · 1 line
2.30.2
Reviewed-by on v1 16/25
#47 lore raw

Re: [PATCH 16/25] media: am437x: fix pm_runtime_get_sync() usage count

Quoted 11 lines · On Wed, 5 May 2021 11:42:06 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

While here, ensure that the driver will check if PM runtime resumed at vpfe_initialize_device().

Quoted 44 lines
---
 drivers/media/platform/am437x/am437x-vpfe.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/media/platform/am437x/am437x-vpfe.c +13 -2
index 6cdc77dda0e4..1c9cb9e05fdf 100644
@@ -1021,7 +1021,9 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe)
 	if (ret)
 		return ret;
 
-	pm_runtime_get_sync(vpfe->pdev);
+	ret = pm_runtime_resume_and_get(vpfe->pdev);
+	if (ret < 0)
+		return ret;
 
 	vpfe_config_enable(&vpfe->ccdc, 1);
 
@@ -2443,7 +2445,11 @@ static int vpfe_probe(struct platform_device *pdev)
 	pm_runtime_enable(&pdev->dev);
 
 	/* for now just enable it here instead of waiting for the open */
-	pm_runtime_get_sync(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
+	if (ret < 0) {
+		vpfe_err(vpfe, "Unable to resume device.\n");
+		goto probe_out_v4l2_unregister;
+	}
 
 	vpfe_ccdc_config_defaults(ccdc);
 
@@ -2530,6 +2536,11 @@ static int vpfe_suspend(struct device *dev)
 
 	/* only do full suspend if streaming has started */
 	if (vb2_start_streaming_called(&vpfe->buffer_queue)) {
+		/*
+		 * ignore RPM resume errors here, as it is already too late.
+		 * A check like that should happen earlier, either at
+		 * open() or just before start streaming.
+		 */
 		pm_runtime_get_sync(dev);
 		vpfe_config_enable(ccdc, 1);
 
Acked-by on v1 16/25
#48 lore raw

Re: [PATCH 16/25] media: am437x: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

Hi Mauro,

Thank you for the patch.

Quoted 8 lines · Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 8 lines

While here, ensure that the driver will check if PM runtime resumed at vpfe_initialize_device().

---
 drivers/media/platform/am437x/am437x-vpfe.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Cheers,
Prabhakar

Quoted 43 lines
drivers/media/platform/am437x/am437x-vpfe.c +13 -3
index 6cdc77dda0e4..1c9cb9e05fdf 100644
@@ -1021,7 +1021,9 @@ static int vpfe_initialize_device(struct vpfe_device *vpfe)
        if (ret)
                return ret;
 
-       pm_runtime_get_sync(vpfe->pdev);
+       ret = pm_runtime_resume_and_get(vpfe->pdev);
+       if (ret < 0)
+               return ret;
 
        vpfe_config_enable(&vpfe->ccdc, 1);
 
@@ -2443,7 +2445,11 @@ static int vpfe_probe(struct platform_device *pdev)
        pm_runtime_enable(&pdev->dev);
 
        /* for now just enable it here instead of waiting for the open */
-       pm_runtime_get_sync(&pdev->dev);
+       ret = pm_runtime_resume_and_get(&pdev->dev);
+       if (ret < 0) {
+               vpfe_err(vpfe, "Unable to resume device.\n");
+               goto probe_out_v4l2_unregister;
+       }
 
        vpfe_ccdc_config_defaults(ccdc);
 
@@ -2530,6 +2536,11 @@ static int vpfe_suspend(struct device *dev)
 
        /* only do full suspend if streaming has started */
        if (vb2_start_streaming_called(&vpfe->buffer_queue)) {
+               /*
+                * ignore RPM resume errors here, as it is already too late.
+                * A check like that should happen earlier, either at
+                * open() or just before start streaming.
+                */
                pm_runtime_get_sync(dev);
                vpfe_config_enable(ccdc, 1);
 
--

2.30.2

#49 lore raw

PATCH 17/25 media: sh_vou: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

While here, check if the PM runtime error was caught at open time.

---
 drivers/media/platform/sh_vou.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/media/platform/sh_vou.c +5 -1
index 4ac48441f22c..ca4310e26c49 100644
@@ -1133,7 +1133,11 @@ static int sh_vou_open(struct file *file)
 	if (v4l2_fh_is_singular_file(file) &&
 	    vou_dev->status == SH_VOU_INITIALISING) {
 		/* First open */
-		pm_runtime_get_sync(vou_dev->v4l2_dev.dev);
+		err = pm_runtime_resume_and_get(vou_dev->v4l2_dev.dev);
+		if (err < 0) {
+			v4l2_fh_release(file);
+			goto done_open;
+		}
 		err = sh_vou_hw_init(vou_dev);
 		if (err < 0) {
 			pm_runtime_put(vou_dev->v4l2_dev.dev);
Signature · 1 line
2.30.2
#50 lore raw

PATCH 18/25 media: mtk-vcodec: fix PM runtime get logic

In reply to Mauro Carvalho Chehab

Currently, the driver just assumes that PM runtime logic succeded resuming the device.

That may not be the case, as pm_runtime_get_sync() can fail (but keeping the usage count incremented).

Replace the code to use pm_runtime_resume_and_get(), and letting it return the error code.

This way, if mtk_vcodec_dec_pw_on() fails, the logic under fops_vcodec_open() will do the right thing and return an error, instead of just assuming that the device is ready to be used.

---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 4 +++-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c  | 8 +++++---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h  | 2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +3 -1
index 147dfef1638d..f87dc47d9e63 100644
@@ -126,7 +126,9 @@ static int fops_vcodec_open(struct file *file)
 	mtk_vcodec_dec_set_default_params(ctx);
 
 	if (v4l2_fh_is_singular(&ctx->fh)) {
-		mtk_vcodec_dec_pw_on(&dev->pm);
+		ret = mtk_vcodec_dec_pw_on(&dev->pm);
+		if (ret < 0)
+			goto err_load_fw;
 		/*
 		 * Does nothing if firmware was already loaded.
 		 */
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c +5 -3
index ddee7046ce42..6038db96f71c 100644
@@ -88,13 +88,15 @@ void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev *dev)
 	put_device(dev->pm.larbvdec);
 }
 
-void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
+int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
 {
 	int ret;
 
-	ret = pm_runtime_get_sync(pm->dev);
+	ret = pm_runtime_resume_and_get(pm->dev);
 	if (ret)
-		mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
+		mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
+
+	return ret;
 }
 
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h +1 -1
index 872d8bf8cfaf..280aeaefdb65 100644
@@ -12,7 +12,7 @@
 int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *dev);
 void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev *dev);
 
-void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm);
+int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm);
Signature · 1 line
2.30.2
Reviewed-by on v1 18/25
#51 lore raw

Re: [PATCH 18/25] media: mtk-vcodec: fix PM runtime get logic

Quoted 9 lines · On Wed, 5 May 2021 11:42:08 +0200 Mauro Carvalho Chehab…

Currently, the driver just assumes that PM runtime logic succeded resuming the device.

That may not be the case, as pm_runtime_get_sync() can fail (but keeping the usage count incremented).

Replace the code to use pm_runtime_resume_and_get(), and letting it return the error code.

Quoted 6 lines

This way, if mtk_vcodec_dec_pw_on() fails, the logic under fops_vcodec_open() will do the right thing and return an error, instead of just assuming that the device is ready to be used.

Quoted 57 lines
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 4 +++-
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c  | 8 +++++---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h  | 2 +-
 3 files changed, 9 insertions(+), 5 deletions(-)
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +3 -1
index 147dfef1638d..f87dc47d9e63 100644
@@ -126,7 +126,9 @@ static int fops_vcodec_open(struct file *file)
 	mtk_vcodec_dec_set_default_params(ctx);
 
 	if (v4l2_fh_is_singular(&ctx->fh)) {
-		mtk_vcodec_dec_pw_on(&dev->pm);
+		ret = mtk_vcodec_dec_pw_on(&dev->pm);
+		if (ret < 0)
+			goto err_load_fw;
 		/*
 		 * Does nothing if firmware was already loaded.
 		 */
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c +5 -3
index ddee7046ce42..6038db96f71c 100644
@@ -88,13 +88,15 @@ void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev *dev)
 	put_device(dev->pm.larbvdec);
 }
 
-void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
+int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm)
 {
 	int ret;
 
-	ret = pm_runtime_get_sync(pm->dev);
+	ret = pm_runtime_resume_and_get(pm->dev);
 	if (ret)
-		mtk_v4l2_err("pm_runtime_get_sync fail %d", ret);
+		mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret);
+
+	return ret;
 }
 
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.h +1 -1
index 872d8bf8cfaf..280aeaefdb65 100644
@@ -12,7 +12,7 @@
 int mtk_vcodec_init_dec_pm(struct mtk_vcodec_dev *dev);
 void mtk_vcodec_release_dec_pm(struct mtk_vcodec_dev *dev);
 
-void mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm);
+int mtk_vcodec_dec_pw_on(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_dec_clock_on(struct mtk_vcodec_pm *pm);
 void mtk_vcodec_dec_clock_off(struct mtk_vcodec_pm *pm);
#52 lore raw

PATCH 19/25 media: s5p-jpeg: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

As a plus, pm_runtime_resume_and_get() doesn't return positive numbers, so the return code validation can be removed.

---
 drivers/media/platform/s5p-jpeg/jpeg-core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +1 -4
index 026111505f5a..d402e456f27d 100644
@@ -2566,11 +2566,8 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
 static int s5p_jpeg_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(q);
-	int ret;
 
-	ret = pm_runtime_get_sync(ctx->jpeg->dev);
-
-	return ret > 0 ? 0 : ret;
+	return pm_runtime_resume_and_get(ctx->jpeg->dev);
 }
 
 static void s5p_jpeg_stop_streaming(struct vb2_queue *q)
Signature · 1 line
2.30.2
Reviewed-by on v1 19/25
#53 lore raw

Re: [PATCH 19/25] media: s5p-jpeg: fix pm_runtime_get_sync() usage count

Quoted 7 lines · On Wed, 5 May 2021 11:42:09 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 7 lines

As a plus, pm_runtime_resume_and_get() doesn't return positive numbers, so the return code validation can be removed.

Quoted 21 lines
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/media/platform/s5p-jpeg/jpeg-core.c +1 -4
index 026111505f5a..d402e456f27d 100644
@@ -2566,11 +2566,8 @@ static void s5p_jpeg_buf_queue(struct vb2_buffer *vb)
 static int s5p_jpeg_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct s5p_jpeg_ctx *ctx = vb2_get_drv_priv(q);
-	int ret;
 
-	ret = pm_runtime_get_sync(ctx->jpeg->dev);
-
-	return ret > 0 ? 0 : ret;
+	return pm_runtime_resume_and_get(ctx->jpeg->dev);
 }
 
 static void s5p_jpeg_stop_streaming(struct vb2_queue *q)
#54 lore raw

PATCH 20/25 media: sti/delta: 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/platform/sti/delta/delta-v4l2.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/sti/delta/delta-v4l2.c +3 -5
index c691b3d81549..064a00a3084a 100644
@@ -954,10 +954,8 @@ static void delta_run_work(struct work_struct *work)
 	/* enable the hardware */
 	if (!dec->pm) {
 		ret = delta_get_sync(ctx);
-		if (ret) {
-			delta_put_autosuspend(ctx);
+		if (ret)
 			goto err;
-		}
 	}
 
 	/* decode this access unit */
@@ -1277,9 +1275,9 @@ int delta_get_sync(struct delta_ctx *ctx)
 	int ret = 0;
 
 	/* enable the hardware */
-	ret = pm_runtime_get_sync(delta->dev);
+	ret = pm_runtime_resume_and_get(delta->dev);
 	if (ret < 0) {
-		dev_err(delta->dev, "%s pm_runtime_get_sync failed (%d)\n",
+		dev_err(delta->dev, "%s pm_runtime_resume_and_get failed (%d)\n",
 			__func__, ret);
 		return ret;
 	}
Signature · 1 line
2.30.2
#55 lore raw

Re: [PATCH 20/25] media: sti/delta: use pm_runtime_resume_and_get()

Quoted 7 lines · On Wed, 5 May 2021 11:42:10 +0200 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.

Trivial thing inline otherwise fine.

Quoted 21 lines
---
 drivers/media/platform/sti/delta/delta-v4l2.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/sti/delta/delta-v4l2.c +1 -3
index c691b3d81549..064a00a3084a 100644
@@ -954,10 +954,8 @@ static void delta_run_work(struct work_struct *work)
 	/* enable the hardware */
 	if (!dec->pm) {
 		ret = delta_get_sync(ctx);
-		if (ret) {
-			delta_put_autosuspend(ctx);
+		if (ret)
 			goto err;
-		}
 	}
 
 	/* decode this access unit */

drivers/media/platform/sti/delta/delta-v4l2.c int delta_get_sync(struct delta_ctx *ctx) · line 1275

Quoted 1 line
drivers/media/platform/sti/delta/delta-v4l2.c +0 -0
@@ -1277,9 +1275,9 @@ int delta_get_sync(struct delta_ctx *ctx)
 	int ret = 0;

Loose the init

Quoted 10 lines
drivers/media/platform/sti/delta/delta-v4l2.c +2 -2
 	/* enable the hardware */
-	ret = pm_runtime_get_sync(delta->dev);
+	ret = pm_runtime_resume_and_get(delta->dev);
 	if (ret < 0) {
-		dev_err(delta->dev, "%s pm_runtime_get_sync failed (%d)\n",
+		dev_err(delta->dev, "%s pm_runtime_resume_and_get failed (%d)\n",
 			__func__, ret);
 		return ret;
 	}
Reviewed-by
#56 lore raw

Re: [PATCH 20/25] media: sti/delta: use pm_runtime_resume_and_get()

Quoted 12 lines · On Wed, 5 May 2021 13:01:58 +0100 Jonathan Cameron…
Quoted 7 lines · On Wed, 5 May 2021 11:42:10 +0200 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.

Trivial thing inline otherwise fine.

Quoted 36 lines
Quoted 21 lines
---
 drivers/media/platform/sti/delta/delta-v4l2.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/sti/delta/delta-v4l2.c +1 -3
index c691b3d81549..064a00a3084a 100644
@@ -954,10 +954,8 @@ static void delta_run_work(struct work_struct *work)
 	/* enable the hardware */
 	if (!dec->pm) {
 		ret = delta_get_sync(ctx);
-		if (ret) {
-			delta_put_autosuspend(ctx);
+		if (ret)
 			goto err;
-		}
 	}
 
 	/* decode this access unit */

drivers/media/platform/sti/delta/delta-v4l2.c int delta_get_sync(struct delta_ctx *ctx) · line 1275

Quoted 1 line
drivers/media/platform/sti/delta/delta-v4l2.c +0 -0
@@ -1277,9 +1275,9 @@ int delta_get_sync(struct delta_ctx *ctx)
 	int ret = 0;  

Loose the init

Quoted 10 lines
drivers/media/platform/sti/delta/delta-v4l2.c +2 -2
 	/* enable the hardware */
-	ret = pm_runtime_get_sync(delta->dev);
+	ret = pm_runtime_resume_and_get(delta->dev);
 	if (ret < 0) {
-		dev_err(delta->dev, "%s pm_runtime_get_sync failed (%d)\n",
+		dev_err(delta->dev, "%s pm_runtime_resume_and_get failed (%d)\n",
 			__func__, ret);
 		return ret;
 	}  
#57 lore raw

PATCH 21/25 media: sunxi: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

---
 drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c +1 -1
index 3f81dd17755c..fbcca59a0517 100644
@@ -494,7 +494,7 @@ static int rotate_start_streaming(struct vb2_queue *vq, unsigned int count)
 		struct device *dev = ctx->dev->dev;
 		int ret;
 
-		ret = pm_runtime_get_sync(dev);
+		ret = pm_runtime_resume_and_get(dev);
 		if (ret < 0) {
 			dev_err(dev, "Failed to enable module\n");
 
Signature · 1 line
2.30.2
#58 lore raw

PATCH 22/25 media: sti/bdisp: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

The bdisp_start_streaming() doesn't take it into account, which would unbalance PM usage counter at bdisp_stop_streaming().

The logic at bdisp_probe() is correct, but the best is to use the same call along the driver.

So, replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

---
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/platform/sti/bdisp/bdisp-v4l2.c +4 -3
index 060ca85f64d5..85288da9d2ae 100644
@@ -499,7 +499,7 @@ static int bdisp_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct bdisp_ctx *ctx = q->drv_priv;
 	struct vb2_v4l2_buffer *buf;
-	int ret = pm_runtime_get_sync(ctx->bdisp_dev->dev);
+	int ret = pm_runtime_resume_and_get(ctx->bdisp_dev->dev);
 
 	if (ret < 0) {
 		dev_err(ctx->bdisp_dev->dev, "failed to set runtime PM\n");
@@ -1364,10 +1364,10 @@ static int bdisp_probe(struct platform_device *pdev)
 
 	/* Power management */
 	pm_runtime_enable(dev);
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0) {
 		dev_err(dev, "failed to set PM\n");
-		goto err_pm;
+		goto err_remove;
 	}
 
 	/* Filters */
@@ -1395,6 +1395,7 @@ static int bdisp_probe(struct platform_device *pdev)
 	bdisp_hw_free_filters(bdisp->dev);
 err_pm:
 	pm_runtime_put(dev);
+err_remove:
 	bdisp_debugfs_remove(bdisp);
 	v4l2_device_unregister(&bdisp->v4l2_dev);
 err_clk:
Signature · 1 line
2.30.2
Reviewed-by on v1 22/25
#59 lore raw

Re: [PATCH 22/25] media: sti/bdisp: fix pm_runtime_get_sync() usage count

Quoted 9 lines · On Wed, 5 May 2021 11:42:12 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

The bdisp_start_streaming() doesn't take it into account, which would unbalance PM usage counter at bdisp_stop_streaming().

The logic at bdisp_probe() is correct, but the best is to use the same call along the driver.

Quoted 6 lines

So, replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 38 lines
---
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/media/platform/sti/bdisp/bdisp-v4l2.c +4 -3
index 060ca85f64d5..85288da9d2ae 100644
@@ -499,7 +499,7 @@ static int bdisp_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct bdisp_ctx *ctx = q->drv_priv;
 	struct vb2_v4l2_buffer *buf;
-	int ret = pm_runtime_get_sync(ctx->bdisp_dev->dev);
+	int ret = pm_runtime_resume_and_get(ctx->bdisp_dev->dev);
 
 	if (ret < 0) {
 		dev_err(ctx->bdisp_dev->dev, "failed to set runtime PM\n");
@@ -1364,10 +1364,10 @@ static int bdisp_probe(struct platform_device *pdev)
 
 	/* Power management */
 	pm_runtime_enable(dev);
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0) {
 		dev_err(dev, "failed to set PM\n");
-		goto err_pm;
+		goto err_remove;
 	}
 
 	/* Filters */
@@ -1395,6 +1395,7 @@ static int bdisp_probe(struct platform_device *pdev)
 	bdisp_hw_free_filters(bdisp->dev);
 err_pm:
 	pm_runtime_put(dev);
+err_remove:
 	bdisp_debugfs_remove(bdisp);
 	v4l2_device_unregister(&bdisp->v4l2_dev);
 err_clk:
#60 lore raw

PATCH 23/25 media: exynos4-is: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

On some places, this is ok, but on others the usage count ended being unbalanced on failures.

Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

As a bonus, such function always return zero on success. So, some code can be simplified.

---
 drivers/media/platform/exynos4-is/fimc-capture.c   |  6 ++----
 drivers/media/platform/exynos4-is/fimc-is.c        |  4 ++--
 drivers/media/platform/exynos4-is/fimc-isp-video.c |  3 +--
 drivers/media/platform/exynos4-is/fimc-isp.c       |  7 +++----
 drivers/media/platform/exynos4-is/fimc-lite.c      |  5 +++--
 drivers/media/platform/exynos4-is/fimc-m2m.c       |  5 +----
 drivers/media/platform/exynos4-is/media-dev.c      |  9 +++------
 drivers/media/platform/exynos4-is/mipi-csis.c      | 10 ++++------
 8 files changed, 19 insertions(+), 30 deletions(-)
drivers/media/platform/exynos4-is/fimc-capture.c +2 -4
index 13c838d3f947..0da36443173c 100644
@@ -478,11 +478,9 @@ static int fimc_capture_open(struct file *file)
 		goto unlock;
 
 	set_bit(ST_CAPT_BUSY, &fimc->state);
-	ret = pm_runtime_get_sync(&fimc->pdev->dev);
-	if (ret < 0) {
-		pm_runtime_put_sync(&fimc->pdev->dev);
+	ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
+	if (ret < 0)
 		goto unlock;
-	}
 
 	ret = v4l2_fh_open(file);
 	if (ret) {
drivers/media/platform/exynos4-is/fimc-is.c +2 -2
index 972d9601d236..1b24f5bfc4af 100644
@@ -828,9 +828,9 @@ static int fimc_is_probe(struct platform_device *pdev)
 			goto err_irq;
 	}
 
-	ret = pm_runtime_get_sync(dev);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret < 0)
-		goto err_pm;
+		goto err_irq;
 
 	vb2_dma_contig_set_max_seg_size(dev, DMA_BIT_MASK(32));
 
drivers/media/platform/exynos4-is/fimc-isp-video.c +1 -2
index 612b9872afc8..8d9dc597deaa 100644
@@ -275,7 +275,7 @@ static int isp_video_open(struct file *file)
 	if (ret < 0)
 		goto unlock;
 
-	ret = pm_runtime_get_sync(&isp->pdev->dev);
+	ret = pm_runtime_resume_and_get(&isp->pdev->dev);
 	if (ret < 0)
 		goto rel_fh;
 
@@ -293,7 +293,6 @@ static int isp_video_open(struct file *file)
 	if (!ret)
 		goto unlock;
 rel_fh:
-	pm_runtime_put_noidle(&isp->pdev->dev);
 	v4l2_fh_release(file);
 unlock:
 	mutex_unlock(&isp->video_lock);
drivers/media/platform/exynos4-is/fimc-isp.c +3 -4
index a77c49b18511..74b49d30901e 100644
@@ -304,11 +304,10 @@ static int fimc_isp_subdev_s_power(struct v4l2_subdev *sd, int on)
 	pr_debug("on: %d\n", on);
 
 	if (on) {
-		ret = pm_runtime_get_sync(&is->pdev->dev);
-		if (ret < 0) {
-			pm_runtime_put(&is->pdev->dev);
+		ret = pm_runtime_resume_and_get(&is->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
+
 		set_bit(IS_ST_PWR_ON, &is->state);
 
 		ret = fimc_is_start_firmware(is);
drivers/media/platform/exynos4-is/fimc-lite.c +3 -2
index fe20af3a7178..4d8b18078ff3 100644
@@ -469,9 +469,9 @@ static int fimc_lite_open(struct file *file)
 	}
 
 	set_bit(ST_FLITE_IN_USE, &fimc->state);
-	ret = pm_runtime_get_sync(&fimc->pdev->dev);
+	ret = pm_runtime_resume_and_get(&fimc->pdev->dev);
 	if (ret < 0)
-		goto err_pm;
+		goto err_in_use;
 
 	ret = v4l2_fh_open(file);
 	if (ret < 0)
@@ -499,6 +499,7 @@ static int fimc_lite_open(struct file *file)
 	v4l2_fh_release(file);
 err_pm:
 	pm_runtime_put_sync(&fimc->pdev->dev);
+err_in_use:
 	clear_bit(ST_FLITE_IN_USE, &fimc->state);
 unlock:
 	mutex_unlock(&fimc->lock);
drivers/media/platform/exynos4-is/fimc-m2m.c +1 -4
index c9704a147e5c..df8e2aa454d8 100644
@@ -73,17 +73,14 @@ static void fimc_m2m_shutdown(struct fimc_ctx *ctx)
 static int start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct fimc_ctx *ctx = q->drv_priv;
-	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->fimc_dev->pdev->dev);
-	return ret > 0 ? 0 : ret;
+	return pm_runtime_resume_and_get(&ctx->fimc_dev->pdev->dev);
 }
 
 static void stop_streaming(struct vb2_queue *q)
 {
 	struct fimc_ctx *ctx = q->drv_priv;
 
-
 	fimc_m2m_shutdown(ctx);
 	fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR);
 	pm_runtime_put(&ctx->fimc_dev->pdev->dev);
drivers/media/platform/exynos4-is/media-dev.c +3 -6
index 13d192ba4aa6..e025178db06c 100644
@@ -512,11 +512,9 @@ static int fimc_md_register_sensor_entities(struct fimc_md *fmd)
 	if (!fmd->pmf)
 		return -ENXIO;
 
-	ret = pm_runtime_get_sync(fmd->pmf);
-	if (ret < 0) {
-		pm_runtime_put(fmd->pmf);
+	ret = pm_runtime_resume_and_get(fmd->pmf);
+	if (ret < 0)
 		return ret;
-	}
 
 	fmd->num_sensors = 0;
 
@@ -1291,8 +1289,7 @@ static int cam_clk_prepare(struct clk_hw *hw)
 	if (camclk->fmd->pmf == NULL)
 		return -ENODEV;
 
-	ret = pm_runtime_get_sync(camclk->fmd->pmf);
-	return ret < 0 ? ret : 0;
+	return pm_runtime_resume_and_get(camclk->fmd->pmf);
 }
 
 static void cam_clk_unprepare(struct clk_hw *hw)
drivers/media/platform/exynos4-is/mipi-csis.c +4 -6
index 1aac167abb17..ebf39c856894 100644
@@ -494,7 +494,7 @@ static int s5pcsis_s_power(struct v4l2_subdev *sd, int on)
 	struct device *dev = &state->pdev->dev;
 
 	if (on)
-		return pm_runtime_get_sync(dev);
+		return pm_runtime_resume_and_get(dev);
 
 	return pm_runtime_put_sync(dev);
 }
@@ -509,11 +509,9 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)
 
 	if (enable) {
 		s5pcsis_clear_counters(state);
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret && ret != 1) {
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
 	}
 
 	mutex_lock(&state->lock);
@@ -535,7 +533,7 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)
 	if (!enable)
 		pm_runtime_put(&state->pdev->dev);
 
-	return ret == 1 ? 0 : ret;
+	return ret;
 }
 
 static int s5pcsis_enum_mbus_code(struct v4l2_subdev *sd,
Signature · 1 line
2.30.2
#61 lore raw

Re: [PATCH 23/25] media: exynos4-is: fix pm_runtime_get_sync() usage count

Quoted 11 lines · On Wed, 5 May 2021 11:42:13 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

On some places, this is ok, but on others the usage count ended being unbalanced on failures.

Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 5 lines

As a bonus, such function always return zero on success. So, some code can be simplified.

Might be nice to call out the two odd cases below.

Quoted 14 lines
drivers/media/platform/exynos4-is/mipi-csis.c +1 -1
index 1aac167abb17..ebf39c856894 100644
@@ -494,7 +494,7 @@ static int s5pcsis_s_power(struct v4l2_subdev *sd, int on)
 	struct device *dev = &state->pdev->dev;
 
 	if (on)
-		return pm_runtime_get_sync(dev);
+		return pm_runtime_resume_and_get(dev);
 
 	return pm_runtime_put_sync(dev);
 }

drivers/media/platform/exynos4-is/mipi-csis.c static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable) · line 513

Quoted 5 lines
drivers/media/platform/exynos4-is/mipi-csis.c +0 -2
@@ -509,11 +509,9 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)
 
 	if (enable) {
 		s5pcsis_clear_counters(state);
-		ret = pm_runtime_get_sync(&state->pdev->dev);
-		if (ret && ret != 1) {

Perhaps add something to the description on this less common case?

Quoted 17 lines
drivers/media/platform/exynos4-is/mipi-csis.c +3 -3
-			pm_runtime_put_noidle(&state->pdev->dev);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
+		if (ret < 0)
 			return ret;
-		}
 	}
 
 	mutex_lock(&state->lock);
@@ -535,7 +533,7 @@ static int s5pcsis_s_stream(struct v4l2_subdev *sd, int enable)
 	if (!enable)
 		pm_runtime_put(&state->pdev->dev);
 
-	return ret == 1 ? 0 : ret;
+	return ret;
 }
 
 static int s5pcsis_enum_mbus_code(struct v4l2_subdev *sd,
#62 lore raw

PATCH 24/25 media: exynos-gsc: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

As a bonus, as pm_runtime_get_sync() always return 0 on success, the logic can be simplified.

---
 drivers/media/platform/exynos-gsc/gsc-m2m.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/platform/exynos-gsc/gsc-m2m.c +1 -3
index 27a3c92c73bc..f1cf847d1cc2 100644
@@ -56,10 +56,8 @@ static void __gsc_m2m_job_abort(struct gsc_ctx *ctx)
 static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct gsc_ctx *ctx = q->drv_priv;
-	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->gsc_dev->pdev->dev);
-	return ret > 0 ? 0 : ret;
+	return pm_runtime_resume_and_get(&ctx->gsc_dev->pdev->dev);
 }
 
 static void __gsc_m2m_cleanup_queue(struct gsc_ctx *ctx)
Signature · 1 line
2.30.2
Reviewed-by on v1 24/25
#63 lore raw

Re: [PATCH 24/25] media: exynos-gsc: fix pm_runtime_get_sync() usage count

Quoted 7 lines · On Wed, 5 May 2021 11:42:14 +0200 Mauro Carvalho Chehab…

The pm_runtime_get_sync() internally increments the
dev->power.usage_count without decrementing it, even on errors.
Replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter, avoiding
a potential PM usage counter leak.

Quoted 5 lines

As a bonus, as pm_runtime_get_sync() always return 0 on success, the logic can be simplified.

Quoted 20 lines
---
 drivers/media/platform/exynos-gsc/gsc-m2m.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/media/platform/exynos-gsc/gsc-m2m.c +1 -3
index 27a3c92c73bc..f1cf847d1cc2 100644
@@ -56,10 +56,8 @@ static void __gsc_m2m_job_abort(struct gsc_ctx *ctx)
 static int gsc_m2m_start_streaming(struct vb2_queue *q, unsigned int count)
 {
 	struct gsc_ctx *ctx = q->drv_priv;
-	int ret;
 
-	ret = pm_runtime_get_sync(&ctx->gsc_dev->pdev->dev);
-	return ret > 0 ? 0 : ret;
+	return pm_runtime_resume_and_get(&ctx->gsc_dev->pdev->dev);
 }
 
 static void __gsc_m2m_cleanup_queue(struct gsc_ctx *ctx)
#64 lore raw

PATCH 25/25 media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

---
 drivers/media/i2c/ccs/ccs-core.c | 39 ++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +24 -15
index b05f409014b2..04c3ab9e37b4 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */
+	rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->ctrl_handler);
+	if (rval)
+		goto error;
 
+	rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
+	if (rval)
+		goto error;
+
+	/* Keep PM runtime usage_count incremented on success */
 	return 0;
+error:
+	pm_runtime_put_noidle(&client->dev);
+	return rval;
 }
 
 static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
@@ -3089,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
maintainer
#65 lore raw

Re: [PATCH 25/25] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

Hi Mauro,

Thanks for the patch.

Quoted 9 lines · Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

Quoted 7 lines

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Could you add Fixes: line and Cc: stable?

The patch that breaks this is 96e3a6b92f23a .

It would be better to fix the bug first so the patch to the stable trees doesn't need special handling.

Quoted 38 lines
---
 drivers/media/i2c/ccs/ccs-core.c | 39 ++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +13 -10
index b05f409014b2..04c3ab9e37b4 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */
+	rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->ctrl_handler);
+	if (rval)

drivers/media/i2c/ccs/ccs-core.c static int ccs_pm_get_init(struct ccs_sensor *sensor) · line 1908

Quoted 10 lines
drivers/media/i2c/ccs/ccs-core.c +8 -0
+		goto error;
 
+	rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
+	if (rval)
+		goto error;
+
+	/* Keep PM runtime usage_count incremented on success */
 	return 0;
+error:
+	pm_runtime_put_noidle(&client->dev);

This needs to be pm_runtime_put() as the device has been successfully.

Quoted 19 lines
drivers/media/i2c/ccs/ccs-core.c +3 -5
+	return rval;
 }
 
 static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
@@ -3089,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 · 3 lines
Kind regards,

Sakari Ailus
#66 lore raw

Re: [PATCH 25/25] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

Em Wed, 5 May 2021 13:34:09 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 20 lines

Hi Mauro,

Thanks for the patch.

Quoted 15 lines · Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Quoted 3 lines
Quoted 1 line

Could you add Fixes: line and Cc: stable?

Sure. See the fixes one enclosed.

Quoted 45 lines

The patch that breaks this is 96e3a6b92f23a .

It would be better to fix the bug first so the patch to the stable trees doesn't need special handling.

Quoted 40 lines
---
 drivers/media/i2c/ccs/ccs-core.c | 39 ++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +14 -10
index b05f409014b2..04c3ab9e37b4 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */
+	rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->ctrl_handler);
+	if (rval)
+		goto error;
 
Quoted 10 lines

drivers/media/i2c/ccs/ccs-core.c static int ccs_pm_get_init(struct ccs_sensor *sensor) · line 1908

Quoted 8 lines
drivers/media/i2c/ccs/ccs-core.c +7 -0
+	rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
+	if (rval)
+		goto error;
+
+	/* Keep PM runtime usage_count incremented on success */
 	return 0;
+error:
+	pm_runtime_put_noidle(&client->dev);  

This needs to be pm_runtime_put() as the device has been successfully.

Ok.

Quoted 18 lines
Quoted 18 lines
drivers/media/i2c/ccs/ccs-core.c +3 -5
+	return rval;
 }
 
 static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
@@ -3089,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;
-	}
 
Quoted 3 lines

drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3109

Quoted 2 lines
drivers/media/i2c/ccs/ccs-core.c +0 -0
 	if (sensor->streaming)
 		ccs_stop_streaming(sensor);  

Thanks,
Mauro

---

[PATCH] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Fixes 96e3a6b92f23 ("media: smiapp: Avoid maintaining power state information")
drivers/media/i2c/ccs/ccs-core.c +22 -10
index b05f409014b2..5ea471fefa3a 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */
+	rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->ctrl_handler);
+	if (rval)
+		goto error;
 
+	rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
+	if (rval)
+		goto error;
+
+	/* Keep PM runtime usage_count incremented on success */
 	return 0;
+error:
+	pm_runtime_put(&client->dev);
+	return rval;
 }
 
 static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
#67 lore raw

Re: [PATCH 25/25] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

Em Wed, 5 May 2021 12:57:00 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:

Quoted 157 lines

Em Wed, 5 May 2021 13:34:09 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 20 lines

Hi Mauro,

Thanks for the patch.

Quoted 15 lines · Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Quoted 3 lines
Quoted 1 line

Could you add Fixes: line and Cc: stable?

Sure. See the fixes one enclosed.

Quoted 45 lines

The patch that breaks this is 96e3a6b92f23a .

It would be better to fix the bug first so the patch to the stable trees doesn't need special handling.

Quoted 40 lines
---
 drivers/media/i2c/ccs/ccs-core.c | 39 ++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +14 -10
index b05f409014b2..04c3ab9e37b4 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */
+	rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->ctrl_handler);
+	if (rval)
+		goto error;
 
Quoted 10 lines

drivers/media/i2c/ccs/ccs-core.c static int ccs_pm_get_init(struct ccs_sensor *sensor) · line 1908

Quoted 8 lines
drivers/media/i2c/ccs/ccs-core.c +7 -0
+	rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
+	if (rval)
+		goto error;
+
+	/* Keep PM runtime usage_count incremented on success */
 	return 0;
+error:
+	pm_runtime_put_noidle(&client->dev);  

This needs to be pm_runtime_put() as the device has been successfully.

Ok.

Quoted 18 lines
Quoted 18 lines
drivers/media/i2c/ccs/ccs-core.c +3 -5
+	return rval;
 }
 
 static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
@@ -3089,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;
-	}
 
Quoted 3 lines

drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3109

Quoted 2 lines
drivers/media/i2c/ccs/ccs-core.c +0 -0
 	if (sensor->streaming)
 		ccs_stop_streaming(sensor);  

Thanks,
Mauro

---

[PATCH] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Fixes 96e3a6b92f23 ("media: smiapp: Avoid maintaining power state information")
drivers/media/i2c/ccs/ccs-core.c +7 -5
index b05f409014b2..5ea471fefa3a 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->

drivers/media/i2c/ccs/ccs-core.c static int ccs_pm_get_init(struct ccs_sensor *sensor) · line 1896

Quoted 10 lines
drivers/media/i2c/ccs/ccs-core.c +4 -5
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */

In time: I'll fold this at the patch:

drivers/media/i2c/ccs/ccs-core.c +1 -1
index 5ea471fefa3a..4a848ac2d2cd 100644
@@ -1896 +1896 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
-       /* Restore V4L2 controls to the suspended device */
+       /* Restore V4L2 controls to the previously suspended device */

Regards,
Mauro

Reviewed-by
#68 lore raw

Re: [PATCH 25/25] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

Quoted 137 lines · On Wed, 5 May 2021 12:58:57 +0200 Mauro Carvalho Chehab…

Em Wed, 5 May 2021 12:57:00 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:

Quoted 134 lines

Em Wed, 5 May 2021 13:34:09 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 20 lines

Hi Mauro,

Thanks for the patch.

Quoted 15 lines · Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Quoted 3 lines
Quoted 1 line

Could you add Fixes: line and Cc: stable?

Sure. See the fixes one enclosed.

Quoted 45 lines

The patch that breaks this is 96e3a6b92f23a .

It would be better to fix the bug first so the patch to the stable trees doesn't need special handling.

Quoted 40 lines
---
 drivers/media/i2c/ccs/ccs-core.c | 39 ++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +14 -10
index b05f409014b2..04c3ab9e37b4 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */
+	rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->ctrl_handler);
+	if (rval)
+		goto error;
 
Quoted 10 lines

drivers/media/i2c/ccs/ccs-core.c static int ccs_pm_get_init(struct ccs_sensor *sensor) · line 1908

Quoted 8 lines
drivers/media/i2c/ccs/ccs-core.c +7 -0
+	rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
+	if (rval)
+		goto error;
+
+	/* Keep PM runtime usage_count incremented on success */
 	return 0;
+error:
+	pm_runtime_put_noidle(&client->dev);    

This needs to be pm_runtime_put() as the device has been successfully.

Ok.

Quoted 18 lines
Quoted 18 lines
drivers/media/i2c/ccs/ccs-core.c +3 -5
+	return rval;
 }
 
 static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
@@ -3089,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;
-	}
 
Quoted 3 lines

drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3109

Quoted 2 lines
drivers/media/i2c/ccs/ccs-core.c +0 -0
 	if (sensor->streaming)
 		ccs_stop_streaming(sensor);    

Thanks,
Mauro

---

[PATCH] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Fixes 96e3a6b92f23 ("media: smiapp: Avoid maintaining power state information")
Quoted 46 lines
Quoted 23 lines
drivers/media/i2c/ccs/ccs-core.c +7 -5
index b05f409014b2..5ea471fefa3a 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->

drivers/media/i2c/ccs/ccs-core.c static int ccs_pm_get_init(struct ccs_sensor *sensor) · line 1896

Quoted 10 lines
drivers/media/i2c/ccs/ccs-core.c +4 -5
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */  

In time: I'll fold this at the patch:

drivers/media/i2c/ccs/ccs-core.c +1 -1
index 5ea471fefa3a..4a848ac2d2cd 100644
@@ -1896 +1896 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
-       /* Restore V4L2 controls to the suspended device */
+       /* Restore V4L2 controls to the previously suspended device */

Regards,
Mauro

#69 lore raw

Re: [PATCH 25/25] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

Hi Jonathan,

Em Wed, 5 May 2021 13:35:48 +0100
Jonathan Cameron <[email protected]> escreveu:

Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

[PATCH] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Fixes 96e3a6b92f23 ("media: smiapp: Avoid maintaining power state information")

Per Sakari's request (for practical reasons on backporting and c/c stable), this was split into two separate patches, one fixing the issues, and a separate trivial one with just the pm_runtime_resume_and_get(). I'm adding your RB on both.

Thanks,
Mauro

#70 lore raw

Re: [PATCH 25/25] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

Quoted 25 lines · On Wed, 5 May 2021 16:06:45 +0200 Mauro Carvalho Chehab…

Hi Jonathan,

Em Wed, 5 May 2021 13:35:48 +0100
Jonathan Cameron <[email protected]> escreveu:

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines

[PATCH] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Fixes 96e3a6b92f23 ("media: smiapp: Avoid maintaining power state information")
Quoted 6 lines
Quoted 1 line

Per Sakari's request (for practical reasons on backporting and c/c stable), this was split into two separate patches, one fixing the issues, and a separate trivial one with just the pm_runtime_resume_and_get(). I'm adding your RB on both.

Makes sense.

Jonathan

Quoted 3 lines

Thanks,
Mauro

maintainer Acked-by
#71 lore raw

Re: [PATCH 25/25] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

In reply to Mauro Carvalho Chehab

Hi Mauro,

Quoted 23 lines · Mauro Carvalho Chehab

Em Wed, 5 May 2021 13:34:09 +0300
Sakari Ailus <[email protected]> escreveu:

Quoted 20 lines

Hi Mauro,

Thanks for the patch.

Quoted 15 lines · Mauro Carvalho Chehab

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Quoted 10 lines
Quoted 3 lines
Quoted 1 line

Could you add Fixes: line and Cc: stable?

Sure. See the fixes one enclosed.

Quoted 4 lines

The patch that breaks this is 96e3a6b92f23a .

It would be better to fix the bug first so the patch to the stable trees doesn't need special handling.

Please ignore this comment.

Quoted 98 lines
Quoted 41 lines
Quoted 41 lines
---
 drivers/media/i2c/ccs/ccs-core.c | 39 ++++++++++++++++++++------------
 1 file changed, 24 insertions(+), 15 deletions(-)
drivers/media/i2c/ccs/ccs-core.c +14 -10
index b05f409014b2..04c3ab9e37b4 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */
+	rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->ctrl_handler);
+	if (rval)
+		goto error;
 
Quoted 10 lines

drivers/media/i2c/ccs/ccs-core.c static int ccs_pm_get_init(struct ccs_sensor *sensor)

Quoted 8 lines
drivers/media/i2c/ccs/ccs-core.c +7 -0
+	rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
+	if (rval)
+		goto error;
+
+	/* Keep PM runtime usage_count incremented on success */
 	return 0;
+error:
+	pm_runtime_put_noidle(&client->dev);  

This needs to be pm_runtime_put() as the device has been successfully.

Ok.

Quoted 18 lines
Quoted 18 lines
drivers/media/i2c/ccs/ccs-core.c +3 -5
+	return rval;
 }
 
 static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
@@ -3089,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;
-	}
 
Quoted 3 lines

drivers/media/i2c/ccs/ccs-core.c static int __maybe_unused ccs_suspend(struct device *dev) · line 3109

Quoted 2 lines
drivers/media/i2c/ccs/ccs-core.c +0 -0
 	if (sensor->streaming)
 		ccs_stop_streaming(sensor);  

Thanks,
Mauro

---

[PATCH] media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

The pm_runtime_get_sync() internally increments the dev->power.usage_count without decrementing it, even on errors.

There is a bug at ccs_pm_get_init(): when this function returns an error, the stream is not started, and RPM usage_count should not be incremented. However, if the calls to v4l2_ctrl_handler_setup() return errors, it will be kept incremented.

At ccs_suspend() the best is to replace it by the new pm_runtime_resume_and_get(), introduced by:
commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter") in order to properly decrement the usage counter automatically,
in the case of errors.

Quoted 3 lines
Fixes 96e3a6b92f23 ("media: smiapp: Avoid maintaining power state information")
Quoted 53 lines
drivers/media/i2c/ccs/ccs-core.c +22 -10
index b05f409014b2..5ea471fefa3a 100644
@@ -1880,21 +1880,33 @@ static int ccs_pm_get_init(struct ccs_sensor *sensor)
 	struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
 	int rval;
 
+	/*
+	 * It can't use pm_runtime_resume_and_get() here, as the driver
+	 * relies at the returned value to detect if the device was already
+	 * active or not.
+	 */
 	rval = pm_runtime_get_sync(&client->dev);
-	if (rval < 0) {
-		pm_runtime_put_noidle(&client->dev);
+	if (rval < 0)
+		goto error;
 
-		return rval;
-	} else if (!rval) {
-		rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->
-					       ctrl_handler);
-		if (rval)
-			return rval;
+	/* Device was already active, so don't set controls */
+	if (rval == 1)
+		return 0;
 
-		return v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
-	}
+	/* Restore V4L2 controls to the suspended device */
+	rval = v4l2_ctrl_handler_setup(&sensor->pixel_array->ctrl_handler);
+	if (rval)
+		goto error;
 
+	rval = v4l2_ctrl_handler_setup(&sensor->src->ctrl_handler);
+	if (rval)
+		goto error;
+
+	/* Keep PM runtime usage_count incremented on success */
 	return 0;
+error:
+	pm_runtime_put(&client->dev);
+	return rval;
 }
 
 static int ccs_set_stream(struct v4l2_subdev *subdev, int enable)
Signature · 3 lines
Kind regards,

Sakari Ailus
#72 lore raw
In reply to Mauro Carvalho Chehab

Em Wed, 5 May 2021 11:41:50 +0200
Mauro Carvalho Chehab <[email protected]> escreveu:

Quoted 9 lines

As part of an effort to cleanup pm_runtime*get* calls, I detected a number of issues at the media subsystem.

Most of the patches here were submitted previously at:

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

This series contain just the bug fixes and other related issues that are present with the current code on media.

Series merged on my stage tree, at:
https://git.linuxtv.org/media_stage.git/log/

I'll be merging it at media_tree (either for 5.13 or 5.14) after the end of the merge window (likely next week).

Please let me know if you find any problems on it.

PS.: please notice that my stage tree can be rebased.

Regards,
Mauro

Quoted 67 lines

It address the points from the existing reviews. I also did my own set of reviews, in order to avoid regressions.

Changes from v4 of the previous changeset:

- reworked i2c/css RPM get logic;
- dropped two patches that could cause regressions;
- am437x: keep using pm_runtime_get_sync on suspend/resume;
- atmel: fix the returned code and add a print on failures at start streaming;
- simplify some checks for return code > 0;
- mdk-vcodec: properly handle RPM errors at device on logic;
- venus: rework venus_sys_error_handler() logic;
- sti/delta: fix an issue at the error checking logic.

Mauro Carvalho Chehab (25):
staging: media: rkvdec: fix pm_runtime_get_sync() usage count
staging: media: imx7-mipi-csis: fix pm_runtime_get_sync() usage count
media: venus: Rework error fail recover logic
media: s5p_cec: decrement usage count if disabled
media: i2c: ccs-core: return the right error code at suspend
media: i2c: imx334: fix the pm runtime get logic
media: exynos-gsc: don't resume at remove time
media: atmel: properly get pm_runtime
media: hantro: do a PM resume earlier
media: marvel-ccic: fix some issues when getting pm_runtime
media: mdk-mdp: fix pm_runtime_get_sync() usage count
media: rcar_fdp1: simplify error check logic at fdp_open()
media: rcar_fdp1: fix pm_runtime_get_sync() usage count
media: renesas-ceu: Properly check for PM errors
media: s5p: fix pm_runtime_get_sync() usage count
media: am437x: fix pm_runtime_get_sync() usage count
media: sh_vou: fix pm_runtime_get_sync() usage count
media: mtk-vcodec: fix PM runtime get logic
media: s5p-jpeg: fix pm_runtime_get_sync() usage count
media: sti/delta: use pm_runtime_resume_and_get()
media: sunxi: fix pm_runtime_get_sync() usage count
media: sti/bdisp: fix pm_runtime_get_sync() usage count
media: exynos4-is: fix pm_runtime_get_sync() usage count
media: exynos-gsc: fix pm_runtime_get_sync() usage count
media: i2c: ccs-core: fix pm_runtime_get_sync() usage count

 drivers/media/cec/platform/s5p/s5p_cec.c      |  7 ++-
 drivers/media/i2c/ccs/ccs-core.c              | 41 ++++++++-----
 drivers/media/i2c/imx334.c                    |  7 ++-
 drivers/media/platform/am437x/am437x-vpfe.c   | 15 ++++-
 drivers/media/platform/atmel/atmel-isc-base.c | 30 +++++++---
 drivers/media/platform/atmel/atmel-isi.c      | 19 ++++--
 drivers/media/platform/exynos-gsc/gsc-core.c  | 11 ++--
 drivers/media/platform/exynos-gsc/gsc-m2m.c   |  4 +-
 .../media/platform/exynos4-is/fimc-capture.c  |  6 +-
 drivers/media/platform/exynos4-is/fimc-is.c   |  4 +-
 .../platform/exynos4-is/fimc-isp-video.c      |  3 +-
 drivers/media/platform/exynos4-is/fimc-isp.c  |  7 +--
 drivers/media/platform/exynos4-is/fimc-lite.c |  5 +-
 drivers/media/platform/exynos4-is/fimc-m2m.c  |  5 +-
 drivers/media/platform/exynos4-is/media-dev.c |  9 +--
 drivers/media/platform/exynos4-is/mipi-csis.c | 10 ++--
 .../media/platform/marvell-ccic/mcam-core.c   |  9 ++-
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c  |  6 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c  |  4 +-
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.c   |  8 ++-
 .../platform/mtk-vcodec/mtk_vcodec_dec_pm.h   |  2 +-
 drivers/media/platform/qcom/venus/core.c      | 59 +++++++++++++++----
 drivers/media/platform/rcar_fdp1.c            | 28 ++++++---
 drivers/media/platform/renesas-ceu.c          |  4 +-
 drivers/media/platform/s5p-jpeg/jpeg-core.c   |  5 +-
Quoted 9 lines
 drivers/media/platform/sh_vou.c               |  6 +-
 drivers/media/platform/sti/bdisp/bdisp-v4l2.c |  7 ++-
 drivers/media/platform/sti/delta/delta-v4l2.c |  8 +--
 .../sunxi/sun8i-rotate/sun8i_rotate.c         |  2 +-
 drivers/staging/media/hantro/hantro_drv.c     |  7 ++-
 drivers/staging/media/imx/imx7-mipi-csis.c    |  7 +--
 drivers/staging/media/rkvdec/rkvdec.c         |  2 +-
 32 files changed, 220 insertions(+), 127 deletions(-)

Thanks,
Mauro