Skip to content

Commit 6cde583

Browse files
YongWu-HFjoergroedel
authored andcommitted
iommu/mediatek: Improve safety for mediatek,smi property in larb nodes
No functional change. Just improve safety from dts. All the larbs that connect to one IOMMU must connect with the same smi-common. This patch checks all the mediatek,smi property for each larb, If their mediatek,smi are different, it will return fails. Also avoid there is no available smi-larb nodes. Suggested-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 ef693a8 commit 6cde583

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ static const struct component_master_ops mtk_iommu_com_ops = {
10541054
static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **match,
10551055
struct mtk_iommu_data *data)
10561056
{
1057-
struct device_node *larbnode, *smicomm_node, *smi_subcomm_node;
1057+
struct device_node *larbnode, *frst_avail_smicomm_node = NULL;
10581058
struct platform_device *plarbdev, *pcommdev;
10591059
struct device_link *link;
10601060
int i, larb_nr, ret;
@@ -1066,6 +1066,7 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
10661066
return -EINVAL;
10671067

10681068
for (i = 0; i < larb_nr; i++) {
1069+
struct device_node *smicomm_node, *smi_subcomm_node;
10691070
u32 id;
10701071

10711072
larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i);
@@ -1106,27 +1107,47 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
11061107
goto err_larbdev_put;
11071108
}
11081109

1110+
/* Get smi-(sub)-common dev from the last larb. */
1111+
smi_subcomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0);
1112+
if (!smi_subcomm_node) {
1113+
ret = -EINVAL;
1114+
goto err_larbdev_put;
1115+
}
1116+
1117+
/*
1118+
* It may have two level smi-common. the node is smi-sub-common if it
1119+
* has a new mediatek,smi property. otherwise it is smi-commmon.
1120+
*/
1121+
smicomm_node = of_parse_phandle(smi_subcomm_node, "mediatek,smi", 0);
1122+
if (smicomm_node)
1123+
of_node_put(smi_subcomm_node);
1124+
else
1125+
smicomm_node = smi_subcomm_node;
1126+
1127+
/*
1128+
* All the larbs that connect to one IOMMU must connect with the same
1129+
* smi-common.
1130+
*/
1131+
if (!frst_avail_smicomm_node) {
1132+
frst_avail_smicomm_node = smicomm_node;
1133+
} else if (frst_avail_smicomm_node != smicomm_node) {
1134+
dev_err(dev, "mediatek,smi property is not right @larb%d.", id);
1135+
of_node_put(smicomm_node);
1136+
ret = -EINVAL;
1137+
goto err_larbdev_put;
1138+
} else {
1139+
of_node_put(smicomm_node);
1140+
}
1141+
11091142
component_match_add(dev, match, component_compare_dev, &plarbdev->dev);
11101143
platform_device_put(plarbdev);
11111144
}
11121145

1113-
/* Get smi-(sub)-common dev from the last larb. */
1114-
smi_subcomm_node = of_parse_phandle(larbnode, "mediatek,smi", 0);
1115-
if (!smi_subcomm_node)
1146+
if (!frst_avail_smicomm_node)
11161147
return -EINVAL;
11171148

1118-
/*
1119-
* It may have two level smi-common. the node is smi-sub-common if it
1120-
* has a new mediatek,smi property. otherwise it is smi-commmon.
1121-
*/
1122-
smicomm_node = of_parse_phandle(smi_subcomm_node, "mediatek,smi", 0);
1123-
if (smicomm_node)
1124-
of_node_put(smi_subcomm_node);
1125-
else
1126-
smicomm_node = smi_subcomm_node;
1127-
1128-
pcommdev = of_find_device_by_node(smicomm_node);
1129-
of_node_put(smicomm_node);
1149+
pcommdev = of_find_device_by_node(frst_avail_smicomm_node);
1150+
of_node_put(frst_avail_smicomm_node);
11301151
if (!pcommdev)
11311152
return -ENODEV;
11321153
data->smicomm_dev = &pcommdev->dev;

0 commit comments

Comments
 (0)