Skip to content

Commit ef693a8

Browse files
Guenter Roeckjoergroedel
authored andcommitted
iommu/mediatek: Validate number of phandles associated with "mediatek,larbs"
Fix the smatch warnings: drivers/iommu/mtk_iommu.c:878 mtk_iommu_mm_dts_parse() error: uninitialized symbol 'larbnode'. If someone abuse the dtsi node(Don't follow the definition of dt-binding), for example "mediatek,larbs" is provided as boolean property, "larb_nr" will be zero and cause abnormal. To fix this problem and improve the code safety, add some checking for the invalid input from dtsi, e.g. checking the larb_nr/larbid valid range, and avoid "mediatek,larb-id" property conflicts in the smi-larb nodes. Fixes: d2e9a11 ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE") Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> 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 2659392 commit ef693a8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,8 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
10621062
larb_nr = of_count_phandle_with_args(dev->of_node, "mediatek,larbs", NULL);
10631063
if (larb_nr < 0)
10641064
return larb_nr;
1065+
if (larb_nr == 0 || larb_nr > MTK_LARB_NR_MAX)
1066+
return -EINVAL;
10651067

10661068
for (i = 0; i < larb_nr; i++) {
10671069
u32 id;
@@ -1080,13 +1082,23 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
10801082
ret = of_property_read_u32(larbnode, "mediatek,larb-id", &id);
10811083
if (ret)/* The id is consecutive if there is no this property */
10821084
id = i;
1085+
if (id >= MTK_LARB_NR_MAX) {
1086+
of_node_put(larbnode);
1087+
ret = -EINVAL;
1088+
goto err_larbdev_put;
1089+
}
10831090

10841091
plarbdev = of_find_device_by_node(larbnode);
10851092
of_node_put(larbnode);
10861093
if (!plarbdev) {
10871094
ret = -ENODEV;
10881095
goto err_larbdev_put;
10891096
}
1097+
if (data->larb_imu[id].dev) {
1098+
platform_device_put(plarbdev);
1099+
ret = -EEXIST;
1100+
goto err_larbdev_put;
1101+
}
10901102
data->larb_imu[id].dev = &plarbdev->dev;
10911103

10921104
if (!plarbdev->dev.driver) {

0 commit comments

Comments
 (0)