Skip to contentSkip to conversation

iommu/mediatek: Fix forever loop in error handling

PATCH Applied Dan Carpenter 3 participants 4 messages Dec 7, 2022 – Dec 12, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iommu/mediatek: Fix forever loop in error handling

There is a typo so this loop does i++ where i-- was intended. It will result in looping until the kernel crashes.

Fixes 26593928564c ("iommu/mediatek: Add error path for loop of mm_dts_parse")
---
 drivers/iommu/mtk_iommu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/mtk_iommu.c +1 -2
index 3e46bc8b0714..2badd6acfb23 100644
@@ -1160,8 +1160,7 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
 	return 0;
 
 err_larbdev_put:
-	/* id may be not linear mapping, loop whole the array */
-	for (i = MTK_LARB_NR_MAX - 1; i >= 0; i++) {
+	for (i = MTK_LARB_NR_MAX - 1; i >= 0; i--) {
 		if (!data->larb_imu[i].dev)
 			continue;
 		put_device(data->larb_imu[i].dev);
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dan Carpenter

There is a typo so this loop does i++ where i-- was intended. It will
result in looping until the kernel crashes.

Fixes 26593928564c ("iommu/mediatek: Add error path for loop of

mm_dts_parse")

Sorry for this.

Thanks Dan.

Quoted 19 lines
---
 drivers/iommu/mtk_iommu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/mtk_iommu.c +1 -2
index 3e46bc8b0714..2badd6acfb23 100644
@@ -1160,8 +1160,7 @@ static int mtk_iommu_mm_dts_parse(struct device
 *dev, struct component_match **m
 	return 0;
 
 err_larbdev_put:
-	/* id may be not linear mapping, loop whole the array */
-	for (i = MTK_LARB_NR_MAX - 1; i >= 0; i++) {
+	for (i = MTK_LARB_NR_MAX - 1; i >= 0; i--) {
 		if (!data->larb_imu[i].dev)
 			continue;

put_device(data->larb_imu[i].dev);

maintainer
#2 lore raw

Hi Joerg,

Quoted 9 lines · YongWu
Quoted 7 lines · Dan Carpenter

There is a typo so this loop does i++ where i-- was intended. It will
result in looping until the kernel crashes.

Fixes 26593928564c ("iommu/mediatek: Add error path for loop of

mm_dts_parse")

Quoted 5 lines

Sorry for this.

Thanks Dan.

Could you help apply this?

I reproduced this below issue, and it could be fixed by this patch.

https://lore.kernel.org/linux-mediatek/[email protected]/

Thanks.

Quoted 21 lines
Quoted 21 lines
---
 drivers/iommu/mtk_iommu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/mtk_iommu.c +0 -0
index 3e46bc8b0714..2badd6acfb23 100644
@@ -1160,8 +1160,7 @@ static int mtk_iommu_mm_dts_parse(struct

device
*dev, struct component_match **m

drivers/iommu/mtk_iommu.c +1 -2
 	return 0;
 
 err_larbdev_put:
-	/* id may be not linear mapping, loop whole the array */
-	for (i = MTK_LARB_NR_MAX - 1; i >= 0; i++) {
+	for (i = MTK_LARB_NR_MAX - 1; i >= 0; i--) {
 		if (!data->larb_imu[i].dev)
 			continue;
 		put_device(data->larb_imu[i].dev);
maintainer Applied
#3 lore raw
In reply to Dan Carpenter
Quoted 8 lines · Dan Carpenter

There is a typo so this loop does i++ where i-- was intended. It will result in looping until the kernel crashes.

Fixes 26593928564c ("iommu/mediatek: Add error path for loop of mm_dts_parse")
---
 drivers/iommu/mtk_iommu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Applied, thanks.