[PATCH v2] media: mediatek: jpeg: retry HW selection after successful wait

From: Pengpeng Hou

Date: Mon Jul 20 2026 - 08:17:10 EST


wait_event_interruptible_timeout() returns a positive value when its
condition becomes true before timeout. mtk_jpegdec_worker() treats every
nonzero result as failure, so a normal decoder wakeup can finish the
mem2mem job as though no hardware became available.

Handle an interrupted wait and exhausted timeout retries separately, and
retry hardware selection after a successful wakeup. The encoder uses
wait_event_interruptible(), whose successful return is zero, so this change
does not alter its separate no-timeout waiting policy.

Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
---
Changes since v1: https://lore.kernel.org/all/20260625003142.99598-1-pengpeng@xxxxxxxxxxx/
- split interrupted waits, timeout exhaustion and successful wakeups
- use distinct diagnostics and explain why the encoder path is outside this
fix
- rebase onto v7.2-rc4

drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
index d147ec483081..9634c95aaada 100644
--- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
+++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
@@ -1697,9 +1697,15 @@ static void mtk_jpegdec_worker(struct work_struct *work)
ret = wait_event_interruptible_timeout(jpeg->hw_wq,
atomic_read(&jpeg->hw_rdy) > 0,
MTK_JPEG_HW_TIMEOUT_MSEC);
- if (ret != 0 || (i++ > MTK_JPEG_MAX_RETRY_TIME)) {
- dev_err(jpeg->dev, "%s : %d, all HW are busy\n",
- __func__, __LINE__);
+ if (ret < 0) {
+ dev_err(jpeg->dev, "decoder HW wait interrupted: %d\n",
+ ret);
+ v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
+ return;
+ }
+
+ if (!ret && i++ > MTK_JPEG_MAX_RETRY_TIME) {
+ dev_err(jpeg->dev, "all decoder HW are busy\n");
v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);
return;
}