From: sashiko-bot@kernel.org
To: "Fan Wu" <fanwu01@zju.edu.cn>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH] media: imx-jpeg: cancel timeout worker when streaming stops
Date: Tue, 23 Jun 2026 10:49:42 +0000 [thread overview]
Message-ID: <20260623104942.B91DF1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260623103031.3051-1-fanwu01@zju.edu.cn>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] A race condition between the frame-done IRQ handler and the timeout callback can lead to a NULL pointer dereference and hardware state corruption due to incorrectly processing a timeout for a finished job.
- [High] Missing v4l2_m2m_job_finish() on error paths in mxc_jpeg_device_run() causes the V4L2 mem2mem framework to hang permanently.
--
commit d5e489df2b36369b3ad5503c5a3b9a1b62e681de
Author: Fan Wu <fanwu01@zju.edu.cn>
media: imx-jpeg: cancel timeout worker when streaming stops
The commit adds a synchronous cancellation of the timeout worker to
mxc_jpeg_stop_streaming(). This prevents a use-after-free race condition
where the delayed work might execute after the context has been freed
when closing the file descriptor.
Fixes: cfed9632ca8e ("media: imx-jpeg: Add a timeout mechanism for each frame")
Cc: stable@vger.kernel.org
> diff --git a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> index 725e941528848..ea2fad5dd646d 100644
> --- a/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> +++ b/drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c
> @@ -1798,6 +1798,8 @@ static void mxc_jpeg_stop_streaming(struct vb2_queue *q)
>
> dev_dbg(ctx->mxc_jpeg->dev, "Stop streaming ctx=%p", ctx);
>
> + cancel_delayed_work_sync(&ctx->task_timer);
> +
[Severity: High]
This isn't a bug introduced by this patch, but does a race condition
still exist between the frame-done IRQ handler and the timeout callback?
When a job completes, mxc_jpeg_dec_irq() calls cancel_delayed_work(),
which is non-synchronous and doesn't wait if the timeout worker is
already executing and spinning on hw_lock:
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c:mxc_jpeg_dec_irq() {
...
cancel_delayed_work(&ctx->task_timer);
...
}
If the IRQ handler finishes the job, the framework can immediately queue
a new job for a different context, acquiring hw_lock and setting
jpeg->slot_data.used = true.
Can the timeout worker for the original ctx then erroneously see
used == true?
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c:mxc_jpeg_device_run_timeout() {
...
if (ctx->mxc_jpeg->slot_data.used) {
...
mxc_jpeg_job_finish(ctx, VB2_BUF_STATE_ERROR, true);
...
}
This could cause mxc_jpeg_job_finish() to be called when ctx has no
buffers left, leading to v4l2_m2m_next_src_buf() returning NULL which
is then dereferenced in v4l2_m2m_buf_done().
[Severity: High]
This is also a pre-existing issue, but can an error in
mxc_jpeg_device_run() cause a permanent hang?
If mxc_jpeg_alloc_slot_data() fails, the code drops hw_lock and returns
without clearing the V4L2 TRANS_RUNNING state or calling
v4l2_m2m_job_finish():
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c:mxc_jpeg_device_run() {
...
if (!mxc_jpeg_alloc_slot_data(jpeg)) {
dev_err(dev, "Cannot allocate slot data\n");
goto end;
}
...
}
Because schedule_delayed_work() is skipped, the timeout worker never runs
to rescue the job.
Would this cause v4l2_m2m_cancel_job() to spin-wait indefinitely for
TRANS_RUNNING to clear when the device is closed?
drivers/media/v4l2-core/v4l2-mem2mem.c:v4l2_m2m_cancel_job() {
...
wait_event(m2m_ctx->finished,
!(m2m_ctx->job_flags & TRANS_RUNNING));
...
}
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260623103031.3051-1-fanwu01@zju.edu.cn?part=1
prev parent reply other threads:[~2026-06-23 10:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 10:30 [PATCH] media: imx-jpeg: cancel timeout worker when streaming stops Fan Wu
2026-06-23 10:49 ` sashiko-bot [this message]
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=20260623104942.B91DF1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=fanwu01@zju.edu.cn \
--cc=imx@lists.linux.dev \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.