iommu/vt-d: Use bitmap_zalloc() when applicable
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Fri, 17 Dec 2021 08:38:14 +0000 (16:38 +0800)
committerJoerg Roedel <jroedel@suse.de>
Fri, 17 Dec 2021 08:40:29 +0000 (09:40 +0100)
'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 <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/cb7a3e0a8d522447a06298a4f244c3df072f948b.1635018498.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20211217083817.1745419-2-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/intel/iommu.c

index 99f9e8229384f27e4a25b3f8e712f078498766bc..16e5fe35b3dc53ecfb825e88891d9ea402381b6e 100644 (file)
@@ -1878,17 +1878,16 @@ static void iommu_disable_translation(struct intel_iommu *iommu)
 
 static int iommu_init_domains(struct intel_iommu *iommu)
 {
-       u32 ndomains, nlongs;
+       u32 ndomains;
        size_t size;
 
        ndomains = cap_ndoms(iommu->cap);
        pr_debug("%s: Number of Domains supported <%d>\n",
                 iommu->name, ndomains);
-       nlongs = BITS_TO_LONGS(ndomains);
 
        spin_lock_init(&iommu->lock);
 
-       iommu->domain_ids = kcalloc(nlongs, sizeof(unsigned long), GFP_KERNEL);
+       iommu->domain_ids = bitmap_zalloc(ndomains, GFP_KERNEL);
        if (!iommu->domain_ids)
                return -ENOMEM;
 
@@ -1903,7 +1902,7 @@ static int iommu_init_domains(struct intel_iommu *iommu)
        if (!iommu->domains || !iommu->domains[0]) {
                pr_err("%s: Allocating domain array failed\n",
                       iommu->name);
-               kfree(iommu->domain_ids);
+               bitmap_free(iommu->domain_ids);
                kfree(iommu->domains);
                iommu->domain_ids = NULL;
                iommu->domains    = NULL;
@@ -1964,7 +1963,7 @@ static void free_dmar_iommu(struct intel_iommu *iommu)
                for (i = 0; i < elems; i++)
                        kfree(iommu->domains[i]);
                kfree(iommu->domains);
-               kfree(iommu->domain_ids);
+               bitmap_free(iommu->domain_ids);
                iommu->domains = NULL;
                iommu->domain_ids = NULL;
        }