linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/78] media: atmel: properly get pm_runtime
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
@ 2021-04-24  6:44 ` Mauro Carvalho Chehab
  2021-04-24  9:36   ` kernel test robot
  2021-04-24  6:44 ` [PATCH 03/78] media: mdk-mdp: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
                   ` (14 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:44 UTC (permalink / raw)
  Cc: Alexandre Belloni, Mauro Carvalho Chehab, linux-kernel, linuxarm,
	Ludovic Desroches, mauro.chehab, Eugen Hristev,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-media

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/atmel/atmel-isc-base.c | 26 ++++++++++++++-----
 drivers/media/platform/atmel/atmel-isi.c      | 19 +++++++++++---
 2 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/drivers/media/platform/atmel/atmel-isc-base.c b/drivers/media/platform/atmel/atmel-isc-base.c
index fe3ec8d0eaee..db1be719192a 100644
--- a/drivers/media/platform/atmel/atmel-isc-base.c
+++ b/drivers/media/platform/atmel/atmel-isc-base.c
@@ -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 0;
+	}
 
 	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,9 @@ 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)
+		goto err_pm_get;
 
 	ret = isc_configure(isc);
 	if (unlikely(ret))
@@ -838,7 +848,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:
@@ -1831,7 +1841,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
diff --git a/drivers/media/platform/atmel/atmel-isi.c b/drivers/media/platform/atmel/atmel-isi.c
index 0514be6153df..6a433926726d 100644
--- a/drivers/media/platform/atmel/atmel-isi.c
+++ b/drivers/media/platform/atmel/atmel-isi.c
@@ -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) {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 03/78] media: mdk-mdp: fix pm_runtime_get_sync() usage count
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
  2021-04-24  6:44 ` [PATCH 01/78] media: atmel: properly get pm_runtime Mauro Carvalho Chehab
@ 2021-04-24  6:44 ` Mauro Carvalho Chehab
  2021-04-24  6:44 ` [PATCH 05/78] " Mauro Carvalho Chehab
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:44 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrew-CT Chen,
	Houlong Wei, Matthias Brugger, Mauro Carvalho Chehab,
	Minghsiu Tsai, linux-arm-kernel, linux-kernel, linux-media,
	linux-mediatek

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 and avoid memory
leaks.

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
index ace4528cdc5e..f14779e7596e 100644
--- a/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
+++ b/drivers/media/platform/mtk-mdp/mtk_mdp_m2m.c
@@ -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,
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 05/78] media: mdk-mdp: fix pm_runtime_get_sync() usage count
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
  2021-04-24  6:44 ` [PATCH 01/78] media: atmel: properly get pm_runtime Mauro Carvalho Chehab
  2021-04-24  6:44 ` [PATCH 03/78] media: mdk-mdp: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
@ 2021-04-24  6:44 ` Mauro Carvalho Chehab
  2021-04-24 18:23   ` Ezequiel Garcia
  2021-04-24  6:44 ` [PATCH 14/78] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
                   ` (12 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:44 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Heiko Stuebner, Jacob Chen, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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 and avoid memory
leaks.

While here, check if the PM runtime was caught during
chipset probing time.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/rockchip/rga/rga.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
index 9d122429706e..bf3fd71ec3af 100644
--- a/drivers/media/platform/rockchip/rga/rga.c
+++ b/drivers/media/platform/rockchip/rga/rga.c
@@ -866,7 +866,9 @@ static int rga_probe(struct platform_device *pdev)
 		goto unreg_video_dev;
 	}
 
-	pm_runtime_get_sync(rga->dev);
+	ret = pm_runtime_resume_and_get(rga->dev);
+	if (ret < 0)
+		goto unreg_video_dev;
 
 	rga->version.major = (rga_read(rga, RGA_VERSION_INFO) >> 24) & 0xFF;
 	rga->version.minor = (rga_read(rga, RGA_VERSION_INFO) >> 20) & 0x0F;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 14/78] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (2 preceding siblings ...)
  2021-04-24  6:44 ` [PATCH 05/78] " Mauro Carvalho Chehab
@ 2021-04-24  6:44 ` Mauro Carvalho Chehab
  2021-04-26 10:11   ` Rui Miguel Silva
  2021-04-24  6:44 ` [PATCH 16/78] staging: media: cedrus_video: " Mauro Carvalho Chehab
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:44 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Fabio Estevam,
	Greg Kroah-Hartman, Mauro Carvalho Chehab, NXP Linux Team,
	Pengutronix Kernel Team, Philipp Zabel, Rui Miguel Silva,
	Sascha Hauer, Shawn Guo, Steve Longerbeam, devel,
	linux-arm-kernel, linux-kernel, linux-media

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
index 025fdc488bd6..1dc680d94a46 100644
--- a/drivers/staging/media/imx/imx7-mipi-csis.c
+++ b/drivers/staging/media/imx/imx7-mipi-csis.c
@@ -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;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 16/78] staging: media: cedrus_video: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (3 preceding siblings ...)
  2021-04-24  6:44 ` [PATCH 14/78] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
@ 2021-04-24  6:44 ` Mauro Carvalho Chehab
  2021-04-24  6:44 ` [PATCH 20/78] media: mtk-vcodec: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:44 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Greg Kroah-Hartman, Jernej Skrabec, Mauro Carvalho Chehab,
	Maxime Ripard, Paul Kocialkowski, devel, linux-arm-kernel,
	linux-kernel, linux-media

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/staging/media/sunxi/cedrus/cedrus_video.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index b62eb8e84057..9ddd789d0b1f 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -490,11 +490,9 @@ static int cedrus_start_streaming(struct vb2_queue *vq, unsigned int count)
 	}
 
 	if (V4L2_TYPE_IS_OUTPUT(vq->type)) {
-		ret = pm_runtime_get_sync(dev->dev);
-		if (ret < 0) {
-			pm_runtime_put_noidle(dev->dev);
+		ret = pm_runtime_resume_and_get(dev->dev);
+		if (ret < 0)
 			goto err_cleanup;
-		}
 
 		if (dev->dec_ops[ctx->current_codec]->start) {
 			ret = dev->dec_ops[ctx->current_codec]->start(ctx);
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 20/78] media: mtk-vcodec: fix pm_runtime_get_sync() usage count
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (4 preceding siblings ...)
  2021-04-24  6:44 ` [PATCH 16/78] staging: media: cedrus_video: " Mauro Carvalho Chehab
@ 2021-04-24  6:44 ` Mauro Carvalho Chehab
  2021-04-24  6:44 ` [PATCH 21/78] media: s5p-jpeg: " Mauro Carvalho Chehab
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:44 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrew-CT Chen,
	Matthias Brugger, Mauro Carvalho Chehab, Tiffany Lin,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

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 and avoid memory
leaks.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
index ddee7046ce42..fe096fe61c9d 100644
--- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
+++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_pm.c
@@ -92,9 +92,9 @@ void 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);
 }
 
 void mtk_vcodec_dec_pw_off(struct mtk_vcodec_pm *pm)
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 21/78] media: s5p-jpeg: fix pm_runtime_get_sync() usage count
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (5 preceding siblings ...)
  2021-04-24  6:44 ` [PATCH 20/78] media: mtk-vcodec: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
@ 2021-04-24  6:44 ` Mauro Carvalho Chehab
  2021-04-27  9:14   ` Sylwester Nawrocki
  2021-04-24  6:44 ` [PATCH 23/78] media: sun8i_rotate: " Mauro Carvalho Chehab
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:44 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Andrzej Pietrasiewicz, Jacek Anaszewski, Mauro Carvalho Chehab,
	Sylwester Nawrocki, linux-arm-kernel, linux-kernel, linux-media

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 and avoid memory
leaks.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/s5p-jpeg/jpeg-core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
index 026111505f5a..c4f19418a460 100644
--- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
+++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
@@ -2568,7 +2568,7 @@ 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);
+	ret = pm_runtime_resume_and_get(ctx->jpeg->dev);
 
 	return ret > 0 ? 0 : ret;
 }
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 23/78] media: sun8i_rotate: fix pm_runtime_get_sync() usage count
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (6 preceding siblings ...)
  2021-04-24  6:44 ` [PATCH 21/78] media: s5p-jpeg: " Mauro Carvalho Chehab
@ 2021-04-24  6:44 ` Mauro Carvalho Chehab
  2021-04-24  6:45 ` [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:44 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Jernej Skrabec, Mauro Carvalho Chehab, Maxime Ripard,
	linux-arm-kernel, linux-kernel, linux-media

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 and avoid memory
leaks.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
index 3f81dd17755c..fbcca59a0517 100644
--- a/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
+++ b/drivers/media/platform/sunxi/sun8i-rotate/sun8i_rotate.c
@@ -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");
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (7 preceding siblings ...)
  2021-04-24  6:44 ` [PATCH 23/78] media: sun8i_rotate: " Mauro Carvalho Chehab
@ 2021-04-24  6:45 ` Mauro Carvalho Chehab
  2021-04-25 20:57   ` Sylwester Nawrocki
  2021-04-24  6:45 ` [PATCH 58/78] media: exynos-gsc: " Mauro Carvalho Chehab
                   ` (6 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:45 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, Sylwester Nawrocki,
	linux-arm-kernel, linux-kernel, linux-media, linux-samsung-soc

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/exynos4-is/fimc-capture.c   | 6 ++----
 drivers/media/platform/exynos4-is/fimc-is.c        | 3 ++-
 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       | 2 +-
 drivers/media/platform/exynos4-is/media-dev.c      | 8 +++-----
 drivers/media/platform/exynos4-is/mipi-csis.c      | 5 ++---
 8 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
index 13c838d3f947..0da36443173c 100644
--- a/drivers/media/platform/exynos4-is/fimc-capture.c
+++ b/drivers/media/platform/exynos4-is/fimc-capture.c
@@ -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) {
diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
index 972d9601d236..bca35866cc74 100644
--- a/drivers/media/platform/exynos4-is/fimc-is.c
+++ b/drivers/media/platform/exynos4-is/fimc-is.c
@@ -828,7 +828,7 @@ 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;
 
@@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)
 	fimc_is_unregister_subdevs(is);
 err_pm:
 	pm_runtime_put_noidle(dev);
+err_suspend:
 	if (!pm_runtime_enabled(dev))
 		fimc_is_runtime_suspend(dev);
 err_irq:
diff --git a/drivers/media/platform/exynos4-is/fimc-isp-video.c b/drivers/media/platform/exynos4-is/fimc-isp-video.c
index 612b9872afc8..8d9dc597deaa 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp-video.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp-video.c
@@ -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);
diff --git a/drivers/media/platform/exynos4-is/fimc-isp.c b/drivers/media/platform/exynos4-is/fimc-isp.c
index a77c49b18511..74b49d30901e 100644
--- a/drivers/media/platform/exynos4-is/fimc-isp.c
+++ b/drivers/media/platform/exynos4-is/fimc-isp.c
@@ -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);
diff --git a/drivers/media/platform/exynos4-is/fimc-lite.c b/drivers/media/platform/exynos4-is/fimc-lite.c
index fe20af3a7178..4d8b18078ff3 100644
--- a/drivers/media/platform/exynos4-is/fimc-lite.c
+++ b/drivers/media/platform/exynos4-is/fimc-lite.c
@@ -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);
diff --git a/drivers/media/platform/exynos4-is/fimc-m2m.c b/drivers/media/platform/exynos4-is/fimc-m2m.c
index c9704a147e5c..7c1eb05c508f 100644
--- a/drivers/media/platform/exynos4-is/fimc-m2m.c
+++ b/drivers/media/platform/exynos4-is/fimc-m2m.c
@@ -75,7 +75,7 @@ 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);
+	ret = pm_runtime_resume_and_get(&ctx->fimc_dev->pdev->dev);
 	return ret > 0 ? 0 : ret;
 }
 
diff --git a/drivers/media/platform/exynos4-is/media-dev.c b/drivers/media/platform/exynos4-is/media-dev.c
index 13d192ba4aa6..9346d44a06c2 100644
--- a/drivers/media/platform/exynos4-is/media-dev.c
+++ b/drivers/media/platform/exynos4-is/media-dev.c
@@ -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,7 +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);
+	ret = pm_runtime_resume_and_get(camclk->fmd->pmf);
 	return ret < 0 ? ret : 0;
 }
 
diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
index 1aac167abb17..a0218237d66b 100644
--- a/drivers/media/platform/exynos4-is/mipi-csis.c
+++ b/drivers/media/platform/exynos4-is/mipi-csis.c
@@ -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,9 +509,8 @@ 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);
+		ret = pm_runtime_resume_and_get(&state->pdev->dev);
 		if (ret && ret != 1) {
-			pm_runtime_put_noidle(&state->pdev->dev);
 			return ret;
 		}
 	}
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (8 preceding siblings ...)
  2021-04-24  6:45 ` [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
@ 2021-04-24  6:45 ` Mauro Carvalho Chehab
  2021-04-27  8:18   ` Sylwester Nawrocki
  2021-04-24  6:45 ` [PATCH 59/78] media: mtk-jpeg: " Mauro Carvalho Chehab
                   ` (5 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:45 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Hans Verkuil, Krzysztof Kozlowski, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-samsung-soc

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/exynos-gsc/gsc-core.c | 3 +--
 drivers/media/platform/exynos-gsc/gsc-m2m.c  | 2 +-
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index 9f41c2e7097a..9d5841194f6b 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)
 	struct gsc_dev *gsc = platform_get_drvdata(pdev);
 	int i;
 
-	pm_runtime_get_sync(&pdev->dev);
+	pm_runtime_resume_and_get(&pdev->dev);
 
 	gsc_unregister_m2m_device(gsc);
 	v4l2_device_unregister(&gsc->v4l2_dev);
@@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)
 	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);
 
 	dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index 27a3c92c73bc..09551e96ac15 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -58,7 +58,7 @@ 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);
+	ret = pm_runtime_resume_and_get(&ctx->gsc_dev->pdev->dev);
 	return ret > 0 ? 0 : ret;
 }
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 59/78] media: mtk-jpeg: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (9 preceding siblings ...)
  2021-04-24  6:45 ` [PATCH 58/78] media: exynos-gsc: " Mauro Carvalho Chehab
@ 2021-04-24  6:45 ` Mauro Carvalho Chehab
  2021-04-24  6:45 ` [PATCH 70/78] media: rga-buf: " Mauro Carvalho Chehab
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:45 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Bin Liu,
	Matthias Brugger, Mauro Carvalho Chehab, Rick Chang,
	linux-arm-kernel, linux-kernel, linux-media, linux-mediatek

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
index 88a23bce569d..a89c7b206eef 100644
--- a/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mtk-jpeg/mtk_jpeg_core.c
@@ -920,7 +920,7 @@ static void mtk_jpeg_enc_device_run(void *priv)
 	src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 	dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 
-	ret = pm_runtime_get_sync(jpeg->dev);
+	ret = pm_runtime_resume_and_get(jpeg->dev);
 	if (ret < 0)
 		goto enc_end;
 
@@ -973,7 +973,7 @@ static void mtk_jpeg_dec_device_run(void *priv)
 		return;
 	}
 
-	ret = pm_runtime_get_sync(jpeg->dev);
+	ret = pm_runtime_resume_and_get(jpeg->dev);
 	if (ret < 0)
 		goto dec_end;
 
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 70/78] media: rga-buf: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (10 preceding siblings ...)
  2021-04-24  6:45 ` [PATCH 59/78] media: mtk-jpeg: " Mauro Carvalho Chehab
@ 2021-04-24  6:45 ` Mauro Carvalho Chehab
  2021-04-28 17:09   ` Ezequiel Garcia
  2021-04-24  6:45 ` [PATCH 71/78] media: rkisp1-capture: " Mauro Carvalho Chehab
                   ` (3 subsequent siblings)
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:45 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
	Heiko Stuebner, Jacob Chen, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/rockchip/rga/rga-buf.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
index bf9a75b75083..81508ed5abf3 100644
--- a/drivers/media/platform/rockchip/rga/rga-buf.c
+++ b/drivers/media/platform/rockchip/rga/rga-buf.c
@@ -79,9 +79,8 @@ static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count)
 	struct rockchip_rga *rga = ctx->rga;
 	int ret;
 
-	ret = pm_runtime_get_sync(rga->dev);
+	ret = pm_runtime_resume_and_get(rga->dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(rga->dev);
 		rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED);
 		return ret;
 	}
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 71/78] media: rkisp1-capture: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (11 preceding siblings ...)
  2021-04-24  6:45 ` [PATCH 70/78] media: rga-buf: " Mauro Carvalho Chehab
@ 2021-04-24  6:45 ` Mauro Carvalho Chehab
  2021-04-24  6:45 ` [PATCH 73/78] media: s5p-mfc: " Mauro Carvalho Chehab
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:45 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Dafna Hirschfeld,
	Heiko Stuebner, Helen Koike, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media, linux-rockchip

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
index 5f6c9d1623e4..3730376897d9 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-capture.c
@@ -1003,9 +1003,8 @@ rkisp1_vb2_start_streaming(struct vb2_queue *queue, unsigned int count)
 	if (ret)
 		goto err_pipeline_stop;
 
-	ret = pm_runtime_get_sync(cap->rkisp1->dev);
+	ret = pm_runtime_resume_and_get(cap->rkisp1->dev);
 	if (ret < 0) {
-		pm_runtime_put_noidle(cap->rkisp1->dev);
 		dev_err(cap->rkisp1->dev, "power up failed %d\n", ret);
 		goto err_destroy_dummy;
 	}
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 73/78] media: s5p-mfc: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (12 preceding siblings ...)
  2021-04-24  6:45 ` [PATCH 71/78] media: rkisp1-capture: " Mauro Carvalho Chehab
@ 2021-04-24  6:45 ` Mauro Carvalho Chehab
  2021-04-27  9:36   ` Sylwester Nawrocki
  2021-04-24  6:45 ` [PATCH 75/78] media: stm32: " Mauro Carvalho Chehab
  2021-04-24  6:45 ` [PATCH 76/78] media: sun4i_v4l2: " Mauro Carvalho Chehab
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:45 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Andrzej Hajda,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/s5p-mfc/s5p_mfc_pm.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
index 62d2320a7218..88b7d33c9197 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_pm.c
@@ -78,11 +78,9 @@ int s5p_mfc_power_on(void)
 {
 	int i, ret = 0;
 
-	ret = pm_runtime_get_sync(pm->device);
-	if (ret < 0) {
-		pm_runtime_put_noidle(pm->device);
+	ret = pm_runtime_resume_and_get(pm->device);
+	if (ret < 0)
 		return ret;
-	}
 
 	/* clock control */
 	for (i = 0; i < pm->num_clocks; i++) {
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 75/78] media: stm32: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (13 preceding siblings ...)
  2021-04-24  6:45 ` [PATCH 73/78] media: s5p-mfc: " Mauro Carvalho Chehab
@ 2021-04-24  6:45 ` Mauro Carvalho Chehab
  2021-04-24  6:45 ` [PATCH 76/78] media: sun4i_v4l2: " Mauro Carvalho Chehab
  15 siblings, 0 replies; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:45 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Alexandre Torgue,
	Hugues Fruchet, Mauro Carvalho Chehab, Maxime Coquelin,
	linux-arm-kernel, linux-kernel, linux-media, linux-stm32

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/stm32/stm32-dcmi.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/stm32/stm32-dcmi.c b/drivers/media/platform/stm32/stm32-dcmi.c
index bbcc2254fa2e..5f4e1db8cfcd 100644
--- a/drivers/media/platform/stm32/stm32-dcmi.c
+++ b/drivers/media/platform/stm32/stm32-dcmi.c
@@ -723,11 +723,11 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 	u32 val = 0;
 	int ret;
 
-	ret = pm_runtime_get_sync(dcmi->dev);
+	ret = pm_runtime_resume_and_get(dcmi->dev);
 	if (ret < 0) {
 		dev_err(dcmi->dev, "%s: Failed to start streaming, cannot get sync (%d)\n",
 			__func__, ret);
-		goto err_pm_put;
+		goto err_unlock;
 	}
 
 	ret = media_pipeline_start(&dcmi->vdev->entity, &dcmi->pipeline);
@@ -848,6 +848,7 @@ static int dcmi_start_streaming(struct vb2_queue *vq, unsigned int count)
 
 err_pm_put:
 	pm_runtime_put(dcmi->dev);
+err_unlock:
 	spin_lock_irq(&dcmi->irqlock);
 	/*
 	 * Return all buffers to vb2 in QUEUED state.
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 76/78] media: sun4i_v4l2: use pm_runtime_resume_and_get()
       [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
                   ` (14 preceding siblings ...)
  2021-04-24  6:45 ` [PATCH 75/78] media: stm32: " Mauro Carvalho Chehab
@ 2021-04-24  6:45 ` Mauro Carvalho Chehab
  2021-04-24 10:21   ` kernel test robot
  15 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-24  6:45 UTC (permalink / raw)
  Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Chen-Yu Tsai,
	Jernej Skrabec, Mauro Carvalho Chehab, Maxime Ripard,
	linux-arm-kernel, linux-kernel, linux-media

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.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
index 4785faddf630..ed6ec41b9c2d 100644
--- a/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
+++ b/drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c
@@ -206,9 +206,9 @@ static int sun4i_csi_open(struct file *file)
 	if (ret)
 		return ret;
 
-	ret = pm_runtime_get_sync(csi->dev);
+	ret = pm_runtime_resume_and_get(csi->dev);
 	if (ret < 0)
-		goto err_pm_put;
+		goto err_unlock;
 
 	ret = v4l2_pipeline_pm_get(&csi->vdev.entity);
 	if (ret)
@@ -225,8 +225,7 @@ static int sun4i_csi_open(struct file *file)
 err_pipeline_pm_put:
 	v4l2_pipeline_pm_put(&csi->vdev.entity);
 
-err_pm_put:
-	pm_runtime_put(csi->dev);
+err_unlock:
 	mutex_unlock(&csi->lock);
 
 	return ret;
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 01/78] media: atmel: properly get pm_runtime
  2021-04-24  6:44 ` [PATCH 01/78] media: atmel: properly get pm_runtime Mauro Carvalho Chehab
@ 2021-04-24  9:36   ` kernel test robot
  0 siblings, 0 replies; 33+ messages in thread
From: kernel test robot @ 2021-04-24  9:36 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Alexandre Belloni, kbuild-all, linux-kernel, linuxarm,
	Ludovic Desroches, mauro.chehab, Eugen Hristev,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-media

[-- Attachment #1: Type: text/plain, Size: 4932 bytes --]

Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on rockchip/for-next tegra/for-next v5.12-rc8 next-20210423]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029
base:   git://linuxtv.org/media_tree.git master
config: nios2-randconfig-s031-20210424 (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/40fc496edfa42498090c5a0d8230ec732b82bdc9
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029
        git checkout 40fc496edfa42498090c5a0d8230ec732b82bdc9
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=nios2 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/atmel/atmel-isc-base.c: In function 'isc_awb_work':
>> drivers/media/platform/atmel/atmel-isc-base.c:1844:2: error: 'ret' undeclared (first use in this function); did you mean 'net'?
    1844 |  ret = pm_runtime_resume_and_get(isc->dev);
         |  ^~~
         |  net
   drivers/media/platform/atmel/atmel-isc-base.c:1844:2: note: each undeclared identifier is reported only once for each function it appears in

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for SERIAL_CORE_CONSOLE
   Depends on TTY && HAS_IOMEM
   Selected by
   - EARLY_PRINTK


vim +1844 drivers/media/platform/atmel/atmel-isc-base.c

  1811	
  1812	static void isc_awb_work(struct work_struct *w)
  1813	{
  1814		struct isc_device *isc =
  1815			container_of(w, struct isc_device, awb_work);
  1816		struct regmap *regmap = isc->regmap;
  1817		struct isc_ctrls *ctrls = &isc->ctrls;
  1818		u32 hist_id = ctrls->hist_id;
  1819		u32 baysel;
  1820		unsigned long flags;
  1821		u32 min, max;
  1822	
  1823		/* streaming is not active anymore */
  1824		if (isc->stop)
  1825			return;
  1826	
  1827		if (ctrls->hist_stat != HIST_ENABLED)
  1828			return;
  1829	
  1830		isc_hist_count(isc, &min, &max);
  1831		ctrls->hist_minmax[hist_id][HIST_MIN_INDEX] = min;
  1832		ctrls->hist_minmax[hist_id][HIST_MAX_INDEX] = max;
  1833	
  1834		if (hist_id != ISC_HIS_CFG_MODE_B) {
  1835			hist_id++;
  1836		} else {
  1837			isc_wb_update(ctrls);
  1838			hist_id = ISC_HIS_CFG_MODE_GR;
  1839		}
  1840	
  1841		ctrls->hist_id = hist_id;
  1842		baysel = isc->config.sd_format->cfa_baycfg << ISC_HIS_CFG_BAYSEL_SHIFT;
  1843	
> 1844		ret = pm_runtime_resume_and_get(isc->dev);
  1845		if (ret < 0)
  1846			return;
  1847	
  1848		/*
  1849		 * only update if we have all the required histograms and controls
  1850		 * if awb has been disabled, we need to reset registers as well.
  1851		 */
  1852		if (hist_id == ISC_HIS_CFG_MODE_GR || ctrls->awb == ISC_WB_NONE) {
  1853			/*
  1854			 * It may happen that DMA Done IRQ will trigger while we are
  1855			 * updating white balance registers here.
  1856			 * In that case, only parts of the controls have been updated.
  1857			 * We can avoid that by locking the section.
  1858			 */
  1859			spin_lock_irqsave(&isc->awb_lock, flags);
  1860			isc_update_awb_ctrls(isc);
  1861			spin_unlock_irqrestore(&isc->awb_lock, flags);
  1862	
  1863			/*
  1864			 * if we are doing just the one time white balance adjustment,
  1865			 * we are basically done.
  1866			 */
  1867			if (ctrls->awb == ISC_WB_ONETIME) {
  1868				v4l2_info(&isc->v4l2_dev,
  1869					  "Completed one time white-balance adjustment.\n");
  1870				/* update the v4l2 controls values */
  1871				isc_update_v4l2_ctrls(isc);
  1872				ctrls->awb = ISC_WB_NONE;
  1873			}
  1874		}
  1875		regmap_write(regmap, ISC_HIS_CFG, hist_id | baysel | ISC_HIS_CFG_RAR);
  1876		isc_update_profile(isc);
  1877		/* if awb has been disabled, we don't need to start another histogram */
  1878		if (ctrls->awb)
  1879			regmap_write(regmap, ISC_CTRLEN, ISC_CTRL_HISREQ);
  1880	
  1881		pm_runtime_put_sync(isc->dev);
  1882	}
  1883	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 34795 bytes --]

[-- Attachment #3: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 76/78] media: sun4i_v4l2: use pm_runtime_resume_and_get()
  2021-04-24  6:45 ` [PATCH 76/78] media: sun4i_v4l2: " Mauro Carvalho Chehab
@ 2021-04-24 10:21   ` kernel test robot
  0 siblings, 0 replies; 33+ messages in thread
From: kernel test robot @ 2021-04-24 10:21 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: kbuild-all, linux-media, linuxarm, mauro.chehab,
	Mauro Carvalho Chehab, Chen-Yu Tsai, Jernej Skrabec,
	Maxime Ripard, linux-arm-kernel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 4732 bytes --]

Hi Mauro,

I love your patch! Yet something to improve:

[auto build test ERROR on linuxtv-media/master]
[also build test ERROR on next-20210423]
[cannot apply to rockchip/for-next tegra/for-next v5.12-rc8]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mauro-Carvalho-Chehab/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029
base:   git://linuxtv.org/media_tree.git master
config: nios2-randconfig-s031-20210424 (attached as .config)
compiler: nios2-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-341-g8af24329-dirty
        # https://github.com/0day-ci/linux/commit/ddf22a45db8814ab855d3535a125e17f5e58f94b
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mauro-Carvalho-Chehab/media-use-pm_runtime_resume_and_get-instead-of-pm_runtime_get_sync/20210424-145029
        git checkout ddf22a45db8814ab855d3535a125e17f5e58f94b
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' W=1 ARCH=nios2 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c: In function 'sun4i_csi_open':
>> drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c:215:3: error: label 'err_pm_put' used but not defined
     215 |   goto err_pm_put;
         |   ^~~~

Kconfig warnings: (for reference only)
   WARNING: unmet direct dependencies detected for SERIAL_CORE_CONSOLE
   Depends on TTY && HAS_IOMEM
   Selected by
   - EARLY_PRINTK


vim +/err_pm_put +215 drivers/media/platform/sunxi/sun4i-csi/sun4i_v4l2.c

577bbf23b758848 Maxime Ripard         2019-08-22  199  
577bbf23b758848 Maxime Ripard         2019-08-22  200  static int sun4i_csi_open(struct file *file)
577bbf23b758848 Maxime Ripard         2019-08-22  201  {
577bbf23b758848 Maxime Ripard         2019-08-22  202  	struct sun4i_csi *csi = video_drvdata(file);
577bbf23b758848 Maxime Ripard         2019-08-22  203  	int ret;
577bbf23b758848 Maxime Ripard         2019-08-22  204  
577bbf23b758848 Maxime Ripard         2019-08-22  205  	ret = mutex_lock_interruptible(&csi->lock);
577bbf23b758848 Maxime Ripard         2019-08-22  206  	if (ret)
577bbf23b758848 Maxime Ripard         2019-08-22  207  		return ret;
577bbf23b758848 Maxime Ripard         2019-08-22  208  
ddf22a45db8814a Mauro Carvalho Chehab 2021-04-24  209  	ret = pm_runtime_resume_and_get(csi->dev);
577bbf23b758848 Maxime Ripard         2019-08-22  210  	if (ret < 0)
ddf22a45db8814a Mauro Carvalho Chehab 2021-04-24  211  		goto err_unlock;
577bbf23b758848 Maxime Ripard         2019-08-22  212  
8fd390b89cc8ca7 Ezequiel Garcia       2020-01-24  213  	ret = v4l2_pipeline_pm_get(&csi->vdev.entity);
577bbf23b758848 Maxime Ripard         2019-08-22  214  	if (ret)
577bbf23b758848 Maxime Ripard         2019-08-22 @215  		goto err_pm_put;
577bbf23b758848 Maxime Ripard         2019-08-22  216  
577bbf23b758848 Maxime Ripard         2019-08-22  217  	ret = v4l2_fh_open(file);
577bbf23b758848 Maxime Ripard         2019-08-22  218  	if (ret)
577bbf23b758848 Maxime Ripard         2019-08-22  219  		goto err_pipeline_pm_put;
577bbf23b758848 Maxime Ripard         2019-08-22  220  
577bbf23b758848 Maxime Ripard         2019-08-22  221  	mutex_unlock(&csi->lock);
577bbf23b758848 Maxime Ripard         2019-08-22  222  
577bbf23b758848 Maxime Ripard         2019-08-22  223  	return 0;
577bbf23b758848 Maxime Ripard         2019-08-22  224  
577bbf23b758848 Maxime Ripard         2019-08-22  225  err_pipeline_pm_put:
8fd390b89cc8ca7 Ezequiel Garcia       2020-01-24  226  	v4l2_pipeline_pm_put(&csi->vdev.entity);
577bbf23b758848 Maxime Ripard         2019-08-22  227  
ddf22a45db8814a Mauro Carvalho Chehab 2021-04-24  228  err_unlock:
577bbf23b758848 Maxime Ripard         2019-08-22  229  	mutex_unlock(&csi->lock);
577bbf23b758848 Maxime Ripard         2019-08-22  230  
577bbf23b758848 Maxime Ripard         2019-08-22  231  	return ret;
577bbf23b758848 Maxime Ripard         2019-08-22  232  }
577bbf23b758848 Maxime Ripard         2019-08-22  233  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 34795 bytes --]

[-- Attachment #3: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 05/78] media: mdk-mdp: fix pm_runtime_get_sync() usage count
  2021-04-24  6:44 ` [PATCH 05/78] " Mauro Carvalho Chehab
@ 2021-04-24 18:23   ` Ezequiel Garcia
  0 siblings, 0 replies; 33+ messages in thread
From: Ezequiel Garcia @ 2021-04-24 18:23 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Heiko Stuebner, Jacob Chen,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media, linux-rockchip

Hi Mauro,

On Sat, 2021-04-24 at 08:44 +0200, Mauro Carvalho Chehab wrote:
> 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 and avoid memory
> leaks.
> 
> While here, check if the PM runtime was caught during
> chipset probing time.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/media/platform/rockchip/rga/rga.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 

The commit log "media" mdk-mdp" is wrong here.

Maybe you can squash this commit with media: rga-buf: use pm_runtime_resume_and_get()?

Thanks,
Ezequiel


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get()
  2021-04-24  6:45 ` [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
@ 2021-04-25 20:57   ` Sylwester Nawrocki
  2021-04-26 13:12     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 33+ messages in thread
From: Sylwester Nawrocki @ 2021-04-25 20:57 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Krzysztof Kozlowski,
	Mauro Carvalho Chehab, Sylwester Nawrocki, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:
> 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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>   drivers/media/platform/exynos4-is/fimc-capture.c   | 6 ++----
>   drivers/media/platform/exynos4-is/fimc-is.c        | 3 ++-
>   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       | 2 +-
>   drivers/media/platform/exynos4-is/media-dev.c      | 8 +++-----
>   drivers/media/platform/exynos4-is/mipi-csis.c      | 5 ++---
>   8 files changed, 17 insertions(+), 22 deletions(-)
> 
> diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> index 13c838d3f947..0da36443173c 100644
> --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> @@ -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) {
> diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
> index 972d9601d236..bca35866cc74 100644
> --- a/drivers/media/platform/exynos4-is/fimc-is.c
> +++ b/drivers/media/platform/exynos4-is/fimc-is.c
> @@ -828,7 +828,7 @@ 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;

It seems you intended to use err_suspend label here. We don't need
a new label though, instead of err_pm we can jump to err_irq when
pm_runtime_resume_and_get() fails. Note that when runtime PM is
disabled pm_runtime_resume_and_get() always returns 0.

> @@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)
>   	fimc_is_unregister_subdevs(is);
>   err_pm:
>   	pm_runtime_put_noidle(dev);
> +err_suspend:
>   	if (!pm_runtime_enabled(dev))
>   		fimc_is_runtime_suspend(dev);
>   err_irq:


> diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
> index 1aac167abb17..a0218237d66b 100644
> --- a/drivers/media/platform/exynos4-is/mipi-csis.c
> +++ b/drivers/media/platform/exynos4-is/mipi-csis.c
> @@ -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,9 +509,8 @@ 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);
> +		ret = pm_runtime_resume_and_get(&state->pdev->dev);
>   		if (ret && ret != 1) {
> -			pm_runtime_put_noidle(&state->pdev->dev);
>   			return ret;
>   		}

Braces could be dropped as well here.

>   	}


Thanks,
Sylwester


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 14/78] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get()
  2021-04-24  6:44 ` [PATCH 14/78] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
@ 2021-04-26 10:11   ` Rui Miguel Silva
  0 siblings, 0 replies; 33+ messages in thread
From: Rui Miguel Silva @ 2021-04-26 10:11 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Fabio Estevam, Greg Kroah-Hartman,
	Mauro Carvalho Chehab, NXP Linux Team, Pengutronix Kernel Team,
	Philipp Zabel, Sascha Hauer, Shawn Guo, Steve Longerbeam, devel,
	linux-arm-kernel, linux-kernel, linux-media

Hi Mauro,
On Sat Apr 24, 2021 at 7:44 AM WEST, Mauro Carvalho Chehab wrote:
> 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.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Thanks, looks good.

Acked-by: Rui Miguel Silva <rmfrfs@gmail.com>

------
Cheers,
	 Rui
> ---
>  drivers/staging/media/imx/imx7-mipi-csis.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/media/imx/imx7-mipi-csis.c b/drivers/staging/media/imx/imx7-mipi-csis.c
> index 025fdc488bd6..1dc680d94a46 100644
> --- a/drivers/staging/media/imx/imx7-mipi-csis.c
> +++ b/drivers/staging/media/imx/imx7-mipi-csis.c
> @@ -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;
> -- 
> 2.30.2



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get()
  2021-04-25 20:57   ` Sylwester Nawrocki
@ 2021-04-26 13:12     ` Mauro Carvalho Chehab
  2021-04-27  8:06       ` Sylwester Nawrocki
  0 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-26 13:12 UTC (permalink / raw)
  To: Sylwester Nawrocki
  Cc: linuxarm, mauro.chehab, Krzysztof Kozlowski,
	Mauro Carvalho Chehab, Sylwester Nawrocki, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

Em Sun, 25 Apr 2021 22:57:25 +0200
Sylwester Nawrocki <snawrocki@kernel.org> escreveu:

> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:
> > 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.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> > ---
> >   drivers/media/platform/exynos4-is/fimc-capture.c   | 6 ++----
> >   drivers/media/platform/exynos4-is/fimc-is.c        | 3 ++-
> >   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       | 2 +-
> >   drivers/media/platform/exynos4-is/media-dev.c      | 8 +++-----
> >   drivers/media/platform/exynos4-is/mipi-csis.c      | 5 ++---
> >   8 files changed, 17 insertions(+), 22 deletions(-)
> > 
> > diff --git a/drivers/media/platform/exynos4-is/fimc-capture.c b/drivers/media/platform/exynos4-is/fimc-capture.c
> > index 13c838d3f947..0da36443173c 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-capture.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-capture.c
> > @@ -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) {
> > diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
> > index 972d9601d236..bca35866cc74 100644
> > --- a/drivers/media/platform/exynos4-is/fimc-is.c
> > +++ b/drivers/media/platform/exynos4-is/fimc-is.c
> > @@ -828,7 +828,7 @@ 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;  
> 
> It seems you intended to use err_suspend label here. We don't need
> a new label though, instead of err_pm we can jump to err_irq when
> pm_runtime_resume_and_get() fails. 

Thanks! Will fix at the next version.

> Note that when runtime PM is
> disabled pm_runtime_resume_and_get() always returns 0.

Ok, but there are a couple of conditions at rpm_resume() function
at drivers/base/power/runtime.c (which is the code that actually
handles those PM macros) that could make it to return errors,
which are independent on the PM callbacks, like those:

        if (dev->power.runtime_error)
                retval = -EINVAL;
        else if (dev->power.disable_depth > 0)
                retval = -EACCES;

and more might be added as the PM core changes.

> 
> > @@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)
> >   	fimc_is_unregister_subdevs(is);
> >   err_pm:
> >   	pm_runtime_put_noidle(dev);
> > +err_suspend:
> >   	if (!pm_runtime_enabled(dev))
> >   		fimc_is_runtime_suspend(dev);
> >   err_irq:  
> 
> 
> > diff --git a/drivers/media/platform/exynos4-is/mipi-csis.c b/drivers/media/platform/exynos4-is/mipi-csis.c
> > index 1aac167abb17..a0218237d66b 100644
> > --- a/drivers/media/platform/exynos4-is/mipi-csis.c
> > +++ b/drivers/media/platform/exynos4-is/mipi-csis.c
> > @@ -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,9 +509,8 @@ 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);
> > +		ret = pm_runtime_resume_and_get(&state->pdev->dev);
> >   		if (ret && ret != 1) {
> > -			pm_runtime_put_noidle(&state->pdev->dev);
> >   			return ret;
> >   		}  
> 
> Braces could be dropped as well here.

OK.

> 
> >   	}  
> 
> 
> Thanks,
> Sylwester
> 



Thanks,
Mauro

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get()
  2021-04-26 13:12     ` Mauro Carvalho Chehab
@ 2021-04-27  8:06       ` Sylwester Nawrocki
  0 siblings, 0 replies; 33+ messages in thread
From: Sylwester Nawrocki @ 2021-04-27  8:06 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Krzysztof Kozlowski,
	Mauro Carvalho Chehab, Sylwester Nawrocki, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

On 26.04.2021 15:12, Mauro Carvalho Chehab wrote:
> Em Sun, 25 Apr 2021 22:57:25 +0200
> Sylwester Nawrocki <snawrocki@kernel.org> escreveu:
> 
>> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:
>>> 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.
>>>
>>> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

>>> diff --git a/drivers/media/platform/exynos4-is/fimc-is.c b/drivers/media/platform/exynos4-is/fimc-is.c
>>> index 972d9601d236..bca35866cc74 100644
>>> --- a/drivers/media/platform/exynos4-is/fimc-is.c
>>> +++ b/drivers/media/platform/exynos4-is/fimc-is.c
>>> @@ -828,7 +828,7 @@ 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;
>>
>> It seems you intended to use err_suspend label here. We don't need
>> a new label though, instead of err_pm we can jump to err_irq when
>> pm_runtime_resume_and_get() fails.
> 
> Thanks! Will fix at the next version.
> 
>> Note that when runtime PM is
>> disabled pm_runtime_resume_and_get() always returns 0.
> 
> Ok, but there are a couple of conditions at rpm_resume() function
> at drivers/base/power/runtime.c (which is the code that actually
> handles those PM macros) that could make it to return errors,
> which are independent on the PM callbacks, like those:
> 
>          if (dev->power.runtime_error)
>                  retval = -EINVAL;
>          else if (dev->power.disable_depth > 0)
>                  retval = -EACCES;
> 
> and more might be added as the PM core changes.

Right, I looked only at !CONFIG_PM case, this is what the "if (!pm_runtime_enabled(dev))"
test and explicit fimc_is_runtime_{resume,suspend} calls were originally for.
Agreed, better not to rely too much on internal implementation as there is
no specific guarantees about return value at the API documentation.

Regards,
Sylwester

>>> @@ -862,6 +862,7 @@ static int fimc_is_probe(struct platform_device *pdev)
>>>    	fimc_is_unregister_subdevs(is);
>>>    err_pm:
>>>    	pm_runtime_put_noidle(dev);
>>> +err_suspend:
>>>    	if (!pm_runtime_enabled(dev))
>>>    		fimc_is_runtime_suspend(dev);
>>>    err_irq:
>>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-24  6:45 ` [PATCH 58/78] media: exynos-gsc: " Mauro Carvalho Chehab
@ 2021-04-27  8:18   ` Sylwester Nawrocki
  2021-04-27  9:30     ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 33+ messages in thread
From: Sylwester Nawrocki @ 2021-04-27  8:18 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:
> 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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  drivers/media/platform/exynos-gsc/gsc-core.c | 3 +--
>  drivers/media/platform/exynos-gsc/gsc-m2m.c  | 2 +-
>  2 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
> index 9f41c2e7097a..9d5841194f6b 100644
> --- a/drivers/media/platform/exynos-gsc/gsc-core.c
> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
> @@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)
>  	struct gsc_dev *gsc = platform_get_drvdata(pdev);
>  	int i;
>  
> -	pm_runtime_get_sync(&pdev->dev);
> +	pm_runtime_resume_and_get(&pdev->dev);
>  
>  	gsc_unregister_m2m_device(gsc);
>  	v4l2_device_unregister(&gsc->v4l2_dev);
> @@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)
>  	for (i = 0; i < gsc->num_clocks; i++)
>  		clk_disable_unprepare(gsc->clock[i]);
>  
> -	pm_runtime_put_noidle(&pdev->dev);

If we do this then the device usage count will not get decremented
after the pm_runtime_resume_and_get() call above and after driver
unload/load cycle it will not be possible to suspend the device.
I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync()
works better in that case.

Regards,
Sylwester

>  	pm_runtime_disable(&pdev->dev);
>  
>  	dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 21/78] media: s5p-jpeg: fix pm_runtime_get_sync() usage count
  2021-04-24  6:44 ` [PATCH 21/78] media: s5p-jpeg: " Mauro Carvalho Chehab
@ 2021-04-27  9:14   ` Sylwester Nawrocki
  0 siblings, 0 replies; 33+ messages in thread
From: Sylwester Nawrocki @ 2021-04-27  9:14 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andrzej Pietrasiewicz, Jacek Anaszewski,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media

On 24.04.2021 08:44, Mauro Carvalho Chehab wrote:
> 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:

s/replace/Replace

> commit dd8088d5a896 ("PM: runtime: Add pm_runtime_resume_and_get to deal with usage counter")
> in order to properly decrement the usage counter and avoid memory
> leaks.

Thank you for the patch. I'm not sure if that could cause any memory
leaks, for sure not optimal power handling for the device.

> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-27  8:18   ` Sylwester Nawrocki
@ 2021-04-27  9:30     ` Mauro Carvalho Chehab
  2021-04-27  9:42       ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-27  9:30 UTC (permalink / raw)
  To: Sylwester Nawrocki
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

Em Tue, 27 Apr 2021 10:18:12 +0200
Sylwester Nawrocki <s.nawrocki@samsung.com> escreveu:

> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:
> > 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.
> > 
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> > ---
> >  drivers/media/platform/exynos-gsc/gsc-core.c | 3 +--
> >  drivers/media/platform/exynos-gsc/gsc-m2m.c  | 2 +-
> >  2 files changed, 2 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
> > index 9f41c2e7097a..9d5841194f6b 100644
> > --- a/drivers/media/platform/exynos-gsc/gsc-core.c
> > +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
> > @@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)
> >  	struct gsc_dev *gsc = platform_get_drvdata(pdev);
> >  	int i;
> >  
> > -	pm_runtime_get_sync(&pdev->dev);
> > +	pm_runtime_resume_and_get(&pdev->dev);
> >  
> >  	gsc_unregister_m2m_device(gsc);
> >  	v4l2_device_unregister(&gsc->v4l2_dev);
> > @@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)
> >  	for (i = 0; i < gsc->num_clocks; i++)
> >  		clk_disable_unprepare(gsc->clock[i]);
> >  
> > -	pm_runtime_put_noidle(&pdev->dev);  
> 
> If we do this then the device usage count will not get decremented
> after the pm_runtime_resume_and_get() call above and after driver
> unload/load cycle it will not be possible to suspend the device.
> I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync()
> works better in that case.

Good point.

Actually, I don't see any reason why to call a PM resume
function - either being pm_runtime_get_sync() or
pm_runtime_resume_and_get().

The code there could simply be:

    static int gsc_remove(struct platform_device *pdev)
    {
        struct gsc_dev *gsc = platform_get_drvdata(pdev);
        int i;

        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_disable(&pdev->dev);

        dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
        return 0;
    }

Eventually also adding:
	pm_runtime_suspended(&pdev->dev);

just after pm_runtime_disable().

Regards,
Mauro

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 73/78] media: s5p-mfc: use pm_runtime_resume_and_get()
  2021-04-24  6:45 ` [PATCH 73/78] media: s5p-mfc: " Mauro Carvalho Chehab
@ 2021-04-27  9:36   ` Sylwester Nawrocki
  0 siblings, 0 replies; 33+ messages in thread
From: Sylwester Nawrocki @ 2021-04-27  9:36 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Andrzej Hajda, Mauro Carvalho Chehab,
	linux-arm-kernel, linux-kernel, linux-media

On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:
> 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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

Thank you for the patch.

Reviewed-by: Sylwester Nawrocki <s.nawrocki@samsung.com>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-27  9:30     ` Mauro Carvalho Chehab
@ 2021-04-27  9:42       ` Mauro Carvalho Chehab
  2021-04-27 11:50         ` Sylwester Nawrocki
  0 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-27  9:42 UTC (permalink / raw)
  To: Sylwester Nawrocki
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

Em Tue, 27 Apr 2021 11:30:55 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:

> Em Tue, 27 Apr 2021 10:18:12 +0200
> Sylwester Nawrocki <s.nawrocki@samsung.com> escreveu:
> 
> > On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:  
> > > 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.
> > > 
> > > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> > > ---
> > >  drivers/media/platform/exynos-gsc/gsc-core.c | 3 +--
> > >  drivers/media/platform/exynos-gsc/gsc-m2m.c  | 2 +-
> > >  2 files changed, 2 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
> > > index 9f41c2e7097a..9d5841194f6b 100644
> > > --- a/drivers/media/platform/exynos-gsc/gsc-core.c
> > > +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
> > > @@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)
> > >  	struct gsc_dev *gsc = platform_get_drvdata(pdev);
> > >  	int i;
> > >  
> > > -	pm_runtime_get_sync(&pdev->dev);
> > > +	pm_runtime_resume_and_get(&pdev->dev);
> > >  
> > >  	gsc_unregister_m2m_device(gsc);
> > >  	v4l2_device_unregister(&gsc->v4l2_dev);
> > > @@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)
> > >  	for (i = 0; i < gsc->num_clocks; i++)
> > >  		clk_disable_unprepare(gsc->clock[i]);
> > >  
> > > -	pm_runtime_put_noidle(&pdev->dev);    
> > 
> > If we do this then the device usage count will not get decremented
> > after the pm_runtime_resume_and_get() call above and after driver
> > unload/load cycle it will not be possible to suspend the device.
> > I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync()
> > works better in that case.  
> 
> Good point.
> 
> Actually, I don't see any reason why to call a PM resume
> function - either being pm_runtime_get_sync() or
> pm_runtime_resume_and_get().
> 
> The code there could simply be:
> 
>     static int gsc_remove(struct platform_device *pdev)
>     {
>         struct gsc_dev *gsc = platform_get_drvdata(pdev);
>         int i;
> 
>         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_disable(&pdev->dev);
> 
>         dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
>         return 0;
>     }
> 
> Eventually also adding:
> 	pm_runtime_suspended(&pdev->dev);

In time: I actually meant:

	pm_runtime_set_suspended(&pdev->dev);

but after double-checking the PM runtime code, it sounds to me that
just calling pm_runtime_disable() would be enough. Not 100% sure
here. Btw, some media drivers call it after pm_runtime_disable(),
while others don't do.

Thanks,
Mauro

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-27  9:42       ` Mauro Carvalho Chehab
@ 2021-04-27 11:50         ` Sylwester Nawrocki
  2021-04-28  7:13           ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 33+ messages in thread
From: Sylwester Nawrocki @ 2021-04-27 11:50 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

On 27.04.2021 11:42, Mauro Carvalho Chehab wrote:
> Em Tue, 27 Apr 2021 11:30:55 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:
> 
>> Em Tue, 27 Apr 2021 10:18:12 +0200
>> Sylwester Nawrocki <s.nawrocki@samsung.com> escreveu:
>>
>>> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:  
>>>> 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.
>>>>
>>>> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
>>>> ---
>>>>  drivers/media/platform/exynos-gsc/gsc-core.c | 3 +--
>>>>  drivers/media/platform/exynos-gsc/gsc-m2m.c  | 2 +-
>>>>  2 files changed, 2 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
>>>> index 9f41c2e7097a..9d5841194f6b 100644
>>>> --- a/drivers/media/platform/exynos-gsc/gsc-core.c
>>>> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
>>>> @@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)
>>>>  	struct gsc_dev *gsc = platform_get_drvdata(pdev);
>>>>  	int i;
>>>>  
>>>> -	pm_runtime_get_sync(&pdev->dev);
>>>> +	pm_runtime_resume_and_get(&pdev->dev);
>>>>  
>>>>  	gsc_unregister_m2m_device(gsc);
>>>>  	v4l2_device_unregister(&gsc->v4l2_dev);
>>>> @@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)
>>>>  	for (i = 0; i < gsc->num_clocks; i++)
>>>>  		clk_disable_unprepare(gsc->clock[i]);
>>>>  
>>>> -	pm_runtime_put_noidle(&pdev->dev);    
>>>
>>> If we do this then the device usage count will not get decremented
>>> after the pm_runtime_resume_and_get() call above and after driver
>>> unload/load cycle it will not be possible to suspend the device.
>>> I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync()
>>> works better in that case.  
>>
>> Good point.
>>
>> Actually, I don't see any reason why to call a PM resume
>> function - either being pm_runtime_get_sync() or
>> pm_runtime_resume_and_get().
>>
>> The code there could simply be:
>>
>>     static int gsc_remove(struct platform_device *pdev)
>>     {
>>         struct gsc_dev *gsc = platform_get_drvdata(pdev);
>>         int i;
>>
>>         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_disable(&pdev->dev);
>>
>>         dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
>>         return 0;
>>     }
>>
>> Eventually also adding:
>> 	pm_runtime_suspended(&pdev->dev);
> 
> In time: I actually meant:
> 
> 	pm_runtime_set_suspended(&pdev->dev);
> 
> but after double-checking the PM runtime code, it sounds to me that
> just calling pm_runtime_disable() would be enough. Not 100% sure
> here. Btw, some media drivers call it after pm_runtime_disable(),
> while others don't do.

I think if the device is brought into suspended state (e.g. by
disabling clocks as above) the pm_runtime_set_suspended() call
should be there. IOW a following sequence: 

	pm_runtime_disable(dev);
	if (!pm_runtime_status_suspended(dev))
		/* put device into suspended state (disable clocks, 
		  voltage regulators, assert GPIOs, etc. */
	pm_runtime_set_suspended(dev);

--
Regards,
Sylwester

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-27 11:50         ` Sylwester Nawrocki
@ 2021-04-28  7:13           ` Mauro Carvalho Chehab
  2021-04-28  7:17             ` Mauro Carvalho Chehab
  0 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28  7:13 UTC (permalink / raw)
  To: Sylwester Nawrocki
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, Mauro Carvalho Chehab, linux-arm-kernel,
	linux-kernel, linux-media, linux-samsung-soc

Em Tue, 27 Apr 2021 13:50:44 +0200
Sylwester Nawrocki <s.nawrocki@samsung.com> escreveu:

> On 27.04.2021 11:42, Mauro Carvalho Chehab wrote:
> > Em Tue, 27 Apr 2021 11:30:55 +0200
> > Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:
> >   
> >> Em Tue, 27 Apr 2021 10:18:12 +0200
> >> Sylwester Nawrocki <s.nawrocki@samsung.com> escreveu:
> >>  
> >>> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:    
> >>>> 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.
> >>>>
> >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> >>>> ---
> >>>>  drivers/media/platform/exynos-gsc/gsc-core.c | 3 +--
> >>>>  drivers/media/platform/exynos-gsc/gsc-m2m.c  | 2 +-
> >>>>  2 files changed, 2 insertions(+), 3 deletions(-)
> >>>>
> >>>> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
> >>>> index 9f41c2e7097a..9d5841194f6b 100644
> >>>> --- a/drivers/media/platform/exynos-gsc/gsc-core.c
> >>>> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
> >>>> @@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)
> >>>>  	struct gsc_dev *gsc = platform_get_drvdata(pdev);
> >>>>  	int i;
> >>>>  
> >>>> -	pm_runtime_get_sync(&pdev->dev);
> >>>> +	pm_runtime_resume_and_get(&pdev->dev);
> >>>>  
> >>>>  	gsc_unregister_m2m_device(gsc);
> >>>>  	v4l2_device_unregister(&gsc->v4l2_dev);
> >>>> @@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)
> >>>>  	for (i = 0; i < gsc->num_clocks; i++)
> >>>>  		clk_disable_unprepare(gsc->clock[i]);
> >>>>  
> >>>> -	pm_runtime_put_noidle(&pdev->dev);      
> >>>
> >>> If we do this then the device usage count will not get decremented
> >>> after the pm_runtime_resume_and_get() call above and after driver
> >>> unload/load cycle it will not be possible to suspend the device.
> >>> I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync()
> >>> works better in that case.    
> >>
> >> Good point.
> >>
> >> Actually, I don't see any reason why to call a PM resume
> >> function - either being pm_runtime_get_sync() or
> >> pm_runtime_resume_and_get().
> >>
> >> The code there could simply be:
> >>
> >>     static int gsc_remove(struct platform_device *pdev)
> >>     {
> >>         struct gsc_dev *gsc = platform_get_drvdata(pdev);
> >>         int i;
> >>
> >>         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_disable(&pdev->dev);
> >>
> >>         dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
> >>         return 0;
> >>     }
> >>
> >> Eventually also adding:
> >> 	pm_runtime_suspended(&pdev->dev);  
> > 
> > In time: I actually meant:
> > 
> > 	pm_runtime_set_suspended(&pdev->dev);
> > 
> > but after double-checking the PM runtime code, it sounds to me that
> > just calling pm_runtime_disable() would be enough. Not 100% sure
> > here. Btw, some media drivers call it after pm_runtime_disable(),
> > while others don't do.  
> 
> I think if the device is brought into suspended state (e.g. by
> disabling clocks as above) the pm_runtime_set_suspended() call
> should be there. IOW a following sequence: 
> 
> 	pm_runtime_disable(dev);
> 	if (!pm_runtime_status_suspended(dev))
> 		/* put device into suspended state (disable clocks, 
> 		  voltage regulators, assert GPIOs, etc. */
> 	pm_runtime_set_suspended(dev);

Not sure if this would work, as the clock framework would try
to do things like calling clk_pm_runtime_put().

Perhaps an alternative would be to just return an error if it
can't resume PM runtime, e. g.:

diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
index 9f41c2e7097a..d47d02c75484 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.c
+++ b/drivers/media/platform/exynos-gsc/gsc-core.c
@@ -1208,9 +1208,11 @@ static int gsc_probe(struct platform_device *pdev)
 static int gsc_remove(struct platform_device *pdev)
 {
        struct gsc_dev *gsc = platform_get_drvdata(pdev);
-       int i;
+       int ret, i;
 
-       pm_runtime_get_sync(&pdev->dev);
+       ret = pm_runtime_resume_and_get(&pdev->dev);
+       if (ret < 0)
+               return ret;
 
        gsc_unregister_m2m_device(gsc);
        v4l2_device_unregister(&gsc->v4l2_dev);


Thanks,
Mauro

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-28  7:13           ` Mauro Carvalho Chehab
@ 2021-04-28  7:17             ` Mauro Carvalho Chehab
  2021-04-28  8:27               ` Sylwester Nawrocki
  0 siblings, 1 reply; 33+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28  7:17 UTC (permalink / raw)
  To: Sylwester Nawrocki
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, linux-arm-kernel, linux-kernel, linux-media,
	linux-samsung-soc

Em Wed, 28 Apr 2021 09:13:02 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:

> Em Tue, 27 Apr 2021 13:50:44 +0200
> Sylwester Nawrocki <s.nawrocki@samsung.com> escreveu:
> 
> > On 27.04.2021 11:42, Mauro Carvalho Chehab wrote:  
> > > Em Tue, 27 Apr 2021 11:30:55 +0200
> > > Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:
> > >     
> > >> Em Tue, 27 Apr 2021 10:18:12 +0200
> > >> Sylwester Nawrocki <s.nawrocki@samsung.com> escreveu:
> > >>    
> > >>> On 24.04.2021 08:45, Mauro Carvalho Chehab wrote:      
> > >>>> 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.
> > >>>>
> > >>>> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> > >>>> ---
> > >>>>  drivers/media/platform/exynos-gsc/gsc-core.c | 3 +--
> > >>>>  drivers/media/platform/exynos-gsc/gsc-m2m.c  | 2 +-
> > >>>>  2 files changed, 2 insertions(+), 3 deletions(-)
> > >>>>
> > >>>> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
> > >>>> index 9f41c2e7097a..9d5841194f6b 100644
> > >>>> --- a/drivers/media/platform/exynos-gsc/gsc-core.c
> > >>>> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
> > >>>> @@ -1210,7 +1210,7 @@ static int gsc_remove(struct platform_device *pdev)
> > >>>>  	struct gsc_dev *gsc = platform_get_drvdata(pdev);
> > >>>>  	int i;
> > >>>>  
> > >>>> -	pm_runtime_get_sync(&pdev->dev);
> > >>>> +	pm_runtime_resume_and_get(&pdev->dev);
> > >>>>  
> > >>>>  	gsc_unregister_m2m_device(gsc);
> > >>>>  	v4l2_device_unregister(&gsc->v4l2_dev);
> > >>>> @@ -1219,7 +1219,6 @@ static int gsc_remove(struct platform_device *pdev)
> > >>>>  	for (i = 0; i < gsc->num_clocks; i++)
> > >>>>  		clk_disable_unprepare(gsc->clock[i]);
> > >>>>  
> > >>>> -	pm_runtime_put_noidle(&pdev->dev);        
> > >>>
> > >>> If we do this then the device usage count will not get decremented
> > >>> after the pm_runtime_resume_and_get() call above and after driver
> > >>> unload/load cycle it will not be possible to suspend the device.
> > >>> I wouldn't be changing anything in gsc_remove(), pm_runtime_get_sync()
> > >>> works better in that case.      
> > >>
> > >> Good point.
> > >>
> > >> Actually, I don't see any reason why to call a PM resume
> > >> function - either being pm_runtime_get_sync() or
> > >> pm_runtime_resume_and_get().
> > >>
> > >> The code there could simply be:
> > >>
> > >>     static int gsc_remove(struct platform_device *pdev)
> > >>     {
> > >>         struct gsc_dev *gsc = platform_get_drvdata(pdev);
> > >>         int i;
> > >>
> > >>         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_disable(&pdev->dev);
> > >>
> > >>         dev_dbg(&pdev->dev, "%s driver unloaded\n", pdev->name);
> > >>         return 0;
> > >>     }
> > >>
> > >> Eventually also adding:
> > >> 	pm_runtime_suspended(&pdev->dev);    
> > > 
> > > In time: I actually meant:
> > > 
> > > 	pm_runtime_set_suspended(&pdev->dev);
> > > 
> > > but after double-checking the PM runtime code, it sounds to me that
> > > just calling pm_runtime_disable() would be enough. Not 100% sure
> > > here. Btw, some media drivers call it after pm_runtime_disable(),
> > > while others don't do.    
> > 
> > I think if the device is brought into suspended state (e.g. by
> > disabling clocks as above) the pm_runtime_set_suspended() call
> > should be there. IOW a following sequence: 
> > 
> > 	pm_runtime_disable(dev);
> > 	if (!pm_runtime_status_suspended(dev))
> > 		/* put device into suspended state (disable clocks, 
> > 		  voltage regulators, assert GPIOs, etc. */
> > 	pm_runtime_set_suspended(dev);  
> 
> Not sure if this would work, as the clock framework would try
> to do things like calling clk_pm_runtime_put().
> 
> Perhaps an alternative would be to just return an error if it
> can't resume PM runtime, e. g.:
> 
> diff --git a/drivers/media/platform/exynos-gsc/gsc-core.c b/drivers/media/platform/exynos-gsc/gsc-core.c
> index 9f41c2e7097a..d47d02c75484 100644
> --- a/drivers/media/platform/exynos-gsc/gsc-core.c
> +++ b/drivers/media/platform/exynos-gsc/gsc-core.c
> @@ -1208,9 +1208,11 @@ static int gsc_probe(struct platform_device *pdev)
>  static int gsc_remove(struct platform_device *pdev)
>  {
>         struct gsc_dev *gsc = platform_get_drvdata(pdev);
> -       int i;
> +       int ret, i;
>  
> -       pm_runtime_get_sync(&pdev->dev);
> +       ret = pm_runtime_resume_and_get(&pdev->dev);
> +       if (ret < 0)
> +               return ret;

Nah, forget about that. Despite the platform driver having a return code,
support for it bogus:


static int platform_remove(struct device *_dev)
{
        struct platform_driver *drv = to_platform_driver(_dev->driver);
        struct platform_device *dev = to_platform_device(_dev);

        if (drv->remove) {
                int ret = drv->remove(dev);

                if (ret)
                        dev_warn(_dev, "remove callback returned a non-zero value. This will be ignored.\n");
        }
        dev_pm_domain_detach(_dev, true);

        return 0;
}

Thanks,
Mauro

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 58/78] media: exynos-gsc: use pm_runtime_resume_and_get()
  2021-04-28  7:17             ` Mauro Carvalho Chehab
@ 2021-04-28  8:27               ` Sylwester Nawrocki
  0 siblings, 0 replies; 33+ messages in thread
From: Sylwester Nawrocki @ 2021-04-28  8:27 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Hans Verkuil,
	Krzysztof Kozlowski, linux-arm-kernel, linux-kernel, linux-media,
	linux-samsung-soc, Sylwester Nawrocki

On 28.04.2021 09:17, Mauro Carvalho Chehab wrote:
> Em Wed, 28 Apr 2021 09:13:02 +0200
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> escreveu:
> 
>> Em Tue, 27 Apr 2021 13:50:44 +0200
>> Sylwester Nawrocki <s.nawrocki@samsung.com> escreveu:
>>
>>> On 27.04.2021 11:42, Mauro Carvalho Chehab wrote:

>>> I think if the device is brought into suspended state (e.g. by
>>> disabling clocks as above) the pm_runtime_set_suspended() call
>>> should be there. IOW a following sequence:
>>>
>>> 	pm_runtime_disable(dev);
>>> 	if (!pm_runtime_status_suspended(dev))
>>> 		/* put device into suspended state (disable clocks,
>>> 		  voltage regulators, assert GPIOs, etc. */
>>> 	pm_runtime_set_suspended(dev);
>>
>> Not sure if this would work, as the clock framework would try
>> to do things like calling clk_pm_runtime_put().

It's done in multiple drivers this way. clk_pm_runtime_put() operates
on different device - the clock supplier, not the consumer device.
We just need to disable runtime PM for GSC as the last step, to avoid
any possible v4l2 m2m device_run() call with runtime PM disabled.

>> Perhaps an alternative would be to just return an error if it
>> can't resume PM runtime, e. g.:
[...]
> Nah, forget about that. Despite the platform driver having a return code,
> support for it bogus:

Yes, we can't really stop remove() from driver level so as much complete
resource release is being done as possible.


Regards,
Sylwester

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 70/78] media: rga-buf: use pm_runtime_resume_and_get()
  2021-04-24  6:45 ` [PATCH 70/78] media: rga-buf: " Mauro Carvalho Chehab
@ 2021-04-28 17:09   ` Ezequiel Garcia
  0 siblings, 0 replies; 33+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:09 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: linuxarm, mauro.chehab, Heiko Stuebner, Jacob Chen,
	Mauro Carvalho Chehab, linux-arm-kernel, linux-kernel,
	linux-media, linux-rockchip

On Sat, 2021-04-24 at 08:45 +0200, Mauro Carvalho Chehab wrote:
> 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.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>


Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>

Thanks,

> ---
>  drivers/media/platform/rockchip/rga/rga-buf.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rga/rga-buf.c b/drivers/media/platform/rockchip/rga/rga-buf.c
> index bf9a75b75083..81508ed5abf3 100644
> --- a/drivers/media/platform/rockchip/rga/rga-buf.c
> +++ b/drivers/media/platform/rockchip/rga/rga-buf.c
> @@ -79,9 +79,8 @@ static int rga_buf_start_streaming(struct vb2_queue *q, unsigned int count)
>         struct rockchip_rga *rga = ctx->rga;
>         int ret;
>  
> -       ret = pm_runtime_get_sync(rga->dev);
> +       ret = pm_runtime_resume_and_get(rga->dev);
>         if (ret < 0) {
> -               pm_runtime_put_noidle(rga->dev);
>                 rga_buf_return_buffers(q, VB2_BUF_STATE_QUEUED);
>                 return ret;
>         }



_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2021-04-28 17:11 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <cover.1619191723.git.mchehab+huawei@kernel.org>
2021-04-24  6:44 ` [PATCH 01/78] media: atmel: properly get pm_runtime Mauro Carvalho Chehab
2021-04-24  9:36   ` kernel test robot
2021-04-24  6:44 ` [PATCH 03/78] media: mdk-mdp: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
2021-04-24  6:44 ` [PATCH 05/78] " Mauro Carvalho Chehab
2021-04-24 18:23   ` Ezequiel Garcia
2021-04-24  6:44 ` [PATCH 14/78] staging: media: imx7-mipi-csis: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
2021-04-26 10:11   ` Rui Miguel Silva
2021-04-24  6:44 ` [PATCH 16/78] staging: media: cedrus_video: " Mauro Carvalho Chehab
2021-04-24  6:44 ` [PATCH 20/78] media: mtk-vcodec: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
2021-04-24  6:44 ` [PATCH 21/78] media: s5p-jpeg: " Mauro Carvalho Chehab
2021-04-27  9:14   ` Sylwester Nawrocki
2021-04-24  6:44 ` [PATCH 23/78] media: sun8i_rotate: " Mauro Carvalho Chehab
2021-04-24  6:45 ` [PATCH 57/78] media: exynos4-is: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
2021-04-25 20:57   ` Sylwester Nawrocki
2021-04-26 13:12     ` Mauro Carvalho Chehab
2021-04-27  8:06       ` Sylwester Nawrocki
2021-04-24  6:45 ` [PATCH 58/78] media: exynos-gsc: " Mauro Carvalho Chehab
2021-04-27  8:18   ` Sylwester Nawrocki
2021-04-27  9:30     ` Mauro Carvalho Chehab
2021-04-27  9:42       ` Mauro Carvalho Chehab
2021-04-27 11:50         ` Sylwester Nawrocki
2021-04-28  7:13           ` Mauro Carvalho Chehab
2021-04-28  7:17             ` Mauro Carvalho Chehab
2021-04-28  8:27               ` Sylwester Nawrocki
2021-04-24  6:45 ` [PATCH 59/78] media: mtk-jpeg: " Mauro Carvalho Chehab
2021-04-24  6:45 ` [PATCH 70/78] media: rga-buf: " Mauro Carvalho Chehab
2021-04-28 17:09   ` Ezequiel Garcia
2021-04-24  6:45 ` [PATCH 71/78] media: rkisp1-capture: " Mauro Carvalho Chehab
2021-04-24  6:45 ` [PATCH 73/78] media: s5p-mfc: " Mauro Carvalho Chehab
2021-04-27  9:36   ` Sylwester Nawrocki
2021-04-24  6:45 ` [PATCH 75/78] media: stm32: " Mauro Carvalho Chehab
2021-04-24  6:45 ` [PATCH 76/78] media: sun4i_v4l2: " Mauro Carvalho Chehab
2021-04-24 10:21   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).