Skip to content

Commit 4de37a4

Browse files
jhovoldChun-Kuang Hu
authored andcommitted
drm/mediatek: fix potential OF node use-after-free
The for_each_child_of_node() helper drops the reference it takes to each node as it iterates over children and an explicit of_node_put() is only needed when exiting the loop early. Drop the recently introduced bogus additional reference count decrement at each iteration that could potentially lead to a use-after-free. Fixes: 1f40369 ("drm/mediatek: Fix device/node reference count leaks in mtk_drm_get_all_drm_priv") Cc: Ma Ke <make24@iscas.ac.cn> Cc: stable@vger.kernel.org Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: CK Hu <ck.hu@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://patchwork.kernel.org/project/dri-devel/patch/20250829090345.21075-2-johan@kernel.org/ Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
1 parent c344148 commit 4de37a4

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

drivers/gpu/drm/mediatek/mtk_drm_drv.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,11 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
387387

388388
of_id = of_match_node(mtk_drm_of_ids, node);
389389
if (!of_id)
390-
goto next_put_node;
390+
continue;
391391

392392
pdev = of_find_device_by_node(node);
393393
if (!pdev)
394-
goto next_put_node;
394+
continue;
395395

396396
drm_dev = device_find_child(&pdev->dev, NULL, mtk_drm_match);
397397
if (!drm_dev)
@@ -417,11 +417,10 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
417417
next_put_device_pdev_dev:
418418
put_device(&pdev->dev);
419419

420-
next_put_node:
421-
of_node_put(node);
422-
423-
if (cnt == MAX_CRTC)
420+
if (cnt == MAX_CRTC) {
421+
of_node_put(node);
424422
break;
423+
}
425424
}
426425

427426
if (drm_priv->data->mmsys_dev_num == cnt) {

0 commit comments

Comments
 (0)