Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iommu/mediatek: simplify dt parsing error handling

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>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>

authored by

Johan Hovold and committed by
Joerg Roedel
4f2a4aec de83d461

+3 -4
+3 -4
drivers/iommu/mtk_iommu.c
··· 1239 1239 return 0; 1240 1240 1241 1241 err_larbdev_put: 1242 - for (i = MTK_LARB_NR_MAX - 1; i >= 0; i--) { 1243 - if (!data->larb_imu[i].dev) 1244 - continue; 1242 + /* id mapping may not be linear, loop the whole array */ 1243 + for (i = 0; i < MTK_LARB_NR_MAX; i++) 1245 1244 put_device(data->larb_imu[i].dev); 1246 - } 1245 + 1247 1246 return ret; 1248 1247 } 1249 1248