iommu/mediatek: Improve safety from dts
Subsystems (3)
Yong Wu
maintainerv2 cover iommu/mediatek: Improve safety from dts
This patchset contains misc improve patches:
[1/5] When mt8195 v7, I added a error log for dts parse fail, but it doesn't ignore probe_defer case.(v6 doesn't have this err log.) [2/5] Add a error path for MM dts parse.
[3/5][4/5] To improve safety from dts. Base on this:
https://lore.kernel.org/linux-mediatek/[email protected]/
Change notes:
v2: a) Rebase on v5.19-rc1.
b) Add a New patch [5/5] just remove a variable that only is for v1.
v1: https://lore.kernel.org/linux-mediatek/[email protected]/
Base on linux-next-20220510.
Guenter Roeck (1):
iommu/mediatek: Validate number of phandles associated with "mediatek,
larbs"
Yong Wu (4):
iommu/mediatek: Use dev_err_probe to mute probe_defer err log iommu/mediatek: Add error path for loop of mm_dts_parse iommu/mediatek: Improve safety for mediatek, smi property in larb
nodes
iommu/mediatek: Remove a unused "mapping" which is only for v1
drivers/iommu/mtk_iommu.c | 86 +++++++++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 25 deletions(-)
Signature · 7 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu
maintainerPATCH v2 1/5 iommu/mediatek: Use dev_err_probe to mute probe_defer err log
Mute the probe defer log:
[ 2.654806] mtk-iommu 14018000.iommu: mm dts parse fail(-517). [ 2.656168] mtk-iommu 1c01f000.iommu: mm dts parse fail(-517).
--- drivers/iommu/mtk_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/mtk_iommu.c +1 -1
@@ -1204,7 +1204,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_MM )) { ret =mtk_iommu_mm_dts_parse (dev, &match, data);if (ret) { -dev_err (dev,"mm dts parse fail(%d)." , ret); +dev_err_probe (dev, ret,"mm dts parse fail." ); goto out_runtime_disable; } } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA) &&
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 1/5] iommu/mediatek: Use dev_err_probe to mute probe_defer err log
Quoted 9 lines · Yong Wu
Mute the probe defer log:
[ 2.654806] mtk-iommu 14018000.iommu: mm dts parse fail(-517). [ 2.656168] mtk-iommu 1c01f000.iommu: mm dts parse fail(-517).Fixes d2e9a1102cfc ("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 Guenter Roeck <[email protected]>
Quoted 9 lines
--- drivers/iommu/mtk_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iommu/mtk_iommu.c +0
-0
drivers/iommu/mtk_iommu.c static int mtk_iommu_probe(struct platform_device *pdev) · line 1210
Quoted 8 lines
drivers/iommu/mtk_iommu.c +1
-1@@ -1204,7 +1204,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)if (MTK_IOMMU_IS_TYPE (data->plat_data,MTK_IOMMU_TYPE_MM )) { ret =mtk_iommu_mm_dts_parse (dev, &match, data);if (ret) { -dev_err (dev,"mm dts parse fail(%d)." , ret); +dev_err_probe (dev, ret,"mm dts parse fail." ); goto out_runtime_disable; } } else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA) &&
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu
maintainerPATCH v2 2/5 iommu/mediatek: Add error path for loop of mm_dts_parse
In reply to Yong WuThe mtk_iommu_mm_dts_parse will parse the smi larbs nodes. if the i+1 larb is parsed fail(return -EINVAL), we should of_node_put for the 0..i larbs. In the fail path, one of_node_put matches with of_parse_phandle in it.
--- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/iommu/mtk_iommu.c +16 -5
@@ -1071,12 +1071,12 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m plarbdev =of_find_device_by_node (larbnode);if (!plarbdev) { -of_node_put (larbnode); -return -ENODEV ; + ret = -ENODEV ; + goto err_larbnode_put; }if (!plarbdev->dev.driver) { -of_node_put (larbnode); -return -EPROBE_DEFER ; + ret = -EPROBE_DEFER ; + goto err_larbnode_put; } data->larb_imu[id].dev = &plarbdev->dev;
@@ -1107,9 +1107,20 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);if (!link) {dev_err (dev,"Unable to link %s.\n" ,dev_name (data->smicomm_dev)); -return -EINVAL ; + ret = -EINVAL ; + goto err_larbnode_put; }return 0 ; + +err_larbnode_put: +while (i--) { + larbnode =of_parse_phandle (dev->of_node,"mediatek,larbs" , i); +if (larbnode &&of_device_is_available (larbnode)) { +of_node_put (larbnode); +of_node_put (larbnode); + } + } +return ret; }static int mtk_iommu_probe (struct platform_device *pdev)
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Robin Murphy
reviewerRe: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse
Quoted 39 lines · Yong Wu
The
mtk_iommu_mm_dts_parsewill parse the smi larbs nodes. if the i+1 larb is parsed fail(return-EINVAL), we shouldof_node_putfor the 0..i larbs. In the fail path, oneof_node_putmatches withof_parse_phandlein it.Fixes d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE")Signed-off-by Yong Wu <[email protected]>--- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/iommu/mtk_iommu.c +6
-5@@ -1071,12 +1071,12 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m plarbdev =of_find_device_by_node (larbnode);if (!plarbdev) { -of_node_put (larbnode); -return -ENODEV ; + ret = -ENODEV ; + goto err_larbnode_put; }if (!plarbdev->dev.driver) { -of_node_put (larbnode); -return -EPROBE_DEFER ; + ret = -EPROBE_DEFER ; + goto err_larbnode_put; } data->larb_imu[id].dev = &plarbdev->dev;@@ -1107,9 +1107,20 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);if (!link) {dev_err (dev,"Unable to link %s.\n" ,dev_name (data->smicomm_dev)); -return -EINVAL ; + ret = -EINVAL ; + goto err_larbnode_put;
drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m · line 1121
Quoted 10 lines
drivers/iommu/mtk_iommu.c +8
-0}return 0 ; + +err_larbnode_put: +while (i--) { + larbnode =of_parse_phandle (dev->of_node,"mediatek,larbs" , i); +if (larbnode &&of_device_is_available (larbnode)) { +of_node_put (larbnode); +of_node_put (larbnode); + }
This looks a bit awkward - could we not just iterate through data->larb_imu and put dev->of_node for each valid dev?
Also, of_find_device_by_node() takes a reference on the struct device itself, so strictly we should be doing put_device() on those as well if we're bailing out.
Robin.
Quoted 5 lines
drivers/iommu/mtk_iommu.c +2
-0+ } +return ret; }static int mtk_iommu_probe (struct platform_device *pdev)
Yong Wu
maintainerRe: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse
Quoted 53 lines · Robin Murphy
Quoted 52 lines · Yong Wu
The
mtk_iommu_mm_dts_parsewill parse the smi larbs nodes. if the i+1
larb is parsed fail(return-EINVAL), we shouldof_node_putfor the 0..i
larbs. In the fail path, oneof_node_putmatches withof_parse_phandlein
it.Fixes d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow withthe MM TYPE")
Signed-off-by Yong Wu <[email protected]>--- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/iommu/mtk_iommu.c +0
-0@@ -1071,12 +1071,12 @@ static int mtk_iommu_mm_dts_parse(structdevice *dev, struct
component_match**mplarbdev = of_find_device_by_node(larbnode); if (!plarbdev) {drivers/iommu/mtk_iommu.c +4
-4-of_node_put (larbnode); -return -ENODEV ; + ret = -ENODEV ; + goto err_larbnode_put; }if (!plarbdev->dev.driver) { -of_node_put (larbnode); -return -EPROBE_DEFER ; + ret = -EPROBE_DEFER ; + goto err_larbnode_put; } data->larb_imu[id].dev = &plarbdev->dev;@@ -1107,9 +1107,20 @@ static int mtk_iommu_mm_dts_parse(structdevice *dev, struct
component_match**m
DL_FLAG_STATELESS|DL_FLAG_PM_RUNTIME);
if (!link) {
dev_err(dev, "Unable to link %s.\n", dev_name(data-Quoted 1 line
smicomm_dev));drivers/iommu/mtk_iommu.c +6
-1-return -EINVAL ; + ret = -EINVAL ; + goto err_larbnode_put; }return 0 ; + +err_larbnode_put: +while (i--) { + larbnode = of_parse_phandle(dev->of_node,
Quoted 8 lines
drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m · line 1121
Quoted 5 lines
"mediatek,larbs", i);
drivers/iommu/mtk_iommu.c +4
-0+if (larbnode &&of_device_is_available (larbnode)) { +of_node_put (larbnode); +of_node_put (larbnode); + }This looks a bit awkward - could we not just iterate through
data->larb_imuand putdev->of_nodefor each valid dev?
It should work. Thanks very much.
Quoted 5 lines
Also,
of_find_device_by_node()takes a reference on the struct device
itself, so strictly we should be doingput_device()on those as well if we're bailing out.
Thanks for this hint. A new reference for me. I will add it.
Quoted 8 lines
Robin.
Quoted 5 lines
drivers/iommu/mtk_iommu.c +2
-0+ } +return ret; }static int mtk_iommu_probe (struct platform_device *pdev)
Robin Murphy
reviewerRe: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse
Quoted 66 lines · Yong Wu
Quoted 53 lines · Robin Murphy
Quoted 52 lines · Yong Wu
The
mtk_iommu_mm_dts_parsewill parse the smi larbs nodes. if the i+1
larb is parsed fail(return-EINVAL), we shouldof_node_putfor the 0..i
larbs. In the fail path, oneof_node_putmatches withof_parse_phandlein
it.Fixes d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow withthe MM TYPE")
Signed-off-by Yong Wu <[email protected]>--- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/iommu/mtk_iommu.c +0
-0@@ -1071,12 +1071,12 @@ static int mtk_iommu_mm_dts_parse(structdevice *dev, struct
component_match**mplarbdev = of_find_device_by_node(larbnode); if (!plarbdev) {drivers/iommu/mtk_iommu.c +4
-4-of_node_put (larbnode); -return -ENODEV ; + ret = -ENODEV ; + goto err_larbnode_put; }if (!plarbdev->dev.driver) { -of_node_put (larbnode); -return -EPROBE_DEFER ; + ret = -EPROBE_DEFER ; + goto err_larbnode_put; } data->larb_imu[id].dev = &plarbdev->dev;@@ -1107,9 +1107,20 @@ static int mtk_iommu_mm_dts_parse(structdevice *dev, struct
component_match**m
DL_FLAG_STATELESS|DL_FLAG_PM_RUNTIME);
if (!link) {
dev_err(dev, "Unable to link %s.\n", dev_name(data-Quoted 1 line
smicomm_dev));drivers/iommu/mtk_iommu.c +6
-1-return -EINVAL ; + ret = -EINVAL ; + goto err_larbnode_put; }return 0 ; + +err_larbnode_put: +while (i--) { + larbnode = of_parse_phandle(dev->of_node,Quoted 8 lines
drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m · line 1121
Quoted 5 lines
"mediatek,larbs", i);
drivers/iommu/mtk_iommu.c +4
-0+if (larbnode &&of_device_is_available (larbnode)) { +of_node_put (larbnode); +of_node_put (larbnode); + }This looks a bit awkward - could we not just iterate through
data->larb_imuand putdev->of_nodefor each valid dev?It should work. Thanks very much.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Also,
of_find_device_by_node()takes a reference on the struct device
itself, so strictly we should be doingput_device()on those as well if we're bailing out.Thanks for this hint. A new reference for me. I will add it.
In fact, thinking about it some more we may as well do the of_node_put() unconditionally immediately after the of_find_device_by_node() call, so then it's *only* the device references we'd need to worry about cleaning up in the failure path.
Robin.
Yong Wu
maintainerRe: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse
Quoted 20 lines · Robin Murphy
Quoted 19 lines · Yong Wu
Quoted 18 lines · Robin Murphy
Quoted 17 lines · Yong Wu
The
mtk_iommu_mm_dts_parsewill parse the smi larbs nodes. if the
i+1
larb is parsed fail(return-EINVAL), we shouldof_node_putfor the
0..i
larbs. In the fail path, oneof_node_putmatches withof_parse_phandlein
it.Fixes d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flowwith
the MM TYPE")Signed-off-by Yong Wu <[email protected]>--- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
[snip..]
Quoted 22 lines
Quoted 22 lines
Quoted 4 lines
Quoted 4 lines
drivers/iommu/mtk_iommu.c +3
-0+err_larbnode_put: +while (i--) { + larbnode = of_parse_phandle(dev->of_node,"mediatek,larbs", i);
Quoted 8 lines
drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m · line 1121
Quoted 5 lines
(quoted diff) +1
-0+ if (larbnode &&
of_device_is_available(larbnode)) {drivers/iommu/mtk_iommu.c +3
-0+of_node_put (larbnode); +of_node_put (larbnode); + }This looks a bit awkward - could we not just iterate through
data->larb_imuand putdev->of_nodefor each valid dev?It should work. Thanks very much.
Quoted 6 lines
Also,
of_find_device_by_node()takes a reference on the struct device
itself, so strictly we should be doingput_device()on those as well
if we're bailing out.
Quoted 5 lines
Quoted 1 line
Thanks for this hint. A new reference for me. I will add it.
In fact, thinking about it some more we may as well do the
of_node_put()
unconditionally immediately after theof_find_device_by_node()call,
of_node_put is called in component_release_of in the normal case, thus we shouldn't call of_node_put unconditionally. Right?
(Sorry for reply late)
Quoted 6 lines
so
then it's *only* the device references we'd need to worry about cleaning
up in the failure path.Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Robin Murphy
reviewerRe: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse
Quoted 46 lines · Yong Wu
Quoted 20 lines · Robin Murphy
Quoted 19 lines · Yong Wu
Quoted 18 lines · Robin Murphy
Quoted 17 lines · Yong Wu
The
mtk_iommu_mm_dts_parsewill parse the smi larbs nodes. if the
i+1
larb is parsed fail(return-EINVAL), we shouldof_node_putfor the
0..i
larbs. In the fail path, oneof_node_putmatches withof_parse_phandlein
it.Fixes d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flowwith
the MM TYPE")Signed-off-by Yong Wu <[email protected]>--- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)[snip..]
Quoted 22 lines
Quoted 22 lines
Quoted 4 lines
Quoted 4 lines
drivers/iommu/mtk_iommu.c +3
-0+err_larbnode_put: +while (i--) { + larbnode = of_parse_phandle(dev->of_node,"mediatek,larbs", i);
Quoted 8 lines
drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m · line 1121
Quoted 5 lines
(quoted diff) +1
-0+ if (larbnode &&
of_device_is_available(larbnode)) {drivers/iommu/mtk_iommu.c +3
-0+of_node_put (larbnode); +of_node_put (larbnode); + }This looks a bit awkward - could we not just iterate through
data->larb_imuand putdev->of_nodefor each valid dev?It should work. Thanks very much.
Quoted 6 lines
Also,
of_find_device_by_node()takes a reference on the struct device
itself, so strictly we should be doingput_device()on those as well
if we're bailing out.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Thanks for this hint. A new reference for me. I will add it.
In fact, thinking about it some more we may as well do the
of_node_put()
unconditionally immediately after theof_find_device_by_node()call,
of_node_putis called incomponent_release_ofin the normal case, thus we shouldn't callof_node_putunconditionally. Right?
As it stands, yes. However I'm also figuring that we could just use component_match_add() there, and probably also switch to component_compare_dev as the the comparison, since we've already resolved the larb device, and it is the device itself that we're interested in here, rather than just its of_node.
I *think* this idea could end up with simpler code overall, but as always, feel free to ignore the suggestion if you think it wouldn't make enough difference to be worth the bother.
Thanks,
Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Matthias Brugger
maintainerRe: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse
In reply to Yong WuQuoted 16 lines · Yong Wu
The
mtk_iommu_mm_dts_parsewill parse the smi larbs nodes. if the i+1 larb is parsed fail(return-EINVAL), we shouldof_node_putfor the 0..i larbs. In the fail path, oneof_node_putmatches withof_parse_phandlein it.Fixes d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow with the MM TYPE")Signed-off-by Yong Wu <[email protected]>--- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/iommu/mtk_iommu.c +0
-0
drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m · line 1071
Quoted 1 line
drivers/iommu/mtk_iommu.c +0
-0@@ -1071,12 +1071,12 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
Don't we need to call the goto also on error case of:
larbnode = of_parse_phandle(dev->of_node, "mediatek,larbs", i);
Regards,
Matthias
Quoted 27 lines
drivers/iommu/mtk_iommu.c +9
-5plarbdev =of_find_device_by_node (larbnode);if (!plarbdev) { -of_node_put (larbnode); -return -ENODEV ; + ret = -ENODEV ; + goto err_larbnode_put; }if (!plarbdev->dev.driver) { -of_node_put (larbnode); -return -EPROBE_DEFER ; + ret = -EPROBE_DEFER ; + goto err_larbnode_put; } data->larb_imu[id].dev = &plarbdev->dev;@@ -1107,9 +1107,20 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME);if (!link) {dev_err (dev,"Unable to link %s.\n" ,dev_name (data->smicomm_dev)); -return -EINVAL ; + ret = -EINVAL ; + goto err_larbnode_put; }return 0 ; + +err_larbnode_put: +while (i--) {
drivers/iommu/mtk_iommu.c static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m · line 1126
Quoted 10 lines
drivers/iommu/mtk_iommu.c +7
-0+ larbnode =of_parse_phandle (dev->of_node,"mediatek,larbs" , i); +if (larbnode &&of_device_is_available (larbnode)) { +of_node_put (larbnode); +of_node_put (larbnode); + } + } +return ret; }static int mtk_iommu_probe (struct platform_device *pdev)
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu
maintainerRe: [PATCH v2 2/5] iommu/mediatek: Add error path for loop of mm_dts_parse
Quoted 27 lines · Matthias Brugger
Quoted 20 lines · Yong Wu
The
mtk_iommu_mm_dts_parsewill parse the smi larbs nodes. if the i+1
larb is parsed fail(return-EINVAL), we shouldof_node_putfor the 0..i
larbs. In the fail path, oneof_node_putmatches withof_parse_phandlein
it.Fixes d2e9a1102cfc ("iommu/mediatek: Contain MM IOMMU flow withthe MM TYPE")
Signed-off-by Yong Wu <[email protected]>--- drivers/iommu/mtk_iommu.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)drivers/iommu/mtk_iommu.c +0
-0@@ -1071,12 +1071,12 @@ static int mtk_iommu_mm_dts_parse(structQuoted 2 lines
device *dev, struct
component_match**mDon't we need to call the goto also on error case of:
Quoted 1 line
larbnode =
of_parse_phandle(dev->of_node, "mediatek,larbs", i);
Thanks very much.
exactly right. I will add in next version.
Quoted 2 lines
Regards,
Matthias
Yong Wu
maintainerPATCH v2 3/5 iommu/mediatek: Validate number of phandles associated with "mediatek, larbs"
In reply to Yong WuFrom: Guenter Roeck <[email protected]>
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.
--- drivers/iommu/mtk_iommu.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/iommu/mtk_iommu.c +11 -0
@@ -1052,6 +1052,8 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m larb_nr =of_count_phandle_with_args (dev->of_node,"mediatek,larbs" ,NULL );if (larb_nr <0 )return larb_nr; +if (larb_nr ==0 || larb_nr >MTK_LARB_NR_MAX ) +return -EINVAL ;for (i =0 ; i < larb_nr; i++) {u32 id;
@@ -1068,6 +1070,10 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m ret =of_property_read_u32 (larbnode,"mediatek,larb-id" , &id);if (ret)/* The id is consecutive if there is no this property */ id = i; +if (id >=MTK_LARB_NR_MAX ) { + ret = -EINVAL ; + goto err_larbnode_put; + } plarbdev =of_find_device_by_node (larbnode);if (!plarbdev) {
@@ -1078,6 +1084,11 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m ret = -EPROBE_DEFER ; goto err_larbnode_put; } + +if (data->larb_imu[id].dev) { + ret = -EEXIST ; + goto err_larbnode_put; + } data->larb_imu[id].dev = &plarbdev->dev; component_match_add_release(dev, match, component_release_of,
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu
maintainerPATCH v2 4/5 iommu/mediatek: Improve safety for mediatek, smi property in larb nodes
In reply to Yong WuNo 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.
--- drivers/iommu/mtk_iommu.c | 49 ++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 16 deletions(-)
drivers/iommu/mtk_iommu.c +33 -16
@@ -1044,7 +1044,7 @@ static const struct component_master_ops mtk_iommu_com_ops = {static int mtk_iommu_mm_dts_parse (struct device *dev,struct component_match **match,struct mtk_iommu_data *data) { -struct device_node *larbnode, *smicomm_node, *smi_subcomm_node; +struct device_node *larbnode, *frst_avail_smicomm_node =NULL ;struct platform_device *plarbdev;struct device_link *link;int i, larb_nr, ret;
@@ -1056,6 +1056,7 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **mreturn -EINVAL ;for (i =0 ; i < larb_nr; i++) { +struct device_node *smicomm_node, *smi_subcomm_node;u32 id; larbnode =of_parse_phandle (dev->of_node,"mediatek,larbs" , i);
@@ -1091,27 +1092,43 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m } data->larb_imu[id].dev = &plarbdev->dev; +/* Get smi-(sub)-common dev from the last larb. */ + smi_subcomm_node =of_parse_phandle (larbnode,"mediatek,smi" ,0 ); +if (!smi_subcomm_node) { + ret = -EINVAL ; + goto err_larbnode_put; + } + +/* +* It may have two level smi-common. the node is smi-sub-common if it +* has a new mediatek,smi property. otherwise it is smi-commmon. +*/ + smicomm_node =of_parse_phandle (smi_subcomm_node,"mediatek,smi" ,0 ); +if (smicomm_node) +of_node_put (smi_subcomm_node); +else + smicomm_node = smi_subcomm_node; + +if (!frst_avail_smicomm_node) { + frst_avail_smicomm_node = smicomm_node; + }else if (frst_avail_smicomm_node != smicomm_node) { +dev_err (dev,"mediatek,smi is not right @larb%d." , id); +of_node_put (smicomm_node); + ret = -EINVAL ; + goto err_larbnode_put; + }else { +of_node_put (smicomm_node); + } +component_match_add_release (dev, match, component_release_of, component_compare_of, larbnode); } -/* Get smi-(sub)-common dev from the last larb. */ - smi_subcomm_node =of_parse_phandle (larbnode,"mediatek,smi" ,0 ); -if (!smi_subcomm_node) +if (!frst_avail_smicomm_node)return -EINVAL ; -/* -* It may have two level smi-common. the node is smi-sub-common if it -* has a new mediatek,smi property. otherwise it is smi-commmon. -*/ - smicomm_node =of_parse_phandle (smi_subcomm_node,"mediatek,smi" ,0 ); -if (smicomm_node) -of_node_put (smi_subcomm_node); -else - smicomm_node = smi_subcomm_node; - - plarbdev =of_find_device_by_node (smicomm_node); -of_node_put (smicomm_node); + plarbdev =of_find_device_by_node (frst_avail_smicomm_node); +of_node_put (frst_avail_smicomm_node); data->smicomm_dev = &plarbdev->dev; link = device_link_add(data->smicomm_dev, dev,
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Yong Wu
maintainerPATCH v2 5/5 iommu/mediatek: Remove a unused "mapping" which is only for v1
In reply to Yong WuJust remove a unused variable that only is for mtk_iommu_v1.
--- drivers/iommu/mtk_iommu.c | 3 --- 1 file changed, 3 deletions(-)
drivers/iommu/mtk_iommu.c +0 -3
@@ -221,10 +221,7 @@ struct mtk_iommu_data {struct device *smicomm_dev;struct mtk_iommu_bank_data *bank; - -struct dma_iommu_mapping *mapping;/* For mtk_iommu_v1.c */ struct regmap *pericfg; -struct mutex mutex;/* Protect m4u_group/m4u_dom above */ /*
Signature · 6 lines
2.18.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 5/5] iommu/mediatek: Remove a unused "mapping" which is only for v1
Il 16/06/22 07:42, Yong Wu ha scritto:
Quoted 4 lines
Just remove a unused variable that only is for
mtk_iommu_v1.Fixes 9485a04a5bb9 ("iommu/mediatek: Separate mtk_iommu_data for v1 and v2")Signed-off-by Yong Wu <[email protected]>
The title isn't immediately clear, looks like you're removing some mapping, not a struct member...
Perhaps... iommu/mediatek: Remove unused "mapping" member from mtk_iommu_data ?
After clarifying the commit title:
Cheers,
Angelo
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Re: [PATCH v2 5/5] iommu/mediatek: Remove a unused "mapping" which is only for v1
In reply to Yong WuQuoted 3 lines · Yong Wu
Just remove a unused variable that only is for
mtk_iommu_v1.Fixes 9485a04a5bb9 ("iommu/mediatek: Separate mtk_iommu_data for v1 and v2")
It does not fix a bug, so no fixes tag here needed.
With that:
Quoted 10 lines
Signed-off-by Yong Wu <[email protected]>--- drivers/iommu/mtk_iommu.c | 3 --- 1 file changed, 3 deletions(-)drivers/iommu/mtk_iommu.c +0
-0
drivers/iommu/mtk_iommu.c struct mtk_iommu_data { · line 227
Quoted 10 lines
drivers/iommu/mtk_iommu.c +0
-3@@ -221,10 +221,7 @@ struct mtk_iommu_data {struct device *smicomm_dev;struct mtk_iommu_bank_data *bank; - -struct dma_iommu_mapping *mapping;/* For mtk_iommu_v1.c */ struct regmap *pericfg; -struct mutex mutex;/* Protect m4u_group/m4u_dom above */ /*
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu