Skip to content

Commit 07c7c64

Browse files
jhovoldChun-Kuang Hu
authored andcommitted
drm/mediatek: Fix probe resource leaks
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: 119f517 ("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> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://patchwork.kernel.org/project/dri-devel/patch/20250923152340.18234-2-johan@kernel.org/ Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
1 parent 65773aa commit 07c7c64

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

drivers/gpu/drm/mediatek/mtk_ddp_comp.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,20 @@ int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev)
621621
return ret;
622622
}
623623

624-
int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
624+
static void mtk_ddp_comp_clk_put(void *_clk)
625+
{
626+
struct clk *clk = _clk;
627+
628+
clk_put(clk);
629+
}
630+
631+
int mtk_ddp_comp_init(struct device *dev, struct device_node *node, struct mtk_ddp_comp *comp,
625632
unsigned int comp_id)
626633
{
627634
struct platform_device *comp_pdev;
628635
enum mtk_ddp_comp_type type;
629636
struct mtk_ddp_comp_dev *priv;
630-
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
631637
int ret;
632-
#endif
633638

634639
if (comp_id >= DDP_COMPONENT_DRM_ID_MAX)
635640
return -EINVAL;
@@ -670,11 +675,18 @@ int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
670675
if (!priv)
671676
return -ENOMEM;
672677

673-
priv->regs = of_iomap(node, 0);
678+
priv->regs = devm_of_iomap(dev, node, 0, NULL);
679+
if (IS_ERR(priv->regs))
680+
return PTR_ERR(priv->regs);
681+
674682
priv->clk = of_clk_get(node, 0);
675683
if (IS_ERR(priv->clk))
676684
return PTR_ERR(priv->clk);
677685

686+
ret = devm_add_action_or_reset(dev, mtk_ddp_comp_clk_put, priv->clk);
687+
if (ret)
688+
return ret;
689+
678690
#if IS_REACHABLE(CONFIG_MTK_CMDQ)
679691
ret = cmdq_dev_get_client_reg(comp->dev, &priv->cmdq_reg, 0);
680692
if (ret)

drivers/gpu/drm/mediatek/mtk_ddp_comp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ static inline void mtk_ddp_comp_encoder_index_set(struct mtk_ddp_comp *comp)
350350
int mtk_ddp_comp_get_id(struct device_node *node,
351351
enum mtk_ddp_comp_type comp_type);
352352
int mtk_find_possible_crtcs(struct drm_device *drm, struct device *dev);
353-
int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
353+
int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node, struct mtk_ddp_comp *comp,
354354
unsigned int comp_id);
355355
enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
356356
void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,

drivers/gpu/drm/mediatek/mtk_drm_drv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ static int mtk_drm_probe(struct platform_device *pdev)
11331133
(void *)private->mmsys_dev,
11341134
sizeof(*private->mmsys_dev));
11351135
private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR].dev = &ovl_adaptor->dev;
1136-
mtk_ddp_comp_init(NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
1136+
mtk_ddp_comp_init(dev, NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
11371137
DDP_COMPONENT_DRM_OVL_ADAPTOR);
11381138
component_match_add(dev, &match, compare_dev, &ovl_adaptor->dev);
11391139
}
@@ -1199,7 +1199,7 @@ static int mtk_drm_probe(struct platform_device *pdev)
11991199
node);
12001200
}
12011201

1202-
ret = mtk_ddp_comp_init(node, &private->ddp_comp[comp_id], comp_id);
1202+
ret = mtk_ddp_comp_init(dev, node, &private->ddp_comp[comp_id], comp_id);
12031203
if (ret) {
12041204
of_node_put(node);
12051205
goto err_node;

0 commit comments

Comments
 (0)