* [PATCH] media: platform: mtk-mdp3: fix device leaks at probe
@ 2025-09-24 14:39 Johan Hovold
2025-09-25 13:44 ` AngeloGioacchino Del Regno
0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2025-09-24 14:39 UTC (permalink / raw)
To: Mauro Carvalho Chehab
Cc: Matthias Brugger, AngeloGioacchino Del Regno, Hans Verkuil,
linux-media, linux-mediatek, linux-kernel, Johan Hovold, stable,
Moudy Ho
Make sure to drop the references taken when looking up the subsys
devices during probe on probe failure (e.g. probe deferral) and on
driver unbind.
Similarly, drop the SCP device reference after retrieving its platform
data during probe to avoid leaking it.
Note that holding a reference to a device does not prevent its driver
data from going away.
Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 driver")
Cc: stable@vger.kernel.org # 6.1
Cc: Moudy Ho <moudy.ho@mediatek.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
.../media/platform/mediatek/mdp3/mtk-mdp3-core.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c
index 8de2c8e4d333..fc117a6a822c 100644
--- a/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c
+++ b/drivers/media/platform/mediatek/mdp3/mtk-mdp3-core.c
@@ -157,10 +157,18 @@ void mdp_video_device_release(struct video_device *vdev)
kfree(mdp);
}
+static void mdp_put_device(void *_dev)
+{
+ struct device *dev = _dev;
+
+ put_device(dev);
+}
+
static int mdp_mm_subsys_deploy(struct mdp_dev *mdp, enum mdp_infra_id id)
{
struct platform_device *mm_pdev = NULL;
struct device **dev;
+ int ret;
int i;
if (!mdp)
@@ -194,6 +202,11 @@ static int mdp_mm_subsys_deploy(struct mdp_dev *mdp, enum mdp_infra_id id)
if (WARN_ON(!mm_pdev))
return -ENODEV;
+ ret = devm_add_action_or_reset(&mdp->pdev->dev, mdp_put_device,
+ &mm_pdev->dev);
+ if (ret)
+ return ret;
+
*dev = &mm_pdev->dev;
}
@@ -279,6 +292,7 @@ static int mdp_probe(struct platform_device *pdev)
goto err_destroy_clock_wq;
}
mdp->scp = platform_get_drvdata(mm_pdev);
+ put_device(&mm_pdev->dev);
}
mdp->rproc_handle = scp_get_rproc(mdp->scp);
--
2.49.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] media: platform: mtk-mdp3: fix device leaks at probe
2025-09-24 14:39 [PATCH] media: platform: mtk-mdp3: fix device leaks at probe Johan Hovold
@ 2025-09-25 13:44 ` AngeloGioacchino Del Regno
0 siblings, 0 replies; 2+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-09-25 13:44 UTC (permalink / raw)
To: Johan Hovold, Mauro Carvalho Chehab
Cc: Matthias Brugger, Hans Verkuil, linux-media, linux-mediatek,
linux-kernel, stable, Moudy Ho
Il 24/09/25 16:39, Johan Hovold ha scritto:
> Make sure to drop the references taken when looking up the subsys
> devices during probe on probe failure (e.g. probe deferral) and on
> driver unbind.
>
> Similarly, drop the SCP device reference after retrieving its platform
> data during probe to avoid leaking it.
>
> Note that holding a reference to a device does not prevent its driver
> data from going away.
>
> Fixes: 61890ccaefaf ("media: platform: mtk-mdp3: add MediaTek MDP3 driver")
> Cc: stable@vger.kernel.org # 6.1
> Cc: Moudy Ho <moudy.ho@mediatek.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-25 13:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-24 14:39 [PATCH] media: platform: mtk-mdp3: fix device leaks at probe Johan Hovold
2025-09-25 13:44 ` AngeloGioacchino Del Regno
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox