Skip to content

Commit bb71257

Browse files
tititiou36joergroedel
authored andcommitted
iommu/vt-d: Use bitmap_zalloc() when applicable
'iommu->domain_ids' is a bitmap. So use 'bitmap_zalloc()' to simplify code and improve the semantic. Also change the corresponding 'kfree()' into 'bitmap_free()' to keep consistency. Signed-off-by: Christophe JAILLET <[email protected]> Link: https://lore.kernel.org/r/cb7a3e0a8d522447a06298a4f244c3df072f948b.1635018498.git.christophe.jaillet@wanadoo.fr Signed-off-by: Lu Baolu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent 9dfa5b6 commit bb71257

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,17 +1878,16 @@ static void iommu_disable_translation(struct intel_iommu *iommu)
18781878

18791879
static int iommu_init_domains(struct intel_iommu *iommu)
18801880
{
1881-
u32 ndomains, nlongs;
1881+
u32 ndomains;
18821882
size_t size;
18831883

18841884
ndomains = cap_ndoms(iommu->cap);
18851885
pr_debug("%s: Number of Domains supported <%d>\n",
18861886
iommu->name, ndomains);
1887-
nlongs = BITS_TO_LONGS(ndomains);
18881887

18891888
spin_lock_init(&iommu->lock);
18901889

1891-
iommu->domain_ids = kcalloc(nlongs, sizeof(unsigned long), GFP_KERNEL);
1890+
iommu->domain_ids = bitmap_zalloc(ndomains, GFP_KERNEL);
18921891
if (!iommu->domain_ids)
18931892
return -ENOMEM;
18941893

@@ -1903,7 +1902,7 @@ static int iommu_init_domains(struct intel_iommu *iommu)
19031902
if (!iommu->domains || !iommu->domains[0]) {
19041903
pr_err("%s: Allocating domain array failed\n",
19051904
iommu->name);
1906-
kfree(iommu->domain_ids);
1905+
bitmap_free(iommu->domain_ids);
19071906
kfree(iommu->domains);
19081907
iommu->domain_ids = NULL;
19091908
iommu->domains = NULL;
@@ -1964,7 +1963,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)
19641963
for (i = 0; i < elems; i++)
19651964
kfree(iommu->domains[i]);
19661965
kfree(iommu->domains);
1967-
kfree(iommu->domain_ids);
1966+
bitmap_free(iommu->domain_ids);
19681967
iommu->domains = NULL;
19691968
iommu->domain_ids = NULL;
19701969
}

0 commit comments

Comments
 (0)