RE: [PATCH 2/4] media: wave5: handle encoder runtime resume failures

From: jackson.lee

Date: Thu Oct 08 2026 - 03:26:19 EST


Hi Jiale

> -----Original Message-----
> From: Jiale Yao <yaojiale02@xxxxxxx>
> Sent: Saturday, October 3, 2026 5:09 PM
> To: Nas Chung <nas.chung@xxxxxxxxxxxxxxx>; jackson.lee
> <jackson.lee@xxxxxxxxxxxxxxx>; Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>;
> Nicolas Dufresne <nicolas.dufresne@xxxxxxxxxxxxx>; Hans Verkuil
> <hverkuil@xxxxxxxxxx>; Sebastian Fricke <sebastian.fricke@xxxxxxxxxxxxx>;
> linux-media@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
> Cc: Jiale Yao <yaojiale02@xxxxxxx>
> Subject: [PATCH 2/4] media: wave5: handle encoder runtime resume failures
>
> The encoder callbacks ignore failures from pm_runtime_resume_and_get() and
> continue issuing firmware commands. Runtime resume can fail while enabling
> the VPU clocks, leaving the registers inaccessible. The callbacks then
> also drop a runtime PM reference that was not acquired.
>
> Check each resume result. Propagate the error from start_streaming(), and
> return queued buffers or finish the job from void callbacks without
> accessing the hardware or issuing an unmatched put.
>
> Fixes: 2092b3833487 ("media: chips-media: wave5: Support runtime
> suspend/resume")
> Signed-off-by: Jiale Yao <yaojiale02@xxxxxxx>
> ---
> .../chips-media/wave5/wave5-vpu-enc.c | 25 ++++++++++++++++---
> 1 file changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
> b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
> index f9fcdf4c224b..5a5ee70cd854 100644
> --- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
> +++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
> @@ -1351,7 +1351,12 @@ static int wave5_vpu_enc_start_streaming(struct
> vb2_queue *q, unsigned int count
> struct v4l2_m2m_ctx *m2m_ctx = inst->v4l2_fh.m2m_ctx;
> int ret = 0;
>
> - 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);
>
> if (inst->state == VPU_INST_STATE_NONE && q->type ==
> V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { @@ -1451,6 +1456,7 @@ static void
> wave5_vpu_enc_stop_streaming(struct vb2_queue *q) {
> struct vpu_instance *inst = vb2_get_drv_priv(q);
> bool check_cmd = true;
> + int ret;
>
> /*
> * Note that we don't need m2m_ctx->next_buf_last for this driver,
> so we @@ -1458,7 +1464,14 @@ static void
> wave5_vpu_enc_stop_streaming(struct vb2_queue *q)
> */
>
> 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) {
> + if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
> + streamoff_output(inst, q);
> + else
> + streamoff_capture(inst, q);
> + return;
> + }
>
> if (wave5_vpu_both_queues_are_streaming(inst))
> switch_state(inst, VPU_INST_STATE_STOP); @@ -1526,7 +1539,13
> @@ static void wave5_vpu_enc_device_run(void *priv)
> u32 fail_res = 0;
> int ret = 0;
>
> - pm_runtime_resume_and_get(inst->dev->dev);
> + ret = pm_runtime_resume_and_get(inst->dev->dev);
> + if (ret < 0) {
> + dev_err(inst->dev->dev, "Failed to resume VPU: %d\n", ret);
> + v4l2_m2m_job_finish(inst->v4l2_m2m_dev, m2m_ctx);
> + return;
> + }
> +

Runtime PM keeps the resume error, so every later resume fails too.
wave5_vpu_enc_job_ready() returns true in PIC_RUN while
m2m_ctx->is_draining is set or source buffers are queued. Nothing is
consumed here, so the job is rescheduled right away and device_run()
fails in a loop. Please switch the instance to STOP, return the
OUTPUT/CAPTURE buffers with VB2_BUF_STATE_ERROR, call vb2_queue_error()
on both queues, and then finish the job.

Thanks
Jackson

> switch (inst->state) {
> case VPU_INST_STATE_PIC_RUN:
> ret = start_encode(inst, &fail_res);
> --
> 2.34.1