Skip to content

Commit a084253

Browse files
laeyraudgregkh
authored andcommitted
iommu/mediatek: Fix NULL pointer deference in mtk_iommu_device_group
[ Upstream commit 38e8844 ] Currently, mtk_iommu calls during probe iommu_device_register before the hw_list from driver data is initialized. Since iommu probing issue fix, it leads to NULL pointer dereference in mtk_iommu_device_group when hw_list is accessed with list_first_entry (not null safe). So, change the call order to ensure iommu_device_register is called after the driver data are initialized. Fixes: 9e3a2a6 ("iommu/mediatek: Adapt sharing and non-sharing pgtable case") Fixes: bcb81ac ("iommu: Get DT/ACPI parsing into the proper probe path") Reviewed-by: Yong Wu <yong.wu@mediatek.com> Tested-by: Chen-Yu Tsai <wenst@chromium.org> # MT8183 Juniper, MT8186 Tentacruel Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Tested-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com> Link: https://lore.kernel.org/r/20250403-fix-mtk-iommu-error-v2-1-fe8b18f8b0a8@collabora.com Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 5efd539 commit a084253

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,15 +1371,6 @@ static int mtk_iommu_probe(struct platform_device *pdev)
13711371
platform_set_drvdata(pdev, data);
13721372
mutex_init(&data->mutex);
13731373

1374-
ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
1375-
"mtk-iommu.%pa", &ioaddr);
1376-
if (ret)
1377-
goto out_link_remove;
1378-
1379-
ret = iommu_device_register(&data->iommu, &mtk_iommu_ops, dev);
1380-
if (ret)
1381-
goto out_sysfs_remove;
1382-
13831374
if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE)) {
13841375
list_add_tail(&data->list, data->plat_data->hw_list);
13851376
data->hw_list = data->plat_data->hw_list;
@@ -1389,19 +1380,28 @@ static int mtk_iommu_probe(struct platform_device *pdev)
13891380
data->hw_list = &data->hw_list_head;
13901381
}
13911382

1383+
ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
1384+
"mtk-iommu.%pa", &ioaddr);
1385+
if (ret)
1386+
goto out_list_del;
1387+
1388+
ret = iommu_device_register(&data->iommu, &mtk_iommu_ops, dev);
1389+
if (ret)
1390+
goto out_sysfs_remove;
1391+
13921392
if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) {
13931393
ret = component_master_add_with_match(dev, &mtk_iommu_com_ops, match);
13941394
if (ret)
1395-
goto out_list_del;
1395+
goto out_device_unregister;
13961396
}
13971397
return ret;
13981398

1399-
out_list_del:
1400-
list_del(&data->list);
1399+
out_device_unregister:
14011400
iommu_device_unregister(&data->iommu);
14021401
out_sysfs_remove:
14031402
iommu_device_sysfs_remove(&data->iommu);
1404-
out_link_remove:
1403+
out_list_del:
1404+
list_del(&data->list);
14051405
if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM))
14061406
device_link_remove(data->smicomm_dev, dev);
14071407
out_runtime_disable:

0 commit comments

Comments
 (0)