FAILED: patch "[PATCH] media: imx-jpeg: finish the job on device_run() error paths" failed to apply to 5.15-stable tree
Subsystems (4)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 30b35fd2b999e1b8c26f8191d974d20c8848d2d6
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 30b35fd2b999e1b8c26f8191d974d20c8848d2d6 Mon Sep 17 00:00:00 2001
From: Fan Wu <[email protected]>
Date: Wed, 24 Jun 2026 00:32:08 +0000
Subject: [PATCH] media: imx-jpeg: finish the job on device_run() error paths
mxc_jpeg_device_run() returns early through a shared "end" label on several error paths (no free slot, mxc_jpeg_alloc_slot_data() failure, or missing buffers or queue data), and none of them calls v4l2_m2m_job_finish(). Since the delayed work is queued only after the hardware is started, those paths neither finish the job directly nor queue timeout work that could finish it later. The job is left with TRANS_RUNNING set, so the wait_event() in v4l2_m2m_cancel_job() (reached from v4l2_m2m_ctx_release() at close) waits indefinitely and the close hangs.
mxc_jpeg_alloc_slot_data() uses dma_alloc_coherent(), so the failure path is reachable under memory pressure.
Return the src/dst buffers with VB2_BUF_STATE_ERROR and call v4l2_m2m_job_finish() on those paths: paths that have buffers use a "buf_finish" label; the no-buffer path uses "job_finish" directly. This mirrors the existing jpeg_parse_error path.
This bug was found by static analysis.
--- .../media/platform/nxp/imx-jpeg/mxc-jpeg.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/media/platform/nxp/imx-jpeg/mxc-jpeg.c +15 -6
@@ -1590,15 +1590,15 @@ static void mxc_jpeg_device_run(void *priv) dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx);if (!src_buf || !dst_buf) {dev_err (dev,"Null src or dst buf\n" ); - goto end; + goto job_finish; } q_data_cap =mxc_jpeg_get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE );if (!q_data_cap) - goto end; + goto buf_finish; q_data_out =mxc_jpeg_get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT );if (!q_data_out) - goto end; + goto buf_finish; src_buf->sequence = q_data_out->sequence++; dst_buf->sequence = q_data_cap->sequence++;
@@ -1636,11 +1636,11 @@ static void mxc_jpeg_device_run(void *priv) ctx->slot =mxc_get_free_slot (&jpeg->slot_data);if (ctx->slot <0 ) {dev_err (dev,"No more free slots\n" ); - goto end; + goto buf_finish; }if (!mxc_jpeg_alloc_slot_data (jpeg)) {dev_err (dev,"Cannot allocate slot data\n" ); - goto end; + goto buf_finish; }mxc_jpeg_enable_slot (reg, ctx->slot);
@@ -1660,8 +1660,17 @@ static void mxc_jpeg_device_run(void *priv)mxc_jpeg_dec_mode_go (dev, reg); }schedule_delayed_work (&ctx->task_timer,msecs_to_jiffies (hw_timeout)); -end: +spin_unlock_irqrestore (&ctx->mxc_jpeg->hw_lock, flags); +return ; +buf_finish: +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_ERROR ); +job_finish: +spin_unlock_irqrestore (&ctx->mxc_jpeg->hw_lock, flags); +v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); } static int mxc_jpeg_decoder_cmd(struct file *file, void *priv,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 media: imx-jpeg: finish the job on device_run() error paths
From: Fan Wu <[email protected]>
[ Upstream commit 30b35fd2b999e1b8c26f8191d974d20c8848d2d6 ]
mxc_jpeg_device_run() returns early through a shared "end" label on several error paths (no free slot, mxc_jpeg_alloc_slot_data() failure, or missing buffers or queue data), and none of them calls v4l2_m2m_job_finish(). Since the delayed work is queued only after the hardware is started, those paths neither finish the job directly nor queue timeout work that could finish it later. The job is left with TRANS_RUNNING set, so the wait_event() in v4l2_m2m_cancel_job() (reached from v4l2_m2m_ctx_release() at close) waits indefinitely and the close hangs.
mxc_jpeg_alloc_slot_data() uses dma_alloc_coherent(), so the failure path is reachable under memory pressure.
Return the src/dst buffers with VB2_BUF_STATE_ERROR and call v4l2_m2m_job_finish() on those paths: paths that have buffers use a "buf_finish" label; the no-buffer path uses "job_finish" directly. This mirrors the existing jpeg_parse_error path.
This bug was found by static analysis.
--- drivers/media/platform/imx-jpeg/mxc-jpeg.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/media/platform/imx-jpeg/mxc-jpeg.c +15 -6
@@ -999,15 +999,15 @@ static void mxc_jpeg_device_run(void *priv) dst_buf =v4l2_m2m_next_dst_buf (ctx->fh.m2m_ctx);if (!src_buf || !dst_buf) {dev_err (dev,"Null src or dst buf\n" ); - goto end; + goto job_finish; } q_data_cap =mxc_jpeg_get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE );if (!q_data_cap) - goto end; + goto buf_finish; q_data_out =mxc_jpeg_get_q_data (ctx,V4L2_BUF_TYPE_VIDEO_OUTPUT );if (!q_data_out) - goto end; + goto buf_finish; src_buf->sequence = q_data_out->sequence++; dst_buf->sequence = q_data_cap->sequence++;
@@ -1050,11 +1050,11 @@ static void mxc_jpeg_device_run(void *priv) ctx->slot =mxc_get_free_slot (jpeg->slot_data,MXC_MAX_SLOTS );if (ctx->slot >=MXC_MAX_SLOTS ) {dev_err (dev,"No more free slots\n" ); - goto end; + goto buf_finish; }if (!mxc_jpeg_alloc_slot_data (jpeg, ctx->slot)) {dev_err (dev,"Cannot allocate slot data\n" ); - goto end; + goto buf_finish; }mxc_jpeg_enable_slot (reg, ctx->slot);
@@ -1073,8 +1073,17 @@ static void mxc_jpeg_device_run(void *priv) &src_buf->vb2_buf, &dst_buf->vb2_buf);mxc_jpeg_dec_mode_go (dev, reg); } -end: +spin_unlock_irqrestore (&ctx->mxc_jpeg->hw_lock, flags); +return ; +buf_finish: +v4l2_m2m_src_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_dst_buf_remove (ctx->fh.m2m_ctx); +v4l2_m2m_buf_done (src_buf,VB2_BUF_STATE_ERROR ); +v4l2_m2m_buf_done (dst_buf,VB2_BUF_STATE_ERROR ); +job_finish: +spin_unlock_irqrestore (&ctx->mxc_jpeg->hw_lock, flags); +v4l2_m2m_job_finish (jpeg->m2m_dev, ctx->fh.m2m_ctx); } static int mxc_jpeg_decoder_cmd(struct file *file, void *priv,
Signature · 1 line
2.53.0