* [PATCH] drm/mediatek: fix device leaks at bind
@ 2025-07-22 9:27 Johan Hovold
2025-08-06 7:13 ` CK Hu (胡俊光)
2025-08-27 9:51 ` Johan Hovold
0 siblings, 2 replies; 6+ messages in thread
From: Johan Hovold @ 2025-07-22 9:27 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-arm-kernel, linux-kernel, Johan Hovold, stable, Nancy.Lin
Make sure to drop the references to the sibling platform devices and
their child drm devices taken by of_find_device_by_node() and
device_find_child() when initialising the driver data during bind().
Fixes: 1ef7ed48356c ("drm/mediatek: Modify mediatek-drm for mt8195 multi mmsys support")
Cc: stable@vger.kernel.org # 6.4
Cc: Nancy.Lin <nancy.lin@mediatek.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpu/drm/mediatek/mtk_drm_drv.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 7c0c12dde488..33b83576af7e 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -395,10 +395,12 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
continue;
drm_dev = device_find_child(&pdev->dev, NULL, mtk_drm_match);
+ put_device(&pdev->dev);
if (!drm_dev)
continue;
temp_drm_priv = dev_get_drvdata(drm_dev);
+ put_device(drm_dev);
if (!temp_drm_priv)
continue;
--
2.49.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/mediatek: fix device leaks at bind
2025-07-22 9:27 [PATCH] drm/mediatek: fix device leaks at bind Johan Hovold
@ 2025-08-06 7:13 ` CK Hu (胡俊光)
2025-08-27 9:51 ` Johan Hovold
1 sibling, 0 replies; 6+ messages in thread
From: CK Hu (胡俊光) @ 2025-08-06 7:13 UTC (permalink / raw)
To: p.zabel@pengutronix.de, chunkuang.hu@kernel.org, johan@kernel.org
Cc: Nancy Lin (林欣螢), simona@ffwll.ch,
dri-devel@lists.freedesktop.org, AngeloGioacchino Del Regno,
airlied@gmail.com, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, matthias.bgg@gmail.com,
linux-mediatek@lists.infradead.org, stable@vger.kernel.org
On Tue, 2025-07-22 at 11:27 +0200, Johan Hovold wrote:
> External email : Please do not click links or open attachments until you have verified the sender or the content.
>
>
> Make sure to drop the references to the sibling platform devices and
> their child drm devices taken by of_find_device_by_node() and
> device_find_child() when initialising the driver data during bind().
Reviewed-by: CK Hu <ck.hu@mediatek.com>
>
> Fixes: 1ef7ed48356c ("drm/mediatek: Modify mediatek-drm for mt8195 multi mmsys support")
> Cc: stable@vger.kernel.org # 6.4
> Cc: Nancy.Lin <nancy.lin@mediatek.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
> drivers/gpu/drm/mediatek/mtk_drm_drv.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index 7c0c12dde488..33b83576af7e 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -395,10 +395,12 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
> continue;
>
> drm_dev = device_find_child(&pdev->dev, NULL, mtk_drm_match);
> + put_device(&pdev->dev);
> if (!drm_dev)
> continue;
>
> temp_drm_priv = dev_get_drvdata(drm_dev);
> + put_device(drm_dev);
> if (!temp_drm_priv)
> continue;
>
> --
> 2.49.1
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/mediatek: fix device leaks at bind
2025-07-22 9:27 [PATCH] drm/mediatek: fix device leaks at bind Johan Hovold
2025-08-06 7:13 ` CK Hu (胡俊光)
@ 2025-08-27 9:51 ` Johan Hovold
2025-08-28 23:51 ` Chun-Kuang Hu
1 sibling, 1 reply; 6+ messages in thread
From: Johan Hovold @ 2025-08-27 9:51 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-arm-kernel, linux-kernel, stable, Nancy.Lin
On Tue, Jul 22, 2025 at 11:27:22AM +0200, Johan Hovold wrote:
> Make sure to drop the references to the sibling platform devices and
> their child drm devices taken by of_find_device_by_node() and
> device_find_child() when initialising the driver data during bind().
>
> Fixes: 1ef7ed48356c ("drm/mediatek: Modify mediatek-drm for mt8195 multi mmsys support")
> Cc: stable@vger.kernel.org # 6.4
> Cc: Nancy.Lin <nancy.lin@mediatek.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
Can this one be picked up?
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/mediatek: fix device leaks at bind
2025-08-27 9:51 ` Johan Hovold
@ 2025-08-28 23:51 ` Chun-Kuang Hu
2025-08-29 7:49 ` Johan Hovold
0 siblings, 1 reply; 6+ messages in thread
From: Chun-Kuang Hu @ 2025-08-28 23:51 UTC (permalink / raw)
To: Johan Hovold
Cc: Chun-Kuang Hu, Philipp Zabel, David Airlie, Simona Vetter,
Matthias Brugger, AngeloGioacchino Del Regno, dri-devel,
linux-mediatek, linux-arm-kernel, linux-kernel, stable, Nancy.Lin
Hi, Johan:
Johan Hovold <johan@kernel.org> 於 2025年8月27日 週三 下午5:51寫道:
>
> On Tue, Jul 22, 2025 at 11:27:22AM +0200, Johan Hovold wrote:
> > Make sure to drop the references to the sibling platform devices and
> > their child drm devices taken by of_find_device_by_node() and
> > device_find_child() when initialising the driver data during bind().
> >
> > Fixes: 1ef7ed48356c ("drm/mediatek: Modify mediatek-drm for mt8195 multi mmsys support")
> > Cc: stable@vger.kernel.org # 6.4
> > Cc: Nancy.Lin <nancy.lin@mediatek.com>
> > Signed-off-by: Johan Hovold <johan@kernel.org>
>
> Can this one be picked up?
Ma Ke has sent a similar patch [1] before you. And that patch fix more things.
I've already pick up the final version [2].
[1] https://patchwork.kernel.org/project/dri-devel/patch/20250718033226.3390054-1-make24@iscas.ac.cn/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/commit/?h=mediatek-drm-fixes-20250825&id=1f403699c40f0806a707a9a6eed3b8904224021a
Regards,
Chun-Kuang.
>
> Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/mediatek: fix device leaks at bind
2025-08-28 23:51 ` Chun-Kuang Hu
@ 2025-08-29 7:49 ` Johan Hovold
2025-08-29 7:53 ` Johan Hovold
0 siblings, 1 reply; 6+ messages in thread
From: Johan Hovold @ 2025-08-29 7:49 UTC (permalink / raw)
To: Chun-Kuang Hu
Cc: Philipp Zabel, David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-arm-kernel, linux-kernel, stable, Nancy.Lin
On Fri, Aug 29, 2025 at 07:51:23AM +0800, Chun-Kuang Hu wrote:
> Johan Hovold <johan@kernel.org> 於 2025年8月27日 週三 下午5:51寫道:
> > On Tue, Jul 22, 2025 at 11:27:22AM +0200, Johan Hovold wrote:
> > > Make sure to drop the references to the sibling platform devices and
> > > their child drm devices taken by of_find_device_by_node() and
> > > device_find_child() when initialising the driver data during bind().
> > >
> > > Fixes: 1ef7ed48356c ("drm/mediatek: Modify mediatek-drm for mt8195 multi mmsys support")
> > > Cc: stable@vger.kernel.org # 6.4
> > > Cc: Nancy.Lin <nancy.lin@mediatek.com>
> > > Signed-off-by: Johan Hovold <johan@kernel.org>
> >
> > Can this one be picked up?
>
> Ma Ke has sent a similar patch [1] before you. And that patch fix more things.
> I've already pick up the final version [2].
>
> [1] https://patchwork.kernel.org/project/dri-devel/patch/20250718033226.3390054-1-make24@iscas.ac.cn/
> [2] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/commit/?h=mediatek-drm-fixes-20250825&id=1f403699c40f0806a707a9a6eed3b8904224021a
I'm afraid that patch is completely broken and introduces a potential
use-after-free by adding a bogus decrement of the OF node refcount.
I suggest you drop that one and pick up mine instead which is correct
and cleaner.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/mediatek: fix device leaks at bind
2025-08-29 7:49 ` Johan Hovold
@ 2025-08-29 7:53 ` Johan Hovold
0 siblings, 0 replies; 6+ messages in thread
From: Johan Hovold @ 2025-08-29 7:53 UTC (permalink / raw)
To: Chun-Kuang Hu
Cc: Philipp Zabel, David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-arm-kernel, linux-kernel, stable, Nancy.Lin
On Fri, Aug 29, 2025 at 09:49:07AM +0200, Johan Hovold wrote:
> On Fri, Aug 29, 2025 at 07:51:23AM +0800, Chun-Kuang Hu wrote:
> > Johan Hovold <johan@kernel.org> 於 2025年8月27日 週三 下午5:51寫道:
>
> > > On Tue, Jul 22, 2025 at 11:27:22AM +0200, Johan Hovold wrote:
> > > > Make sure to drop the references to the sibling platform devices and
> > > > their child drm devices taken by of_find_device_by_node() and
> > > > device_find_child() when initialising the driver data during bind().
> > > >
> > > > Fixes: 1ef7ed48356c ("drm/mediatek: Modify mediatek-drm for mt8195 multi mmsys support")
> > > > Cc: stable@vger.kernel.org # 6.4
> > > > Cc: Nancy.Lin <nancy.lin@mediatek.com>
> > > > Signed-off-by: Johan Hovold <johan@kernel.org>
> > >
> > > Can this one be picked up?
> >
> > Ma Ke has sent a similar patch [1] before you. And that patch fix more things.
> > I've already pick up the final version [2].
> >
> > [1] https://patchwork.kernel.org/project/dri-devel/patch/20250718033226.3390054-1-make24@iscas.ac.cn/
> > [2] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/commit/?h=mediatek-drm-fixes-20250825&id=1f403699c40f0806a707a9a6eed3b8904224021a
>
> I'm afraid that patch is completely broken and introduces a potential
> use-after-free by adding a bogus decrement of the OF node refcount.
>
> I suggest you drop that one and pick up mine instead which is correct
> and cleaner.
I see now that that patch was included in a drm pull request for rc4.
I'll send an incremental fix instead.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-08-29 8:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-22 9:27 [PATCH] drm/mediatek: fix device leaks at bind Johan Hovold
2025-08-06 7:13 ` CK Hu (胡俊光)
2025-08-27 9:51 ` Johan Hovold
2025-08-28 23:51 ` Chun-Kuang Hu
2025-08-29 7:49 ` Johan Hovold
2025-08-29 7:53 ` Johan Hovold
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).