From: sashiko-bot@kernel.org
To: "Haojie Li" <lihaojie@kylinos.cn>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/mediatek: Add missing IS_ERR check for ovl_adaptor platform device
Date: Wed, 19 Aug 2026 07:07:52 +0000 [thread overview]
Message-ID: <20260819070753.5B0901F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260819065642.136222-1-lihaojie@kylinos.cn>
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
Pre-existing issues:
- [High] The dynamically registered `ovl_adaptor` platform device is leaked on probe error paths and during device removal, causing duplicate device accumulation.
- [High] `platform_device_register_data()` is misused to create a shallow, byte-for-byte clone of a `struct device` object.
- [High] `mtk_drm_bind()` mistakenly drops the `private->mutex_node` reference on `-EPROBE_DEFER`, causing an unbalanced put and potential use-after-free.
- [High] In `mtk_drm_of_ddp_path_build_one()`, if `mtk_drm_of_get_ddp_ep_cid()` fails early, it causes a double-put of the current device node in the loop.
- [Medium] In `mtk_drm_of_ddp_path_build_one()`, if the initial call to `mtk_drm_of_get_ddp_ep_cid()` fails but sets `next`, the acquired device node reference is leaked.
--
--- Patch [1]: [PATCH] drm/mediatek: Add missing IS_ERR check for ovl_adaptor platform device ---
commit 6317e1a251b60c3bf25295a5bff30bc7683eb97b
Author: Haojie Li <lihaojie@kylinos.cn>
drm/mediatek: Add missing IS_ERR check for ovl_adaptor platform device
This commit adds an IS_ERR() check after platform_device_register_data() in
mtk_drm_probe() to prevent a potential kernel crash due to an invalid pointer
dereference on error.
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index c86a3f54f35bc..667d7fdbfbac6 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -1112,6 +1112,10 @@ static int mtk_drm_probe(struct platform_device *pdev)
> PLATFORM_DEVID_AUTO,
> (void *)private->mmsys_dev,
> sizeof(*private->mmsys_dev));
[Severity: High]
This isn't a bug introduced by this patch, but is it safe to pass
(void *)private->mmsys_dev and sizeof(*private->mmsys_dev) as the platform
data?
platform_device_register_data() kmemdups the provided memory into the new
device's platform_data.
Copying the entire struct device object (including its kobject, mutexes,
and list heads) byte-for-byte might lead to subsystem operations running on
cloned and broken locks or kobjects when used by the OVL adaptor driver.
> + if (IS_ERR(ovl_adaptor)) {
> + ret = PTR_ERR(ovl_adaptor);
> + goto err_node;
> + }
[Severity: High]
This is a pre-existing issue, but is the dynamically registered ovl_adaptor
platform device leaked on probe error paths and during device removal?
If probe fails later (for example, returning -EPROBE_DEFER) and jumps to
err_node, or when mtk_drm_remove() is called, it doesn't look like
platform_device_unregister() is ever called.
This could leave orphaned devices accumulating on the platform bus.
> private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR].dev = &ovl_adaptor->dev;
> mtk_ddp_comp_init(dev, NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
> DDP_COMPONENT_DRM_OVL_ADAPTOR);
[ ... ]
> static int mtk_drm_bind(struct device *dev)
> {
> ...
> of_node_put(private->mutex_node);
> return -EPROBE_DEFER;
> ...
> }
[Severity: High]
This is a pre-existing issue, but does mtk_drm_bind() mistakenly drop the
private->mutex_node reference on -EPROBE_DEFER?
If it drops the reference here when the disp-mutex device is delayed, and the
driver is later unbound, mtk_drm_remove() will call of_node_put() again on
the same node pointer.
Could this cause an unbalanced put and potential use-after-free?
[ ... ]
> static int mtk_drm_of_ddp_path_build_one(...)
> {
> ...
> ret = mtk_drm_of_get_ddp_ep_cid(vdo, 0, cpath, &next, &temp_path[idx]);
> if (ret) {
> if (next && temp_path[idx] == DDP_COMPONENT_DRM_OVL_ADAPTOR) {
> ...
> } else {
> if (next)
> dev_err(dev, "Invalid component %pOF\n", next);
> else
> dev_err(dev, "Cannot find first endpoint for path %d\n", cpath);
>
> return ret;
> }
> }
[Severity: Medium]
This is a pre-existing issue, but does this initial error path leak the
acquired device node reference?
If mtk_drm_of_get_ddp_ep_cid() fails but still sets next, the code logs an
error and returns ret directly.
It doesn't appear to call of_node_put(next) before returning, which would
leave the reference dangling.
[ ... ]
> do {
> prev = next;
> ret = mtk_drm_of_get_ddp_ep_cid(next, 1, cpath, &next, &temp_path[idx]);
> of_node_put(prev);
> if (ret) {
> of_node_put(next);
> break;
> }
[Severity: High]
This is a pre-existing issue, but can this error path trigger a double-put of
the device node?
If mtk_drm_of_get_ddp_ep_cid() fails early (for example, returning -ENOENT)
without updating the next pointer, next will still point to prev.
The loop calls of_node_put(prev), and since ret is non-zero, it also
calls of_node_put(next). This would decrement the refcount of the same node
twice.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260819065642.136222-1-lihaojie@kylinos.cn?part=1
next prev parent reply other threads:[~2026-08-19 7:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-19 6:56 [PATCH] drm/mediatek: Add missing IS_ERR check for ovl_adaptor platform device Haojie Li
2026-08-19 7:07 ` sashiko-bot [this message]
2026-08-25 6:23 ` CK Hu (胡俊光)
2026-08-25 10:08 ` [PATCH v2] " Haojie Li
2026-08-25 10:20 ` sashiko-bot
2026-08-26 6:50 ` CK Hu (胡俊光)
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=20260819070753.5B0901F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=lihaojie@kylinos.cn \
--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