Skip to content

Commit 2659392

Browse files
YongWu-HFjoergroedel
authored andcommitted
iommu/mediatek: Add error path for loop of mm_dts_parse
The mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the i+1 larb is parsed fail, we should put_device for the i..0 larbs. There are two places need to comment: 1) The larbid may be not linear mapping, we should loop whole the array in the error path. 2) I move this line position: "data->larb_imu[id].dev = &plarbdev->dev;" before "if (!plarbdev->dev.driver)", That means set data->larb_imu[id].dev before the error path. then we don't need "platform_device_put(plarbdev)" again in probe_defer case. All depend on "put_device" of the error path in error cases. Fixes: d2e9a11 ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Signed-off-by: Yong Wu <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent b5765a1 commit 2659392

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,8 +1067,10 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
10671067
u32 id;
10681068

10691069
larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i);
1070-
if (!larbnode)
1071-
return -EINVAL;
1070+
if (!larbnode) {
1071+
ret = -EINVAL;
1072+
goto err_larbdev_put;
1073+
}
10721074

10731075
if (!of_device_is_available(larbnode)) {
10741076
of_node_put(larbnode);
@@ -1081,14 +1083,16 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
10811083

10821084
plarbdev = of_find_device_by_node(larbnode);
10831085
of_node_put(larbnode);
1084-
if (!plarbdev)
1085-
return -ENODEV;
1086+
if (!plarbdev) {
1087+
ret = -ENODEV;
1088+
goto err_larbdev_put;
1089+
}
1090+
data->larb_imu[id].dev = &plarbdev->dev;
10861091

10871092
if (!plarbdev->dev.driver) {
1088-
platform_device_put(plarbdev);
1089-
return -EPROBE_DEFER;
1093+
ret = -EPROBE_DEFER;
1094+
goto err_larbdev_put;
10901095
}
1091-
data->larb_imu[id].dev = &plarbdev->dev;
10921096

10931097
component_match_add(dev, match, component_compare_dev, &plarbdev->dev);
10941098
platform_device_put(plarbdev);
@@ -1123,6 +1127,15 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
11231127
return -EINVAL;
11241128
}
11251129
return 0;
1130+
1131+
err_larbdev_put:
1132+
/* id may be not linear mapping, loop whole the array */
1133+
for (i = MTK_LARB_NR_MAX - 1; i >= 0; i++) {
1134+
if (!data->larb_imu[i].dev)
1135+
continue;
1136+
put_device(data->larb_imu[i].dev);
1137+
}
1138+
return ret;
11261139
}
11271140

11281141
static int mtk_iommu_probe(struct platform_device *pdev)

0 commit comments

Comments
 (0)