mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: chips-media: wave5: Check decoder qbuf runtime resume
@ 2026-07-05 14:57 Guangshuo Li
  2026-07-16  1:50 ` Nicolas Dufresne
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2026-07-05 14:57 UTC (permalink / raw)
  To: Nas Chung, Jackson Lee, Mauro Carvalho Chehab, Nicolas Dufresne,
	Hans Verkuil, linux-media, linux-kernel
  Cc: Guangshuo Li

wave5_vpu_dec_buf_queue_dst() resumes the VPU before it may clear a
decoder display flag. This is needed because clearing the display flag
accesses VPU registers.

However, the return value from pm_runtime_resume_and_get() is ignored.
If the resume fails, pm_runtime_resume_and_get() has already dropped the
runtime PM usage count it acquired before returning the error. The
unconditional pm_runtime_put_autosuspend() at the end of the function
then drops the usage count again.

The failed resume path can also continue into
wave5_vpu_dec_clr_disp_flag() while the device is still suspended,
reopening the powered-off register access that the runtime PM get was
meant to prevent.

Check the return value from pm_runtime_resume_and_get(). If the resume
fails, complete the queued buffer with an error and return without
touching the hardware or dropping an unmatched runtime PM reference.

Fixes: cbb9c0d50e47 ("media: chips-media: wave5: Fix SError of kernel panic when closed")
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
index bb2ba9204a83..03d108b808ba 100644
--- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
+++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
@@ -1290,8 +1290,14 @@ static void wave5_vpu_dec_buf_queue_dst(struct vb2_buffer *vb)
 	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
 	struct vpu_instance *inst = vb2_get_drv_priv(vb->vb2_queue);
 	struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(inst->dev->dev);
+	if (ret < 0) {
+		vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
+		return;
+	}
 
-	pm_runtime_resume_and_get(inst->dev->dev);
 	vbuf->sequence = inst->queued_dst_buf_num++;
 
 	if (inst->state == VPU_INST_STATE_PIC_RUN) {
-- 
2.43.0


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

* Re: [PATCH] media: chips-media: wave5: Check decoder qbuf runtime resume
  2026-07-05 14:57 [PATCH] media: chips-media: wave5: Check decoder qbuf runtime resume Guangshuo Li
@ 2026-07-16  1:50 ` Nicolas Dufresne
  0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Dufresne @ 2026-07-16  1:50 UTC (permalink / raw)
  To: Guangshuo Li, Nas Chung, Jackson Lee, Mauro Carvalho Chehab,
	Hans Verkuil, linux-media, linux-kernel

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

Le dimanche 05 juillet 2026 à 22:57 +0800, Guangshuo Li a écrit :
> wave5_vpu_dec_buf_queue_dst() resumes the VPU before it may clear a
> decoder display flag. This is needed because clearing the display flag
> accesses VPU registers.
> 
> However, the return value from pm_runtime_resume_and_get() is ignored.
> If the resume fails, pm_runtime_resume_and_get() has already dropped the
> runtime PM usage count it acquired before returning the error. The
> unconditional pm_runtime_put_autosuspend() at the end of the function
> then drops the usage count again.
> 
> The failed resume path can also continue into
> wave5_vpu_dec_clr_disp_flag() while the device is still suspended,
> reopening the powered-off register access that the runtime PM get was
> meant to prevent.
> 
> Check the return value from pm_runtime_resume_and_get(). If the resume
> fails, complete the queued buffer with an error and return without
> touching the hardware or dropping an unmatched runtime PM reference.
> 
> Fixes: cbb9c0d50e47 ("media: chips-media: wave5: Fix SError of kernel panic when closed")
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
> ---
>  drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
> index bb2ba9204a83..03d108b808ba 100644
> --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
> +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
> @@ -1290,8 +1290,14 @@ static void wave5_vpu_dec_buf_queue_dst(struct vb2_buffer *vb)
>  	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
>  	struct vpu_instance *inst = vb2_get_drv_priv(vb->vb2_queue);
>  	struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx;
> +	int ret;
> +
> +	ret = pm_runtime_resume_and_get(inst->dev->dev);
> +	if (ret < 0) {
> +		vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
> +		return;
> +	}

And what about the 4 other calls to this function ? Please be consistent.

Nicolas

>  
> -	pm_runtime_resume_and_get(inst->dev->dev);
>  	vbuf->sequence = inst->queued_dst_buf_num++;
>  
>  	if (inst->state == VPU_INST_STATE_PIC_RUN) {

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

end of thread, other threads:[~2026-07-16  1:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-05 14:57 [PATCH] media: chips-media: wave5: Check decoder qbuf runtime resume Guangshuo Li
2026-07-16  1:50 ` Nicolas Dufresne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®