Skip to content

Commit 98b6474

Browse files
tititiou36willdeacon
authored andcommitted
iommu/arm-smmu-v3: Avoid open coded arithmetic in memory allocation
kmalloc_array()/kcalloc() should be used to avoid potential overflow when a multiplication is needed to compute the size of the requested memory. So turn a devm_kzalloc()+explicit size computation into an equivalent devm_kcalloc(). Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Acked-by: Robin Murphy <robin.murphy@arm.com> Link: https://lore.kernel.org/r/3f7b9b202c6b6f5edc234ab7af5f208fbf8bc944.1644274051.git.christophe.jaillet@wanadoo.fr Signed-off-by: Will Deacon <will@kernel.org>
1 parent 26291c5 commit 98b6474

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2981,10 +2981,10 @@ static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu)
29812981
{
29822982
unsigned int i;
29832983
struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
2984-
size_t size = sizeof(*cfg->l1_desc) * cfg->num_l1_ents;
29852984
void *strtab = smmu->strtab_cfg.strtab;
29862985

2987-
cfg->l1_desc = devm_kzalloc(smmu->dev, size, GFP_KERNEL);
2986+
cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents,
2987+
sizeof(*cfg->l1_desc), GFP_KERNEL);
29882988
if (!cfg->l1_desc)
29892989
return -ENOMEM;
29902990

0 commit comments

Comments
 (0)