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

From: Nicolas Dufresne

Date: Wed Jul 15 2026 - 21:40:23 EST


Le jeudi 25 juin 2026 à 08:31 +0800, Pengpeng Hou a écrit :
> wait_event_interruptible_timeout() returns a positive value when the
> condition becomes true before the timeout expires.
>
> mtk_jpegdec_worker() treats every non-zero return value as a failure and
> finishes the mem2mem job with an error.  A normal wakeup that indicates
> that a decode engine is ready can therefore be handled as if all hardware
> remained busy.
>
> Only fail immediately on interrupted waits.  Keep the existing retry limit
> for real timeouts, and retry hardware selection after a successful wait.
>
> Signed-off-by: Pengpeng Hou <pengpeng@xxxxxxxxxxx>goto
> ---
>  drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index d147ec483..391db77a6 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> @@ -1697,7 +1697,7 @@ 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)) {
> + if (ret < 0 || (!ret && i++ > MTK_JPEG_MAX_RETRY_TIME)) {

I agree with the text and the code logic, but I'm wondering why do we use
timeout for decoder, but not for encoder ? Perhaps we should have different
error logs for when we ran out of retry vs when wait_event failed ? I would also
like to see this condition broken down, maybe by moving the goto earlier with an
explicit check for the timeout ?

Nicolas

>   dev_err(jpeg->dev, "%s : %d, all HW are busy\n",
>   __func__, __LINE__);
>   v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx);

Attachment: signature.asc
Description: This is a digitally signed message part