Skip to content

Commit 5429116

Browse files
jhovoldgregkh
authored andcommitted
drm/mediatek: Fix probe resource leaks
commit 07c7c64 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4fcb7f8 commit 5429116

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
@@ -1123,7 +1123,7 @@ static int mtk_drm_probe(struct platform_device *pdev)
11231123
(void *)private->mmsys_dev,
11241124
sizeof(*private->mmsys_dev));
11251125
private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR].dev = &ovl_adaptor->dev;
1126-
mtk_ddp_comp_init(NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
1126+
mtk_ddp_comp_init(dev, NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
11271127
DDP_COMPONENT_DRM_OVL_ADAPTOR);
11281128
component_match_add(dev, &match, compare_dev, &ovl_adaptor->dev);
11291129
}
@@ -1189,7 +1189,7 @@ static int mtk_drm_probe(struct platform_device *pdev)
11891189
node);
11901190
}
11911191

1192-
ret = mtk_ddp_comp_init(node, &private->ddp_comp[comp_id], comp_id);
1192+
ret = mtk_ddp_comp_init(dev, node, &private->ddp_comp[comp_id], comp_id);
11931193
if (ret) {
11941194
of_node_put(node);
11951195
goto err_node;

0 commit comments

Comments
 (0)