From: sashiko-bot@kernel.org
To: "Anand Moon" <linux.amoon@gmail.com>
Cc: linux-amlogic@lists.infradead.org, linux-media@vger.kernel.org,
neil.armstrong@linaro.org
Subject: Re: [PATCH v6 1/8] media: meson: vdec: Fix memory leaks and lifetime of m2m device
Date: Sat, 30 May 2026 09:55:43 +0000 [thread overview]
Message-ID: <20260530095544.997391F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260530094326.11892-2-linux.amoon@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Use-After-Free of `m2m_dev` and `core` on driver unbind.
- [Medium] Logically backwards error unwinding in `vdec_open()` introduces dead code and fails to fix a resource leak.
--
commit 1e540207d92a3242e7aac789684a1ad3c201c64e
Author: Anand Moon <linux.amoon@gmail.com>
media: meson: vdec: Fix memory leaks and lifetime of m2m device
This commit shifts the v4l2_m2m_init() call to vdec_probe() and releases
it in vdec_remove() to address a design flaw where the m2m device was bound
to the session. It also attempts to resolve resource leaks in the driver's
error handling paths.
Cc: Nicolas Dufresne <nicolas@ndufresne.ca>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260520045905.6ACBA1F000E9@smtp.kernel.org/#t
Fixes: 3e7f51bd9607 ("media: meson: add v4l2 m2m video decoder driver")
> diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c
> --- a/drivers/staging/media/meson/vdec/vdec.c
> +++ b/drivers/staging/media/meson/vdec/vdec.c
[ ... ]
> @@ -873,23 +873,16 @@ static int vdec_open(struct file *file)
>
> sess->core = core;
>
> - sess->m2m_dev = v4l2_m2m_init(&vdec_m2m_ops);
> - if (IS_ERR(sess->m2m_dev)) {
> - dev_err(dev, "Fail to v4l2_m2m_init\n");
> - ret = PTR_ERR(sess->m2m_dev);
> - goto err_free_sess;
> - }
> -
> - sess->m2m_ctx = v4l2_m2m_ctx_init(sess->m2m_dev, sess, m2m_queue_init);
> + sess->m2m_ctx = v4l2_m2m_ctx_init(core->m2m_dev, sess, m2m_queue_init);
> if (IS_ERR(sess->m2m_ctx)) {
> dev_err(dev, "Fail to v4l2_m2m_ctx_init\n");
> ret = PTR_ERR(sess->m2m_ctx);
> - goto err_m2m_release;
> + goto err_fh_del;
[Severity: Medium]
Is this error unwinding logic in the correct order? Jumps to err_fh_del here
will call v4l2_fh_exit() on sess->fh before it has been initialized further
down in vdec_open().
> }
>
> ret = vdec_init_ctrls(sess);
> if (ret)
> - goto err_m2m_release;
> + goto err_free_sess;
[Severity: Medium]
Does skipping err_fh_del here lead to a memory leak? If vdec_init_ctrls()
fails, jumping directly to err_free_sess bypasses freeing the successfully
allocated sess->m2m_ctx.
[ ... ]
> @@ -925,9 +918,9 @@ static int vdec_close(struct file *file)
> struct amvdec_session *sess = file_to_amvdec_session(file);
>
> v4l2_m2m_ctx_release(sess->m2m_ctx);
[Severity: High]
Can this result in a use-after-free if the user holds the file descriptor
open after the driver is unbound?
During driver unbind, vdec_remove() explicitly frees core->m2m_dev and
devres cleans up the amvdec_core structure.
If a user subsequently closes an open file descriptor, vdec_close()
calls v4l2_m2m_ctx_release(), which will dereference the freed m2m_dev
pointer inside v4l2_m2m_cancel_job().
Additionally, any pending jobs may trigger vdec_m2m_job_abort(), which
dereferences the freed sess->core and sess->core->m2m_dev.
> - v4l2_m2m_release(sess->m2m_dev);
> v4l2_fh_del(&sess->fh, file);
> v4l2_fh_exit(&sess->fh);
> + v4l2_ctrl_handler_free(&sess->ctrl_handler);
>
> mutex_destroy(&sess->lock);
> mutex_destroy(&sess->bufs_recycle_lock);
[ ... ]
> @@ -1104,6 +1106,7 @@ static void vdec_remove(struct platform_device *pdev)
>
> video_unregister_device(core->vdev_dec);
> v4l2_device_unregister(&core->v4l2_dev);
> + v4l2_m2m_release(core->m2m_dev);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530094326.11892-1-linux.amoon@gmail.com?part=1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Anand Moon" <linux.amoon@gmail.com>
Cc: linux-amlogic@lists.infradead.org, linux-media@vger.kernel.org,
neil.armstrong@linaro.org
Subject: Re: [PATCH v6 1/8] media: meson: vdec: Fix memory leaks and lifetime of m2m device
Date: Sat, 30 May 2026 09:55:43 +0000 [thread overview]
Message-ID: <20260530095544.997391F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260530094326.11892-2-linux.amoon@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Use-After-Free of `m2m_dev` and `core` on driver unbind.
- [Medium] Logically backwards error unwinding in `vdec_open()` introduces dead code and fails to fix a resource leak.
--
commit 1e540207d92a3242e7aac789684a1ad3c201c64e
Author: Anand Moon <linux.amoon@gmail.com>
media: meson: vdec: Fix memory leaks and lifetime of m2m device
This commit shifts the v4l2_m2m_init() call to vdec_probe() and releases
it in vdec_remove() to address a design flaw where the m2m device was bound
to the session. It also attempts to resolve resource leaks in the driver's
error handling paths.
Cc: Nicolas Dufresne <nicolas@ndufresne.ca>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/20260520045905.6ACBA1F000E9@smtp.kernel.org/#t
Fixes: 3e7f51bd9607 ("media: meson: add v4l2 m2m video decoder driver")
> diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c
> --- a/drivers/staging/media/meson/vdec/vdec.c
> +++ b/drivers/staging/media/meson/vdec/vdec.c
[ ... ]
> @@ -873,23 +873,16 @@ static int vdec_open(struct file *file)
>
> sess->core = core;
>
> - sess->m2m_dev = v4l2_m2m_init(&vdec_m2m_ops);
> - if (IS_ERR(sess->m2m_dev)) {
> - dev_err(dev, "Fail to v4l2_m2m_init\n");
> - ret = PTR_ERR(sess->m2m_dev);
> - goto err_free_sess;
> - }
> -
> - sess->m2m_ctx = v4l2_m2m_ctx_init(sess->m2m_dev, sess, m2m_queue_init);
> + sess->m2m_ctx = v4l2_m2m_ctx_init(core->m2m_dev, sess, m2m_queue_init);
> if (IS_ERR(sess->m2m_ctx)) {
> dev_err(dev, "Fail to v4l2_m2m_ctx_init\n");
> ret = PTR_ERR(sess->m2m_ctx);
> - goto err_m2m_release;
> + goto err_fh_del;
[Severity: Medium]
Is this error unwinding logic in the correct order? Jumps to err_fh_del here
will call v4l2_fh_exit() on sess->fh before it has been initialized further
down in vdec_open().
> }
>
> ret = vdec_init_ctrls(sess);
> if (ret)
> - goto err_m2m_release;
> + goto err_free_sess;
[Severity: Medium]
Does skipping err_fh_del here lead to a memory leak? If vdec_init_ctrls()
fails, jumping directly to err_free_sess bypasses freeing the successfully
allocated sess->m2m_ctx.
[ ... ]
> @@ -925,9 +918,9 @@ static int vdec_close(struct file *file)
> struct amvdec_session *sess = file_to_amvdec_session(file);
>
> v4l2_m2m_ctx_release(sess->m2m_ctx);
[Severity: High]
Can this result in a use-after-free if the user holds the file descriptor
open after the driver is unbound?
During driver unbind, vdec_remove() explicitly frees core->m2m_dev and
devres cleans up the amvdec_core structure.
If a user subsequently closes an open file descriptor, vdec_close()
calls v4l2_m2m_ctx_release(), which will dereference the freed m2m_dev
pointer inside v4l2_m2m_cancel_job().
Additionally, any pending jobs may trigger vdec_m2m_job_abort(), which
dereferences the freed sess->core and sess->core->m2m_dev.
> - v4l2_m2m_release(sess->m2m_dev);
> v4l2_fh_del(&sess->fh, file);
> v4l2_fh_exit(&sess->fh);
> + v4l2_ctrl_handler_free(&sess->ctrl_handler);
>
> mutex_destroy(&sess->lock);
> mutex_destroy(&sess->bufs_recycle_lock);
[ ... ]
> @@ -1104,6 +1106,7 @@ static void vdec_remove(struct platform_device *pdev)
>
> video_unregister_device(core->vdev_dec);
> v4l2_device_unregister(&core->v4l2_dev);
> + v4l2_m2m_release(core->m2m_dev);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260530094326.11892-1-linux.amoon@gmail.com?part=1
next prev parent reply other threads:[~2026-05-30 9:55 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 9:42 [PATCH v6 0/8] media: meson: Fix memory leak in error path in vdec Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` [PATCH v6 1/8] media: meson: vdec: Fix memory leaks and lifetime of m2m device Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:55 ` sashiko-bot [this message]
2026-05-30 9:55 ` sashiko-bot
2026-05-30 9:42 ` [PATCH v6 2/8] media: meson: vdec: Fix concurrent STREAMON / STREAMOFF race conditions Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 10:08 ` sashiko-bot
2026-05-30 10:08 ` sashiko-bot
2026-05-30 9:42 ` [PATCH v6 3/8] media: meson: vdec: Handle kthread failure and free codec state Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 10:25 ` sashiko-bot
2026-05-30 10:25 ` sashiko-bot
2026-05-30 9:42 ` [PATCH v6 4/8] media: meson: vdec: Condition buffer flushing on queue type in start_streaming Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 10:43 ` sashiko-bot
2026-05-30 10:43 ` sashiko-bot
2026-05-30 9:42 ` [PATCH v6 5/8] media: meson: vdec: Cancel esparser work during teardown Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 10:59 ` sashiko-bot
2026-05-30 10:59 ` sashiko-bot
2026-05-30 9:42 ` [PATCH v6 6/8] media: meson: vdec: Configure DMA mask and segment size in probe Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 11:10 ` sashiko-bot
2026-05-30 11:10 ` sashiko-bot
2026-05-30 9:42 ` [PATCH v6 7/8] media: meson: vdec: Fix NULL pointer dereference in ISR handlers Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 11:23 ` sashiko-bot
2026-05-30 11:23 ` sashiko-bot
2026-05-30 9:42 ` [PATCH v6 8/8] gpu: drm: meson: Fix DMA max segment size for DMABUF imports Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 9:42 ` Anand Moon
2026-05-30 11:35 ` sashiko-bot
2026-05-30 11:35 ` 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=20260530095544.997391F00893@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-amlogic@lists.infradead.org \
--cc=linux-media@vger.kernel.org \
--cc=linux.amoon@gmail.com \
--cc=neil.armstrong@linaro.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 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.