* [PATCH 1/5] drm/mediatek: fix probe resource leaks
2025-09-23 15:23 [PATCH 0/5] drm/mediatek: fix probe resource leaks Johan Hovold
@ 2025-09-23 15:23 ` Johan Hovold
2025-09-23 15:23 ` [PATCH 2/5] drm/mediatek: fix probe memory leak Johan Hovold
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2025-09-23 15:23 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-kernel, Johan Hovold, stable, CK Hu
Make sure to unmap and release the component iomap and clock on probe
failure (e.g. probe deferral) and on driver unbind.
Note that unlike of_iomap(), devm_of_iomap() also checks whether the
region is already mapped.
Fixes: 119f5173628a ("drm/mediatek: Add DRM Driver for Mediatek SoC MT8173.")
Cc: stable@vger.kernel.org # 4.7
Cc: CK Hu <ck.hu@mediatek.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpu/drm/mediatek/mtk_ddp_comp.c | 20 ++++++++++++++++----
drivers/gpu/drm/mediatek/mtk_ddp_comp.h | 2 +-
drivers/gpu/drm/mediatek/mtk_drm_drv.c | 4 ++--
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
index ac6620e10262..0264017806ad 100644
--- a/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
@@ -621,15 +621,20 @@ int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev)
return ret;
}
-int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
+static void mtk_ddp_comp_clk_put(void *_clk)
+{
+ struct clk *clk = _clk;
+
+ clk_put(clk);
+}
+
+int mtk_ddp_comp_init(struct device *dev, struct device_node *node, struct mtk_ddp_comp *comp,
unsigned int comp_id)
{
struct platform_device *comp_pdev;
enum mtk_ddp_comp_type type;
struct mtk_ddp_comp_dev *priv;
-#if IS_REACHABLE(CONFIG_MTK_CMDQ)
int ret;
-#endif
if (comp_id >= DDP_COMPONENT_DRM_ID_MAX)
return -EINVAL;
@@ -670,11 +675,18 @@ int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
if (!priv)
return -ENOMEM;
- priv->regs = of_iomap(node, 0);
+ priv->regs = devm_of_iomap(dev, node, 0, NULL);
+ if (IS_ERR(priv->regs))
+ return PTR_ERR(priv->regs);
+
priv->clk = of_clk_get(node, 0);
if (IS_ERR(priv->clk))
return PTR_ERR(priv->clk);
+ ret = devm_add_action_or_reset(dev, mtk_ddp_comp_clk_put, priv->clk);
+ if (ret)
+ return ret;
+
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
ret = cmdq_dev_get_client_reg(comp->dev, &priv->cmdq_reg, 0);
if (ret)
diff --git a/drivers/gpu/drm/mediatek/mtk_ddp_comp.h b/drivers/gpu/drm/mediatek/mtk_ddp_comp.h
index 7289b3dcf22f..3f3d43f4330d 100644
--- a/drivers/gpu/drm/mediatek/mtk_ddp_comp.h
+++ b/drivers/gpu/drm/mediatek/mtk_ddp_comp.h
@@ -350,7 +350,7 @@ static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
int mtk_ddp_comp_get_id(struct device_node *node,
enum mtk_ddp_comp_type comp_type);
int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev);
-int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
+int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node, struct mtk_ddp_comp *comp,
unsigned int comp_id);
enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index eb5537f0ac90..384b0510272c 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -1133,7 +1133,7 @@ static int mtk_drm_probe(struct platform_device *pdev)
(void *)private->mmsys_dev,
sizeof(*private->mmsys_dev));
private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR].dev = &ovl_adaptor->dev;
- mtk_ddp_comp_init(NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
+ mtk_ddp_comp_init(dev, NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
DDP_COMPONENT_DRM_OVL_ADAPTOR);
component_match_add(dev, &match, compare_dev, &ovl_adaptor->dev);
}
@@ -1199,7 +1199,7 @@ static int mtk_drm_probe(struct platform_device *pdev)
node);
}
- ret = mtk_ddp_comp_init(node, &private->ddp_comp[comp_id], comp_id);
+ ret = mtk_ddp_comp_init(dev, node, &private->ddp_comp[comp_id], comp_id);
if (ret) {
of_node_put(node);
goto err_node;
--
2.49.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 2/5] drm/mediatek: fix probe memory leak
2025-09-23 15:23 [PATCH 0/5] drm/mediatek: fix probe resource leaks Johan Hovold
2025-09-23 15:23 ` [PATCH 1/5] " Johan Hovold
@ 2025-09-23 15:23 ` Johan Hovold
2025-09-23 15:23 ` [PATCH 3/5] drm/mediatek: fix probe device leaks Johan Hovold
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2025-09-23 15:23 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-kernel, Johan Hovold, stable, CK Hu
The Mediatek DRM driver allocates private data for components without a
platform driver but as the lifetime is tied to each component device,
the memory is never freed.
Tie the allocation lifetime to the DRM platform device so that the
memory is released on probe failure (e.g. probe deferral) and when the
driver is unbound.
Fixes: c0d36de868a6 ("drm/mediatek: Move clk info from struct mtk_ddp_comp to sub driver private data")
Cc: stable@vger.kernel.org # 5.12
Cc: CK Hu <ck.hu@mediatek.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpu/drm/mediatek/mtk_ddp_comp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/mediatek/mtk_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
index 0264017806ad..31d67a131c50 100644
--- a/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
@@ -671,7 +671,7 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node, struct mtk_d
type == MTK_DSI)
return 0;
- priv = devm_kzalloc(comp->dev, sizeof(*priv), GFP_KERNEL);
+ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
--
2.49.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 3/5] drm/mediatek: fix probe device leaks
2025-09-23 15:23 [PATCH 0/5] drm/mediatek: fix probe resource leaks Johan Hovold
2025-09-23 15:23 ` [PATCH 1/5] " Johan Hovold
2025-09-23 15:23 ` [PATCH 2/5] drm/mediatek: fix probe memory leak Johan Hovold
@ 2025-09-23 15:23 ` Johan Hovold
2025-09-23 15:23 ` [PATCH 4/5] drm/mediatek: mtk_hdmi: " Johan Hovold
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2025-09-23 15:23 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-kernel, Johan Hovold, stable
Make sure to drop the reference taken to each component device during
probe on probe failure (e.g. probe deferral) and on driver unbind.
Fixes: 6ea6f8276725 ("drm/mediatek: Use correct device pointer to get CMDQ client register")
Cc: stable@vger.kernel.org # 5.12
Cc: Chun-Kuang Hu <chunkuang.hu@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpu/drm/mediatek/mtk_ddp_comp.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/gpu/drm/mediatek/mtk_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
index 31d67a131c50..9672ea1f91a2 100644
--- a/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_ddp_comp.c
@@ -621,6 +621,13 @@ int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev)
return ret;
}
+static void mtk_ddp_comp_put_device(void *_dev)
+{
+ struct device *dev = _dev;
+
+ put_device(dev);
+}
+
static void mtk_ddp_comp_clk_put(void *_clk)
{
struct clk *clk = _clk;
@@ -656,6 +663,10 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *node, struct mtk_d
}
comp->dev = &comp_pdev->dev;
+ ret = devm_add_action_or_reset(dev, mtk_ddp_comp_put_device, comp->dev);
+ if (ret)
+ return ret;
+
if (type == MTK_DISP_AAL ||
type == MTK_DISP_BLS ||
type == MTK_DISP_CCORR ||
--
2.49.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 4/5] drm/mediatek: mtk_hdmi: fix probe device leaks
2025-09-23 15:23 [PATCH 0/5] drm/mediatek: fix probe resource leaks Johan Hovold
` (2 preceding siblings ...)
2025-09-23 15:23 ` [PATCH 3/5] drm/mediatek: fix probe device leaks Johan Hovold
@ 2025-09-23 15:23 ` Johan Hovold
2025-09-23 15:23 ` [PATCH 5/5] drm/mediatek: ovl_adaptor: " Johan Hovold
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2025-09-23 15:23 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-kernel, Johan Hovold, stable, Jie Qiu
Make sure to drop the references to the DDC adapter and CEC device
taken during probe on probe failure (e.g. probe deferral) and on driver
unbind.
Fixes: 8f83f26891e1 ("drm/mediatek: Add HDMI support")
Cc: stable@vger.kernel.org # 4.8
Cc: Jie Qiu <jie.qiu@mediatek.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/gpu/drm/mediatek/mtk_hdmi.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/gpu/drm/mediatek/mtk_hdmi.c b/drivers/gpu/drm/mediatek/mtk_hdmi.c
index b766dd5e6c8d..306e2c907311 100644
--- a/drivers/gpu/drm/mediatek/mtk_hdmi.c
+++ b/drivers/gpu/drm/mediatek/mtk_hdmi.c
@@ -1345,6 +1345,13 @@ static const struct drm_bridge_funcs mtk_hdmi_bridge_funcs = {
.edid_read = mtk_hdmi_bridge_edid_read,
};
+static void mtk_hdmi_put_device(void *_dev)
+{
+ struct device *dev = _dev;
+
+ put_device(dev);
+}
+
static int mtk_hdmi_get_cec_dev(struct mtk_hdmi *hdmi, struct device *dev, struct device_node *np)
{
struct platform_device *cec_pdev;
@@ -1369,6 +1376,10 @@ static int mtk_hdmi_get_cec_dev(struct mtk_hdmi *hdmi, struct device *dev, struc
}
of_node_put(cec_np);
+ ret = devm_add_action_or_reset(dev, mtk_hdmi_put_device, &cec_pdev->dev);
+ if (ret)
+ return ret;
+
/*
* The mediatek,syscon-hdmi property contains a phandle link to the
* MMSYS_CONFIG device and the register offset of the HDMI_SYS_CFG
@@ -1423,6 +1434,10 @@ static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
if (!hdmi->ddc_adpt)
return dev_err_probe(dev, -EINVAL, "Failed to get ddc i2c adapter by node\n");
+ ret = devm_add_action_or_reset(dev, mtk_hdmi_put_device, &hdmi->ddc_adpt->dev);
+ if (ret)
+ return ret;
+
ret = mtk_hdmi_get_cec_dev(hdmi, dev, np);
if (ret)
return ret;
--
2.49.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH 5/5] drm/mediatek: ovl_adaptor: fix probe device leaks
2025-09-23 15:23 [PATCH 0/5] drm/mediatek: fix probe resource leaks Johan Hovold
` (3 preceding siblings ...)
2025-09-23 15:23 ` [PATCH 4/5] drm/mediatek: mtk_hdmi: " Johan Hovold
@ 2025-09-23 15:23 ` Johan Hovold
2025-09-24 10:39 ` [PATCH 0/5] drm/mediatek: fix probe resource leaks AngeloGioacchino Del Regno
2025-10-27 13:34 ` Johan Hovold
6 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2025-09-23 15:23 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-kernel, Johan Hovold, stable, Nancy.Lin
Make sure to drop the references taken to the component devices by
of_find_device_by_node() during probe on probe failure (e.g. probe
deferral) and on driver unbind.
Fixes: 453c3364632a ("drm/mediatek: Add ovl_adaptor support for MT8195")
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_disp_ovl_adaptor.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c b/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c
index fe97bb97e004..c0af3e3b51d5 100644
--- a/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c
+++ b/drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c
@@ -527,6 +527,13 @@ bool mtk_ovl_adaptor_is_comp_present(struct device_node *node)
type == OVL_ADAPTOR_TYPE_PADDING;
}
+static void ovl_adaptor_put_device(void *_dev)
+{
+ struct device *dev = _dev;
+
+ put_device(dev);
+}
+
static int ovl_adaptor_comp_init(struct device *dev, struct component_match **match)
{
struct mtk_disp_ovl_adaptor *priv = dev_get_drvdata(dev);
@@ -560,6 +567,11 @@ static int ovl_adaptor_comp_init(struct device *dev, struct component_match **ma
if (!comp_pdev)
return -EPROBE_DEFER;
+ ret = devm_add_action_or_reset(dev, ovl_adaptor_put_device,
+ &comp_pdev->dev);
+ if (ret)
+ return ret;
+
priv->ovl_adaptor_comp[id] = &comp_pdev->dev;
drm_of_component_match_add(dev, match, component_compare_of, node);
--
2.49.1
^ permalink raw reply related [flat|nested] 8+ messages in thread* Re: [PATCH 0/5] drm/mediatek: fix probe resource leaks
2025-09-23 15:23 [PATCH 0/5] drm/mediatek: fix probe resource leaks Johan Hovold
` (4 preceding siblings ...)
2025-09-23 15:23 ` [PATCH 5/5] drm/mediatek: ovl_adaptor: " Johan Hovold
@ 2025-09-24 10:39 ` AngeloGioacchino Del Regno
2025-10-27 13:34 ` Johan Hovold
6 siblings, 0 replies; 8+ messages in thread
From: AngeloGioacchino Del Regno @ 2025-09-24 10:39 UTC (permalink / raw)
To: Johan Hovold, Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger, dri-devel,
linux-mediatek, linux-kernel
Il 23/09/25 17:23, Johan Hovold ha scritto:
> This series fixes various probe resource leaks in the mediatek drm
> drivers that were found through inspection.
>
> Johan
Whole series is
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [PATCH 0/5] drm/mediatek: fix probe resource leaks
2025-09-23 15:23 [PATCH 0/5] drm/mediatek: fix probe resource leaks Johan Hovold
` (5 preceding siblings ...)
2025-09-24 10:39 ` [PATCH 0/5] drm/mediatek: fix probe resource leaks AngeloGioacchino Del Regno
@ 2025-10-27 13:34 ` Johan Hovold
6 siblings, 0 replies; 8+ messages in thread
From: Johan Hovold @ 2025-10-27 13:34 UTC (permalink / raw)
To: Chun-Kuang Hu, Philipp Zabel
Cc: David Airlie, Simona Vetter, Matthias Brugger,
AngeloGioacchino Del Regno, dri-devel, linux-mediatek,
linux-kernel
On Tue, Sep 23, 2025 at 05:23:35PM +0200, Johan Hovold wrote:
> This series fixes various probe resource leaks in the mediatek drm
> drivers that were found through inspection.
Can these be picked up (for 6.19) as well?
Johan
^ permalink raw reply [flat|nested] 8+ messages in thread