* [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
[not found] <cover.1619621413.git.mchehab+huawei@kernel.org>
@ 2021-04-28 14:51 ` Mauro Carvalho Chehab
2021-04-28 15:09 ` Johan Hovold
2021-04-28 14:52 ` [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
` (3 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:51 UTC (permalink / raw)
Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
Greg Kroah-Hartman, Mauro Carvalho Chehab, devel, 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.
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
drivers/staging/media/rkvdec/rkvdec.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
index d821661d30f3..8c17615f3a7a 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
if (WARN_ON(!desc))
return;
- ret = pm_runtime_get_sync(rkvdec->dev);
+ ret = pm_runtime_resume_and_get(rkvdec->dev);
if (ret < 0) {
rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
return;
--
2.30.2
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get()
[not found] <cover.1619621413.git.mchehab+huawei@kernel.org>
2021-04-28 14:51 ` [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
2021-04-28 17:11 ` Ezequiel Garcia
2021-04-28 14:52 ` [PATCH v4 70/79] media: rkisp1: " Mauro Carvalho Chehab
` (2 subsequent siblings)
4 siblings, 1 reply; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 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 +--
drivers/media/platform/rockchip/rga/rga.c | 4 +++-
2 files changed, 4 insertions(+), 3 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;
}
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-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 70/79] media: rkisp1: use pm_runtime_resume_and_get()
[not found] <cover.1619621413.git.mchehab+huawei@kernel.org>
2021-04-28 14:51 ` [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 78/79] media: hantro: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 79/79] media: hantro: do a PM resume earlier Mauro Carvalho Chehab
4 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 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-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
[not found] <cover.1619621413.git.mchehab+huawei@kernel.org>
` (2 preceding siblings ...)
2021-04-28 14:52 ` [PATCH v4 70/79] media: rkisp1: " Mauro Carvalho Chehab
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
2021-04-28 17:14 ` Ezequiel Garcia
2021-04-30 18:09 ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 79/79] media: hantro: do a PM resume earlier Mauro Carvalho Chehab
4 siblings, 2 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
Greg Kroah-Hartman, Mauro Carvalho Chehab, Philipp Zabel, devel,
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.
While there's nothing wrong with the current usage on this driver,
as we're getting rid of the pm_runtime_get_sync() call all over
the media subsystem, let's remove the last occurrence on this
driver.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 595e82a82728..25fa36e7e773 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
return hantro_get_dec_buf_addr(ctx, buf);
}
-static void hantro_job_finish(struct hantro_dev *vpu,
- struct hantro_ctx *ctx,
- enum vb2_buffer_state result)
+static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
+ struct hantro_ctx *ctx,
+ enum vb2_buffer_state result)
{
struct vb2_v4l2_buffer *src, *dst;
- pm_runtime_mark_last_busy(vpu->dev);
- pm_runtime_put_autosuspend(vpu->dev);
clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
@@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
result);
}
+static void hantro_job_finish(struct hantro_dev *vpu,
+ struct hantro_ctx *ctx,
+ enum vb2_buffer_state result)
+{
+ pm_runtime_mark_last_busy(vpu->dev);
+ pm_runtime_put_autosuspend(vpu->dev);
+
+ hantro_job_finish_no_pm(vpu, ctx, result);
+}
+
void hantro_irq_done(struct hantro_dev *vpu,
enum vb2_buffer_state result)
{
@@ -155,7 +163,8 @@ static void device_run(void *priv)
ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
if (ret)
goto err_cancel_job;
- ret = pm_runtime_get_sync(ctx->dev->dev);
+
+ ret = pm_runtime_resume_and_get(ctx->dev->dev);
if (ret < 0)
goto err_cancel_job;
@@ -165,7 +174,7 @@ static void device_run(void *priv)
return;
err_cancel_job:
- hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
+ hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
}
static struct v4l2_m2m_ops vpu_m2m_ops = {
--
2.30.2
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH v4 79/79] media: hantro: do a PM resume earlier
[not found] <cover.1619621413.git.mchehab+huawei@kernel.org>
` (3 preceding siblings ...)
2021-04-28 14:52 ` [PATCH v4 78/79] media: hantro: " Mauro Carvalho Chehab
@ 2021-04-28 14:52 ` Mauro Carvalho Chehab
2021-04-28 17:17 ` Ezequiel Garcia
4 siblings, 1 reply; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-28 14:52 UTC (permalink / raw)
Cc: linuxarm, mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia,
Greg Kroah-Hartman, Mauro Carvalho Chehab, Philipp Zabel, devel,
linux-kernel, linux-media, linux-rockchip
The device_run() first enables the clock and then
tries to resume PM runtime, checking for errors.
Well, if for some reason the pm_runtime can not resume,
it would be better to detect it beforehand.
So, change the order inside device_run().
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
index 25fa36e7e773..67de6b15236d 100644
--- a/drivers/staging/media/hantro/hantro_drv.c
+++ b/drivers/staging/media/hantro/hantro_drv.c
@@ -160,14 +160,14 @@ static void device_run(void *priv)
src = hantro_get_src_buf(ctx);
dst = hantro_get_dst_buf(ctx);
- ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
- if (ret)
- goto err_cancel_job;
-
ret = pm_runtime_resume_and_get(ctx->dev->dev);
if (ret < 0)
goto err_cancel_job;
+ ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
+ if (ret)
+ goto err_cancel_job;
+
v4l2_m2m_buf_copy_metadata(src, dst, true);
ctx->codec_ops->run(ctx);
--
2.30.2
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
2021-04-28 14:51 ` [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
@ 2021-04-28 15:09 ` Johan Hovold
2021-04-29 7:38 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 12+ messages in thread
From: Johan Hovold @ 2021-04-28 15:09 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel, linux-rockchip,
mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia, linux-media
On Wed, Apr 28, 2021 at 04:51:41PM +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.
Again, there is no memory leak here either. Just a potential PM usage
counter leak.
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
> drivers/staging/media/rkvdec/rkvdec.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> index d821661d30f3..8c17615f3a7a 100644
> --- a/drivers/staging/media/rkvdec/rkvdec.c
> +++ b/drivers/staging/media/rkvdec/rkvdec.c
> @@ -658,7 +658,7 @@ static void rkvdec_device_run(void *priv)
> if (WARN_ON(!desc))
> return;
>
> - ret = pm_runtime_get_sync(rkvdec->dev);
> + ret = pm_runtime_resume_and_get(rkvdec->dev);
> if (ret < 0) {
> rkvdec_job_finish_no_pm(ctx, VB2_BUF_STATE_ERROR);
> return;
Johan
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get()
2021-04-28 14:52 ` [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
@ 2021-04-28 17:11 ` Ezequiel Garcia
0 siblings, 0 replies; 12+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:11 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 Wed, 2021-04-28 at 16:52 +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>
Ugh, sigh... OK, there was a v4. Sorry for the noise!
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
> ---
> drivers/media/platform/rockchip/rga/rga-buf.c | 3 +--
> drivers/media/platform/rockchip/rga/rga.c | 4 +++-
> 2 files changed, 4 insertions(+), 3 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;
> }
> 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;
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
2021-04-28 14:52 ` [PATCH v4 78/79] media: hantro: " Mauro Carvalho Chehab
@ 2021-04-28 17:14 ` Ezequiel Garcia
2021-04-30 18:09 ` Jonathan Cameron
1 sibling, 0 replies; 12+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:14 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman, Mauro Carvalho Chehab,
Philipp Zabel, devel, linux-kernel, linux-media, linux-rockchip
On Wed, 2021-04-28 at 16:52 +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.
>
> While there's nothing wrong with the current usage on this driver,
> as we're getting rid of the pm_runtime_get_sync() call all over
> the media subsystem, let's remove the last occurrence on this
> driver.
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Looks good.
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Thanks,
Ezequiel
> ---
> drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
> 1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 595e82a82728..25fa36e7e773 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
> return hantro_get_dec_buf_addr(ctx, buf);
> }
>
> -static void hantro_job_finish(struct hantro_dev *vpu,
> - struct hantro_ctx *ctx,
> - enum vb2_buffer_state result)
> +static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
> + struct hantro_ctx *ctx,
> + enum vb2_buffer_state result)
> {
> struct vb2_v4l2_buffer *src, *dst;
>
> - pm_runtime_mark_last_busy(vpu->dev);
> - pm_runtime_put_autosuspend(vpu->dev);
> clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>
> src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
> result);
> }
>
> +static void hantro_job_finish(struct hantro_dev *vpu,
> + struct hantro_ctx *ctx,
> + enum vb2_buffer_state result)
> +{
> + pm_runtime_mark_last_busy(vpu->dev);
> + pm_runtime_put_autosuspend(vpu->dev);
> +
> + hantro_job_finish_no_pm(vpu, ctx, result);
> +}
> +
> void hantro_irq_done(struct hantro_dev *vpu,
> enum vb2_buffer_state result)
> {
> @@ -155,7 +163,8 @@ static void device_run(void *priv)
> ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> if (ret)
> goto err_cancel_job;
> - ret = pm_runtime_get_sync(ctx->dev->dev);
> +
> + ret = pm_runtime_resume_and_get(ctx->dev->dev);
> if (ret < 0)
> goto err_cancel_job;
>
> @@ -165,7 +174,7 @@ static void device_run(void *priv)
> return;
>
> err_cancel_job:
> - hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> + hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> }
>
> static struct v4l2_m2m_ops vpu_m2m_ops = {
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 79/79] media: hantro: do a PM resume earlier
2021-04-28 14:52 ` [PATCH v4 79/79] media: hantro: do a PM resume earlier Mauro Carvalho Chehab
@ 2021-04-28 17:17 ` Ezequiel Garcia
2021-04-29 7:13 ` Mauro Carvalho Chehab
0 siblings, 1 reply; 12+ messages in thread
From: Ezequiel Garcia @ 2021-04-28 17:17 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman, Mauro Carvalho Chehab,
Philipp Zabel, devel, linux-kernel, linux-media, linux-rockchip
Hi Mauro,
Thanks a lot for taking care of this.
On Wed, 2021-04-28 at 16:52 +0200, Mauro Carvalho Chehab wrote:
> The device_run() first enables the clock and then
> tries to resume PM runtime, checking for errors.
>
> Well, if for some reason the pm_runtime can not resume,
> it would be better to detect it beforehand.
>
> So, change the order inside device_run().
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Clocks could be behind power-domains, IIRC, so this change
is fixing that.
However, this has ever been a problem for this driver,
so I don't think it makes sense to bother with Fixes tag.
Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
Thanks,
Ezequiel
> ---
> drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 25fa36e7e773..67de6b15236d 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -160,14 +160,14 @@ static void device_run(void *priv)
> src = hantro_get_src_buf(ctx);
> dst = hantro_get_dst_buf(ctx);
>
> - ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> - if (ret)
> - goto err_cancel_job;
> -
> ret = pm_runtime_resume_and_get(ctx->dev->dev);
> if (ret < 0)
> goto err_cancel_job;
>
> + ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> + if (ret)
> + goto err_cancel_job;
> +
> v4l2_m2m_buf_copy_metadata(src, dst, true);
>
> ctx->codec_ops->run(ctx);
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 79/79] media: hantro: do a PM resume earlier
2021-04-28 17:17 ` Ezequiel Garcia
@ 2021-04-29 7:13 ` Mauro Carvalho Chehab
0 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29 7:13 UTC (permalink / raw)
To: Ezequiel Garcia
Cc: linuxarm, mauro.chehab, Greg Kroah-Hartman, Mauro Carvalho Chehab,
Philipp Zabel, devel, linux-kernel, linux-media, linux-rockchip
Em Wed, 28 Apr 2021 14:17:50 -0300
Ezequiel Garcia <ezequiel@collabora.com> escreveu:
> Hi Mauro,
>
> Thanks a lot for taking care of this.
>
> On Wed, 2021-04-28 at 16:52 +0200, Mauro Carvalho Chehab wrote:
> > The device_run() first enables the clock and then
> > tries to resume PM runtime, checking for errors.
> >
> > Well, if for some reason the pm_runtime can not resume,
> > it would be better to detect it beforehand.
> >
> > So, change the order inside device_run().
> >
> > Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
>
> Clocks could be behind power-domains, IIRC, so this change
> is fixing that.
>
> However, this has ever been a problem for this driver,
> so I don't think it makes sense to bother with Fixes tag.
I would prefer to move this patch to the first part of this
series, together with other fixes, rebasing it to apply cleanly
before the pm_runtime_resume_and_get() patch, with:
Fixes: 775fec69008d ("media: add Rockchip VPU JPEG encoder driver")
This way, people that could be interested on backporting it will be
capable to apply it as is to stable Kernel releases that came
with this driver.
>
> Reviewed-by: Ezequiel Garcia <ezequiel@collabora.com>
>
> Thanks,
> Ezequiel
>
> > ---
> > drivers/staging/media/hantro/hantro_drv.c | 8 ++++----
> > 1 file changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> > index 25fa36e7e773..67de6b15236d 100644
> > --- a/drivers/staging/media/hantro/hantro_drv.c
> > +++ b/drivers/staging/media/hantro/hantro_drv.c
> > @@ -160,14 +160,14 @@ static void device_run(void *priv)
> > src = hantro_get_src_buf(ctx);
> > dst = hantro_get_dst_buf(ctx);
> >
> > - ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> > - if (ret)
> > - goto err_cancel_job;
> > -
> > ret = pm_runtime_resume_and_get(ctx->dev->dev);
> > if (ret < 0)
> > goto err_cancel_job;
> >
> > + ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> > + if (ret)
> > + goto err_cancel_job;
> > +
> > v4l2_m2m_buf_copy_metadata(src, dst, true);
> >
> > ctx->codec_ops->run(ctx);
>
>
Thanks,
Mauro
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count
2021-04-28 15:09 ` Johan Hovold
@ 2021-04-29 7:38 ` Mauro Carvalho Chehab
0 siblings, 0 replies; 12+ messages in thread
From: Mauro Carvalho Chehab @ 2021-04-29 7:38 UTC (permalink / raw)
To: Johan Hovold
Cc: devel, Greg Kroah-Hartman, linuxarm, linux-kernel, linux-rockchip,
mauro.chehab, Mauro Carvalho Chehab, Ezequiel Garcia, linux-media
Em Wed, 28 Apr 2021 17:09:57 +0200
Johan Hovold <johan@kernel.org> escreveu:
> On Wed, Apr 28, 2021 at 04:51:41PM +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.
>
> Again, there is no memory leak here either. Just a potential PM usage
> counter leak.
True. Will fix it at the entire series with:
FILTER_BRANCH_SQUELCH_WARNING=1 git filter-branch -f --msg-filter "cat|perl -0pe 's/ and avoid memory\n\s*leaks./, avoiding\na potential PM usage counter leak./igs'" BASE..
Regards,
Mauro
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 78/79] media: hantro: use pm_runtime_resume_and_get()
2021-04-28 14:52 ` [PATCH v4 78/79] media: hantro: " Mauro Carvalho Chehab
2021-04-28 17:14 ` Ezequiel Garcia
@ 2021-04-30 18:09 ` Jonathan Cameron
1 sibling, 0 replies; 12+ messages in thread
From: Jonathan Cameron @ 2021-04-30 18:09 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: linuxarm, mauro.chehab, Ezequiel Garcia, Greg Kroah-Hartman,
Mauro Carvalho Chehab, Philipp Zabel, devel, linux-kernel,
linux-media, linux-rockchip
On Wed, 28 Apr 2021 16:52:39 +0200
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> 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.
>
> While there's nothing wrong with the current usage on this driver,
> as we're getting rid of the pm_runtime_get_sync() call all over
> the media subsystem, let's remove the last occurrence on this
> driver.
Not sure there is nothing wrong in here before your patch...
>
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
> drivers/staging/media/hantro/hantro_drv.c | 23 ++++++++++++++++-------
> 1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/staging/media/hantro/hantro_drv.c b/drivers/staging/media/hantro/hantro_drv.c
> index 595e82a82728..25fa36e7e773 100644
> --- a/drivers/staging/media/hantro/hantro_drv.c
> +++ b/drivers/staging/media/hantro/hantro_drv.c
> @@ -56,14 +56,12 @@ dma_addr_t hantro_get_ref(struct hantro_ctx *ctx, u64 ts)
> return hantro_get_dec_buf_addr(ctx, buf);
> }
>
> -static void hantro_job_finish(struct hantro_dev *vpu,
> - struct hantro_ctx *ctx,
> - enum vb2_buffer_state result)
> +static void hantro_job_finish_no_pm(struct hantro_dev *vpu,
> + struct hantro_ctx *ctx,
> + enum vb2_buffer_state result)
> {
> struct vb2_v4l2_buffer *src, *dst;
>
> - pm_runtime_mark_last_busy(vpu->dev);
> - pm_runtime_put_autosuspend(vpu->dev);
> clk_bulk_disable(vpu->variant->num_clocks, vpu->clocks);
>
> src = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
> @@ -81,6 +79,16 @@ static void hantro_job_finish(struct hantro_dev *vpu,
> result);
> }
>
> +static void hantro_job_finish(struct hantro_dev *vpu,
> + struct hantro_ctx *ctx,
> + enum vb2_buffer_state result)
> +{
> + pm_runtime_mark_last_busy(vpu->dev);
> + pm_runtime_put_autosuspend(vpu->dev);
> +
> + hantro_job_finish_no_pm(vpu, ctx, result);
> +}
> +
> void hantro_irq_done(struct hantro_dev *vpu,
> enum vb2_buffer_state result)
> {
> @@ -155,7 +163,8 @@ static void device_run(void *priv)
> ret = clk_bulk_enable(ctx->dev->variant->num_clocks, ctx->dev->clocks);
> if (ret)
> goto err_cancel_job;
Before your patch, if this error condition happened, we'd call runtime_put
before the related runtime_get... You fixed that, but the patch description
doesn't call it out.
> - ret = pm_runtime_get_sync(ctx->dev->dev);
> +
> + ret = pm_runtime_resume_and_get(ctx->dev->dev);
> if (ret < 0)
> goto err_cancel_job;
>
> @@ -165,7 +174,7 @@ static void device_run(void *priv)
> return;
>
> err_cancel_job:
> - hantro_job_finish(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> + hantro_job_finish_no_pm(ctx->dev, ctx, VB2_BUF_STATE_ERROR);
> }
>
> static struct v4l2_m2m_ops vpu_m2m_ops = {
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-04-30 18:10 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <cover.1619621413.git.mchehab+huawei@kernel.org>
2021-04-28 14:51 ` [PATCH v4 20/79] staging: media: rkvdec: fix pm_runtime_get_sync() usage count Mauro Carvalho Chehab
2021-04-28 15:09 ` Johan Hovold
2021-04-29 7:38 ` Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 57/79] media: rockchip/rga: use pm_runtime_resume_and_get() Mauro Carvalho Chehab
2021-04-28 17:11 ` Ezequiel Garcia
2021-04-28 14:52 ` [PATCH v4 70/79] media: rkisp1: " Mauro Carvalho Chehab
2021-04-28 14:52 ` [PATCH v4 78/79] media: hantro: " Mauro Carvalho Chehab
2021-04-28 17:14 ` Ezequiel Garcia
2021-04-30 18:09 ` Jonathan Cameron
2021-04-28 14:52 ` [PATCH v4 79/79] media: hantro: do a PM resume earlier Mauro Carvalho Chehab
2021-04-28 17:17 ` Ezequiel Garcia
2021-04-29 7:13 ` Mauro Carvalho Chehab
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).