mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guangshuo Li <lgs201920130244@gmail.com>
To: Nas Chung <nas.chung@chipsnmedia.com>,
	Jackson Lee <jackson.lee@chipsnmedia.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Guangshuo Li <lgs201920130244@gmail.com>
Subject: [PATCH v2 2/2] media: chips-media: wave5: Check decoder runtime resume errors
Date: Sat, 18 Jul 2026 21:00:37 +0800	[thread overview]
Message-ID: <20260718130037.3306626-3-lgs201920130244@gmail.com> (raw)
In-Reply-To: <20260718130037.3306626-1-lgs201920130244@gmail.com>

The decoder start_streaming, stop_streaming and device_run callbacks
resume the VPU before accessing hardware, but do not check the return
value from pm_runtime_resume_and_get().

If runtime resume fails, continuing can access the VPU while it remains
suspended. Since pm_runtime_resume_and_get() does not retain a runtime PM
usage reference on failure, the later unconditional
pm_runtime_put_autosuspend() can also drop an unmatched reference.

Check the return value in all three callbacks. Return queued buffers as
required by vb2 when start_streaming fails, clean up buffers without
touching hardware when stop_streaming fails, and finish the current
mem2mem job when device_run cannot resume.

Only call pm_runtime_put_autosuspend() after a successful runtime
resume.

Fixes: 2092b3833487 ("media: chips-media: wave5: Support runtime suspend/resume")
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 .../chips-media/wave5/wave5-vpu-dec.c         | 36 +++++++++++++++++--
 1 file changed, 33 insertions(+), 3 deletions(-)

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 03d108b808ba..bb59bc962603 100644
--- a/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
+++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-dec.c
@@ -1380,7 +1380,11 @@ static int wave5_vpu_dec_start_streaming(struct vb2_queue *q, unsigned int count
 	int ret = 0;
 
 	dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type);
-	pm_runtime_resume_and_get(inst->dev->dev);
+	ret = pm_runtime_resume_and_get(inst->dev->dev);
+	if (ret < 0) {
+		wave5_return_bufs(q, VB2_BUF_STATE_QUEUED);
+		return ret;
+	}
 
 	v4l2_m2m_update_start_streaming_state(m2m_ctx, q);
 
@@ -1544,9 +1548,29 @@ static void wave5_vpu_dec_stop_streaming(struct vb2_queue *q)
 	struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx;
 
 	bool check_cmd = TRUE;
+	int ret;
 
 	dev_dbg(inst->dev->dev, "%s: type: %u\n", __func__, q->type);
-	pm_runtime_resume_and_get(inst->dev->dev);
+	ret = pm_runtime_resume_and_get(inst->dev->dev);
+	if (ret < 0) {
+		struct vpu_src_buffer *vpu_buf;
+
+		v4l2_m2m_update_stop_streaming_state(m2m_ctx, q);
+
+		if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
+			inst->retry = false;
+			inst->queuing_num = 0;
+			while ((vpu_buf = inst_src_buf_remove(inst)) != NULL)
+				;
+			inst->eos = false;
+		}
+
+		wave5_return_bufs(q, VB2_BUF_STATE_ERROR);
+		inst->empty_queue = false;
+		inst->sent_eos = false;
+		return;
+	}
+
 	inst->empty_queue = true;
 	while (check_cmd) {
 		struct queue_status_info q_status;
@@ -1659,7 +1683,13 @@ static void wave5_vpu_dec_device_run(void *priv)
 	int ret = 0;
 
 	dev_dbg(inst->dev->dev, "%s: Fill the ring buffer with new bitstream data", __func__);
-	pm_runtime_resume_and_get(inst->dev->dev);
+
+	ret = pm_runtime_resume_and_get(inst->dev->dev);
+	if (ret < 0) {
+		v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx);
+		return;
+	}
+
 	if (!inst->retry) {
 		ret = fill_ringbuffer(inst);
 		if (ret < 0) {
-- 
2.43.0


  parent reply	other threads:[~2026-07-18 13:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-18 13:00 [PATCH v2 0/2] media: chips-media: wave5: Handle decoder runtime resume failures Guangshuo Li
2026-07-18 13:00 ` [PATCH v2 1/2] media: chips-media: wave5: Check decoder qbuf runtime resume Guangshuo Li
2026-09-28 21:10   ` Nicolas Dufresne
2026-07-18 13:00 ` Guangshuo Li [this message]
2026-09-28 21:13   ` [PATCH v2 2/2] media: chips-media: wave5: Check decoder runtime resume errors Nicolas Dufresne
2026-09-28 21:21     ` Nicolas Dufresne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260718130037.3306626-3-lgs201920130244@gmail.com \
    --to=lgs201920130244@gmail.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=jackson.lee@chipsnmedia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nas.chung@chipsnmedia.com \
    --cc=nicolas.dufresne@collabora.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®