Skip to content

Commit b2fbe0f

Browse files
jhovoldgregkh
authored andcommitted
drm/mediatek: fix potential OF node use-after-free
commit 4de37a4 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 6632845 commit b2fbe0f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

drivers/gpu/drm/mediatek/mtk_drm_drv.c

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

366366
of_id = of_match_node(mtk_drm_of_ids, node);
367367
if (!of_id)
368-
goto next_put_node;
368+
continue;
369369

370370
pdev = of_find_device_by_node(node);
371371
if (!pdev)
372-
goto next_put_node;
372+
continue;
373373

374374
drm_dev = device_find_child(&pdev->dev, NULL, mtk_drm_match);
375375
if (!drm_dev)
@@ -395,11 +395,10 @@ static bool mtk_drm_get_all_drm_priv(struct device *dev)
395395
next_put_device_pdev_dev:
396396
put_device(&pdev->dev);
397397

398-
next_put_node:
399-
of_node_put(node);
400-
401-
if (cnt == MAX_CRTC)
398+
if (cnt == MAX_CRTC) {
399+
of_node_put(node);
402400
break;
401+
}
403402
}
404403

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

0 commit comments

Comments
 (0)