Skip to content

Commit 47b2de3

Browse files
jgunthorpewilldeacon
authored andcommitted
iommu/arm-smmu-v3: Do not use devm for the cd table allocations
The master->cd_table is entirely contained within the struct arm_smmu_master which is guaranteed to be freed by the core code under arm_smmu_release_device(). There is no reason to use devm here, arm_smmu_free_cd_tables() is reliably called to free the CD related memory. Remove it and save some memory. Tested-by: Nicolin Chen <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 8c153ef commit 47b2de3

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,8 +1222,8 @@ static int arm_smmu_alloc_cd_leaf_table(struct arm_smmu_device *smmu,
12221222
{
12231223
size_t size = CTXDESC_L2_ENTRIES * (CTXDESC_CD_DWORDS << 3);
12241224

1225-
l1_desc->l2ptr = dmam_alloc_coherent(smmu->dev, size,
1226-
&l1_desc->l2ptr_dma, GFP_KERNEL);
1225+
l1_desc->l2ptr = dma_alloc_coherent(smmu->dev, size,
1226+
&l1_desc->l2ptr_dma, GFP_KERNEL);
12271227
if (!l1_desc->l2ptr) {
12281228
dev_warn(smmu->dev,
12291229
"failed to allocate context descriptor table\n");
@@ -1437,17 +1437,17 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master)
14371437
cd_table->num_l1_ents = DIV_ROUND_UP(max_contexts,
14381438
CTXDESC_L2_ENTRIES);
14391439

1440-
cd_table->l1_desc = devm_kcalloc(smmu->dev, cd_table->num_l1_ents,
1441-
sizeof(*cd_table->l1_desc),
1442-
GFP_KERNEL);
1440+
cd_table->l1_desc = kcalloc(cd_table->num_l1_ents,
1441+
sizeof(*cd_table->l1_desc),
1442+
GFP_KERNEL);
14431443
if (!cd_table->l1_desc)
14441444
return -ENOMEM;
14451445

14461446
l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3);
14471447
}
14481448

1449-
cd_table->cdtab = dmam_alloc_coherent(smmu->dev, l1size, &cd_table->cdtab_dma,
1450-
GFP_KERNEL);
1449+
cd_table->cdtab = dma_alloc_coherent(smmu->dev, l1size,
1450+
&cd_table->cdtab_dma, GFP_KERNEL);
14511451
if (!cd_table->cdtab) {
14521452
dev_warn(smmu->dev, "failed to allocate context descriptor\n");
14531453
ret = -ENOMEM;
@@ -1458,7 +1458,7 @@ static int arm_smmu_alloc_cd_tables(struct arm_smmu_master *master)
14581458

14591459
err_free_l1:
14601460
if (cd_table->l1_desc) {
1461-
devm_kfree(smmu->dev, cd_table->l1_desc);
1461+
kfree(cd_table->l1_desc);
14621462
cd_table->l1_desc = NULL;
14631463
}
14641464
return ret;
@@ -1478,21 +1478,18 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_master *master)
14781478
if (!cd_table->l1_desc[i].l2ptr)
14791479
continue;
14801480

1481-
dmam_free_coherent(smmu->dev, size,
1482-
cd_table->l1_desc[i].l2ptr,
1483-
cd_table->l1_desc[i].l2ptr_dma);
1481+
dma_free_coherent(smmu->dev, size,
1482+
cd_table->l1_desc[i].l2ptr,
1483+
cd_table->l1_desc[i].l2ptr_dma);
14841484
}
1485-
devm_kfree(smmu->dev, cd_table->l1_desc);
1486-
cd_table->l1_desc = NULL;
1485+
kfree(cd_table->l1_desc);
14871486

14881487
l1size = cd_table->num_l1_ents * (CTXDESC_L1_DESC_DWORDS << 3);
14891488
} else {
14901489
l1size = cd_table->num_l1_ents * (CTXDESC_CD_DWORDS << 3);
14911490
}
14921491

1493-
dmam_free_coherent(smmu->dev, l1size, cd_table->cdtab, cd_table->cdtab_dma);
1494-
cd_table->cdtab_dma = 0;
1495-
cd_table->cdtab = NULL;
1492+
dma_free_coherent(smmu->dev, l1size, cd_table->cdtab, cd_table->cdtab_dma);
14961493
}
14971494

14981495
/* Stream table manipulation functions */

0 commit comments

Comments
 (0)