[PATCH v3 07/14] iommu/mediatek: simplify dt parsing error handling

Johan Hovold posted 14 patches 1 month, 4 weeks ago
[PATCH v3 07/14] iommu/mediatek: simplify dt parsing error handling
Posted by Johan Hovold 1 month, 4 weeks ago
As previously documented by commit 26593928564c ("iommu/mediatek: Add
error path for loop of mm_dts_parse"), the id mapping may not be linear
so the whole larb array needs to be iterated on devicetree parsing
errors.

Simplify the loop by iterating from index zero while dropping the
redundant NULL check for consistency with later cleanups.

Also add back the comment which was removed by commit 462e768b55a2
("iommu/mediatek: Fix forever loop in error handling") to prevent anyone
from trying to optimise the loop by iterating backwards from 'i'.

Cc: Yong Wu <yong.wu@mediatek.com>
Acked-by: Robin Murphy <robin.murphy@arm.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/iommu/mtk_iommu.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
index 64ce041238fd..f21cd3766069 100644
--- a/drivers/iommu/mtk_iommu.c
+++ b/drivers/iommu/mtk_iommu.c
@@ -1239,11 +1239,10 @@ static int mtk_iommu_mm_dts_parse(struct device *dev, struct component_match **m
 	return 0;
 
 err_larbdev_put:
-	for (i = MTK_LARB_NR_MAX - 1; i >= 0; i--) {
-		if (!data->larb_imu[i].dev)
-			continue;
+	/* id mapping may not be linear, loop the whole array */
+	for (i = 0; i < MTK_LARB_NR_MAX; i++)
 		put_device(data->larb_imu[i].dev);
-	}
+
 	return ret;
 }
 
-- 
2.49.1
Re: [PATCH v3 07/14] iommu/mediatek: simplify dt parsing error handling
Posted by Yong Wu (吴勇) 1 month, 3 weeks ago
On Mon, 2025-10-20 at 06:53 +0200, Johan Hovold wrote:
> External email : Please do not click links or open attachments until
> you have verified the sender or the content.
> 
> 
> As previously documented by commit 26593928564c ("iommu/mediatek: Add
> error path for loop of mm_dts_parse"), the id mapping may not be
> linear
> so the whole larb array needs to be iterated on devicetree parsing
> errors.
> 
> Simplify the loop by iterating from index zero while dropping the
> redundant NULL check for consistency with later cleanups.
> 
> Also add back the comment which was removed by commit 462e768b55a2
> ("iommu/mediatek: Fix forever loop in error handling") to prevent
> anyone
> from trying to optimise the loop by iterating backwards from 'i'.
> 
> Cc: Yong Wu <yong.wu@mediatek.com>
> Acked-by: Robin Murphy <robin.murphy@arm.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>

Reviewed-by: Yong Wu <yong.wu@mediatek.com>

Re: [PATCH v3 07/14] iommu/mediatek: simplify dt parsing error handling
Posted by AngeloGioacchino Del Regno 1 month, 4 weeks ago
Il 20/10/25 06:53, Johan Hovold ha scritto:
> As previously documented by commit 26593928564c ("iommu/mediatek: Add
> error path for loop of mm_dts_parse"), the id mapping may not be linear
> so the whole larb array needs to be iterated on devicetree parsing
> errors.
> 
> Simplify the loop by iterating from index zero while dropping the
> redundant NULL check for consistency with later cleanups.
> 
> Also add back the comment which was removed by commit 462e768b55a2
> ("iommu/mediatek: Fix forever loop in error handling") to prevent anyone
> from trying to optimise the loop by iterating backwards from 'i'.
> 
> Cc: Yong Wu <yong.wu@mediatek.com>
> Acked-by: Robin Murphy <robin.murphy@arm.com>
> Signed-off-by: Johan Hovold <johan@kernel.org>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>