devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Kyrie Wu" <kyrie.wu@mediatek.com>
Cc: media-ci@linuxtv.org, conor+dt@kernel.org,
	devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH v18 07/13] media: mediatek: jpeg: fix resolution change event handling in decoder
Date: Sat, 10 Oct 2026 08:24:35 +0000	[thread overview]
Message-ID: <sashiko-outbox-166343@kernel.org> (raw)
In-Reply-To: <d32a1c2510d7f1f1517fdfba482c65cfa7c18cd7.1791614327.git.kyrie.wu@mediatek.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] media: mtk-jpeg: infinite loop in worker on MTK_JPEG_SOURCE_CHANGE
- [High] media: mtk-jpeg: unprotected queue data mutation in async worker
--

commit 1072cbb260c137f5bbe5c089ef41101b9ac96729
Author: Kyrie Wu <kyrie.wu@mediatek.com>

media: mediatek: jpeg: fix resolution change event handling in decoder

This commit refines the handling of resolution change events in the JPEG
decoder worker. It updates the queue data before queuing the source
change event and setting the state to MTK_JPEG_SOURCE_CHANGE. It also
adds an early exit when the context is already in the source change state.

> diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> index e152ebae0f219..edd9e2d0ab05f 100644
> --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c
> +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c

[ ... ]

> @@ -1738,11 +1738,15 @@ static void mtk_jpegdec_worker(struct work_struct *work)
>  
>  	if (mtk_jpeg_check_resolution_change(ctx,
>  					     &jpeg_src_buf->dec_param)) {
> -		mtk_jpeg_queue_src_chg_event(ctx);
> +		mtk_jpeg_set_queue_data(ctx, &jpeg_src_buf->dec_param);

[Severity: High]
Does calling mtk_jpeg_set_queue_data() here mutate ctx->out_q and ctx->cap_q
without holding jpeg->lock? Since this runs in an asynchronous worker thread,
can concurrent V4L2 ioctls (like VIDIOC_G_FMT) issued from user space race
with these updates?

Updating the resolution before user space acknowledges the change with
STREAMOFF might also violate the driver's documented architectural contract.

>  		ctx->state = MTK_JPEG_SOURCE_CHANGE;
> +		mtk_jpeg_queue_src_chg_event(ctx);
>  		goto getbuf_fail;
>  	}
>  
> +	if (ctx->state == MTK_JPEG_SOURCE_CHANGE)
> +		goto getbuf_fail;

[Severity: High]
Could this introduce an infinite loop? If we jump to getbuf_fail here, the job
finishes without consuming the pending buffers.

Because mtk_jpeg_multicore_dec_m2m_ops lacks a .job_ready callback:

static const struct v4l2_m2m_ops mtk_jpeg_multicore_dec_m2m_ops = {
	.device_run = mtk_jpeg_multicore_dec_device_run,
};

the V4L2 M2M core assumes the device is always ready. Will the M2M core
immediately requeue the context, causing the worker to run again, hit this
same check, and loop infinitely consuming 100% CPU?

> +
>  	mtk_jpegdec_set_hw_param(ctx, hw_id, src_buf, dst_buf);
>  	ret = pm_runtime_resume_and_get(comp_jpeg[hw_id]->dev);
>  	if (ret < 0) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1791614327.git.kyrie.wu@mediatek.com?part=7

  reply	other threads:[~2026-10-10  8:24 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-10  8:07 [PATCH v18 00/13] media: mediatek: jpeg: add MT8196 JPEG support Kyrie Wu
2026-10-10  8:07 ` [PATCH v18 01/13] media: mediatek: jpeg: fix jpeg cores' amounts setting Kyrie Wu
2026-10-10  8:16   ` sashiko-bot
2026-10-10  8:07 ` [PATCH v18 02/13] media: mediatek: jpeg: fix jpeg buffer payload size setting Kyrie Wu
2026-10-10  8:07 ` [PATCH v18 03/13] media: mediatek: jpeg: fix buffer structure size and layout Kyrie Wu
2026-10-10  8:07 ` [PATCH v18 04/13] media: mediatek: jpeg: Fix buffer completion on multi-core streaming stop Kyrie Wu
2026-10-10  8:17   ` sashiko-bot
2026-10-10  8:07 ` [PATCH v18 05/13] media: mediatek: jpeg: Fix multi-core clk suspend and resume setting Kyrie Wu
2026-10-10  8:24   ` sashiko-bot
2026-10-10  8:07 ` [PATCH v18 06/13] media: mediatek: jpeg: fix buffer state update timing Kyrie Wu
2026-10-10  8:19   ` sashiko-bot
2026-10-10  8:07 ` [PATCH v18 07/13] media: mediatek: jpeg: fix resolution change event handling in decoder Kyrie Wu
2026-10-10  8:24   ` sashiko-bot [this message]
2026-10-10  8:07 ` [PATCH v18 08/13] media: mediatek: jpeg: fix remove buffer removal timing for multi-core Kyrie Wu
2026-10-10  8:18   ` sashiko-bot
2026-10-10  8:07 ` [PATCH v18 09/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgdec compatible Kyrie Wu
2026-10-10  8:07 ` [PATCH v18 10/13] media: dt-bindings: mediatek,jpeg: Add mediatek, mt8196-jpgenc compatible Kyrie Wu
2026-10-10  8:18   ` sashiko-bot
2026-10-10  8:07 ` [PATCH v18 11/13] media: mediatek: jpeg: add jpeg compatible Kyrie Wu
2026-10-10  8:21   ` sashiko-bot
2026-10-10  8:07 ` [PATCH v18 12/13] dt-bindings: mediatek: Add MT8196 JPEG SMMU bindings Kyrie Wu
2026-10-10  8:07 ` [PATCH v18 13/13] media: mediatek: jpeg: add jpeg smmu sid setting Kyrie Wu
2026-10-10  8:23   ` sashiko-bot

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=sashiko-outbox-166343@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kyrie.wu@mediatek.com \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).