* [PATCH] media: chips-media: wave5: Balance runtime PM on encoder close errors
@ 2026-07-17 7:57 Linmao Li
2026-09-28 20:57 ` Nicolas Dufresne
0 siblings, 1 reply; 2+ messages in thread
From: Linmao Li @ 2026-07-17 7:57 UTC (permalink / raw)
To: Nas Chung, Jackson Lee
Cc: Mauro Carvalho Chehab, Nicolas Dufresne, Sebastian Fricke,
Hans Verkuil, linux-media, linux-kernel, Linmao Li, stable
wave5_vpu_enc_close() resumes the device before taking the hardware lock.
Its three error paths call pm_runtime_resume_and_get() again instead of
dropping that reference. Each failure therefore increments the runtime PM
usage count twice and can prevent the device from suspending afterward.
Replace the extra resume calls with pm_runtime_put_sync() to balance the
reference acquired on entry, matching the successful close path. This
aligns wave5_vpu_enc_close() with wave5_vpu_dec_close(), which already
releases the reference on its error paths.
Fixes: 2092b3833487 ("media: chips-media: wave5: Support runtime suspend/resume")
Cc: stable@vger.kernel.org
Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
---
.../platform/chips-media/wave5/wave5-vpuapi.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c
index f77abd5e122a..4c1842f02c88 100644
--- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c
+++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c
@@ -754,7 +754,7 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res)
ret = mutex_lock_interruptible(&vpu_dev->hw_lock);
if (ret) {
- pm_runtime_resume_and_get(inst->dev->dev);
+ pm_runtime_put_sync(inst->dev->dev);
return ret;
}
@@ -762,16 +762,13 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res)
ret = wave5_vpu_enc_finish_seq(inst, fail_res);
if (ret < 0 && *fail_res != WAVE5_SYSERR_VPU_STILL_RUNNING) {
dev_warn(inst->dev->dev, "enc_finish_seq timed out\n");
- pm_runtime_resume_and_get(inst->dev->dev);
- mutex_unlock(&vpu_dev->hw_lock);
- return ret;
+ goto unlock_and_return;
}
if (*fail_res == WAVE5_SYSERR_VPU_STILL_RUNNING &&
retry++ >= MAX_FIRMWARE_CALL_RETRY) {
- pm_runtime_resume_and_get(inst->dev->dev);
- mutex_unlock(&vpu_dev->hw_lock);
- return -ETIMEDOUT;
+ ret = -ETIMEDOUT;
+ goto unlock_and_return;
}
} while (ret != 0);
@@ -787,10 +784,12 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res)
}
wave5_vdi_free_dma_memory(vpu_dev, &p_enc_info->vb_task);
+
+unlock_and_return:
mutex_unlock(&vpu_dev->hw_lock);
pm_runtime_put_sync(inst->dev->dev);
- return 0;
+ return ret;
}
int wave5_vpu_enc_register_frame_buffer(struct vpu_instance *inst, unsigned int num,
--
2.25.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] media: chips-media: wave5: Balance runtime PM on encoder close errors
2026-07-17 7:57 [PATCH] media: chips-media: wave5: Balance runtime PM on encoder close errors Linmao Li
@ 2026-09-28 20:57 ` Nicolas Dufresne
0 siblings, 0 replies; 2+ messages in thread
From: Nicolas Dufresne @ 2026-09-28 20:57 UTC (permalink / raw)
To: Linmao Li, Nas Chung, Jackson Lee
Cc: Mauro Carvalho Chehab, Sebastian Fricke, Hans Verkuil,
linux-media, linux-kernel, stable
[-- Attachment #1: Type: text/plain, Size: 2782 bytes --]
Le vendredi 17 juillet 2026 à 15:57 +0800, Linmao Li a écrit :
> wave5_vpu_enc_close() resumes the device before taking the hardware lock.
> Its three error paths call pm_runtime_resume_and_get() again instead of
> dropping that reference. Each failure therefore increments the runtime PM
> usage count twice and can prevent the device from suspending afterward.
>
> Replace the extra resume calls with pm_runtime_put_sync() to balance the
> reference acquired on entry, matching the successful close path. This
> aligns wave5_vpu_enc_close() with wave5_vpu_dec_close(), which already
> releases the reference on its error paths.
>
> Fixes: 2092b3833487 ("media: chips-media: wave5: Support runtime suspend/resume")
> Cc: stable@vger.kernel.org
> Signed-off-by: Linmao Li <lilinmao@kylinos.cn>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
picked, ty.
> ---
> .../platform/chips-media/wave5/wave5-vpuapi.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c
> index f77abd5e122a..4c1842f02c88 100644
> --- a/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c
> +++ b/drivers/media/platform/chips-media/wave5/wave5-vpuapi.c
> @@ -754,7 +754,7 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res)
>
> ret = mutex_lock_interruptible(&vpu_dev->hw_lock);
> if (ret) {
> - pm_runtime_resume_and_get(inst->dev->dev);
> + pm_runtime_put_sync(inst->dev->dev);
> return ret;
> }
>
> @@ -762,16 +762,13 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res)
> ret = wave5_vpu_enc_finish_seq(inst, fail_res);
> if (ret < 0 && *fail_res != WAVE5_SYSERR_VPU_STILL_RUNNING) {
> dev_warn(inst->dev->dev, "enc_finish_seq timed out\n");
> - pm_runtime_resume_and_get(inst->dev->dev);
> - mutex_unlock(&vpu_dev->hw_lock);
> - return ret;
> + goto unlock_and_return;
> }
>
> if (*fail_res == WAVE5_SYSERR_VPU_STILL_RUNNING &&
> retry++ >= MAX_FIRMWARE_CALL_RETRY) {
> - pm_runtime_resume_and_get(inst->dev->dev);
> - mutex_unlock(&vpu_dev->hw_lock);
> - return -ETIMEDOUT;
> + ret = -ETIMEDOUT;
> + goto unlock_and_return;
> }
> } while (ret != 0);
>
> @@ -787,10 +784,12 @@ int wave5_vpu_enc_close(struct vpu_instance *inst, u32 *fail_res)
> }
>
> wave5_vdi_free_dma_memory(vpu_dev, &p_enc_info->vb_task);
> +
> +unlock_and_return:
> mutex_unlock(&vpu_dev->hw_lock);
> pm_runtime_put_sync(inst->dev->dev);
>
> - return 0;
> + return ret;
> }
>
> int wave5_vpu_enc_register_frame_buffer(struct vpu_instance *inst, unsigned int num,
[-- 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-09-28 20:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-17 7:57 [PATCH] media: chips-media: wave5: Balance runtime PM on encoder close errors Linmao Li
2026-09-28 20:57 ` 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®