Skip to content

Commit b07cd3b

Browse files
Erick Archerjoergroedel
authored andcommitted
iommu/mtk_iommu: Use devm_kcalloc() instead of devm_kzalloc()
This is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows [1]. Here the multiplication is obviously safe because MTK_PROTECT_PA_ALIGN is defined as a literal value of 256 or 128. For the "mtk_iommu.c" file: 256 For the "mtk_iommu_v1.c" file: 128 However, using devm_kcalloc() is more appropriate [2] and improves readability. This patch has no effect on runtime behavior. Link: KSPP#162 [1] Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [2] Signed-off-by: Erick Archer <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Matthias Brugger <[email protected]> Reviewed-by: Gustavo A. R. Silva <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 54be6c6 commit b07cd3b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1264,7 +1264,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
12641264
data->plat_data = of_device_get_match_data(dev);
12651265

12661266
/* Protect memory. HW will access here while translation fault.*/
1267-
protect = devm_kzalloc(dev, MTK_PROTECT_PA_ALIGN * 2, GFP_KERNEL);
1267+
protect = devm_kcalloc(dev, 2, MTK_PROTECT_PA_ALIGN, GFP_KERNEL);
12681268
if (!protect)
12691269
return -ENOMEM;
12701270
data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN);

drivers/iommu/mtk_iommu_v1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ static int mtk_iommu_v1_probe(struct platform_device *pdev)
621621
data->dev = dev;
622622

623623
/* Protect memory. HW will access here while translation fault.*/
624-
protect = devm_kzalloc(dev, MTK_PROTECT_PA_ALIGN * 2,
625-
GFP_KERNEL | GFP_DMA);
624+
protect = devm_kcalloc(dev, 2, MTK_PROTECT_PA_ALIGN,
625+
GFP_KERNEL | GFP_DMA);
626626
if (!protect)
627627
return -ENOMEM;
628628
data->protect_base = ALIGN(virt_to_phys(protect), MTK_PROTECT_PA_ALIGN);

0 commit comments

Comments
 (0)