All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lu Baolu <baolu.lu@linux.intel.com>
To: Joerg Roedel <joro@8bytes.org>
Cc: "Kefeng Wang" <wangkefeng.wang@huawei.com>,
	"Kees Cook" <keescook@chromium.org>,
	"Yury Norov" <yury.norov@gmail.com>,
	"Maíra Canal" <maira.canal@usp.br>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	iommu@lists.linux-foundation.org,
	"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>
Subject: [PATCH 1/4] iommu/vt-d: Use bitmap_zalloc() when applicable
Date: Fri, 17 Dec 2021 16:38:14 +0800	[thread overview]
Message-ID: <20211217083817.1745419-2-baolu.lu@linux.intel.com> (raw)
In-Reply-To: <20211217083817.1745419-1-baolu.lu@linux.intel.com>

From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

'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>
---
 drivers/iommu/intel/iommu.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c
index b6a8f3282411..4acc97765209 100644
--- a/drivers/iommu/intel/iommu.c
+++ b/drivers/iommu/intel/iommu.c
@@ -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;
 	}
-- 
2.25.1

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-12-17  8:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-17  8:38 [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Lu Baolu
2021-12-17  8:38 ` Lu Baolu [this message]
2021-12-17  8:38 ` [PATCH 2/4] iommu/vt-d: Drop duplicate check in dma_pte_free_pagetable() Lu Baolu
2021-12-17  8:38 ` [PATCH 3/4] iommu/vt-d: Remove unused dma_to_mm_pfn function Lu Baolu
2021-12-17  8:38 ` [PATCH 4/4] iommu/vt-d: Use correctly sized arguments for bit field Lu Baolu
2021-12-17  8:41 ` [PATCH 0/4] [PULL REQUEST] Intel IOMMU Updates for Linux v5.17 Joerg Roedel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211217083817.1745419-2-baolu.lu@linux.intel.com \
    --to=baolu.lu@linux.intel.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=keescook@chromium.org \
    --cc=maira.canal@usp.br \
    --cc=ndesaulniers@google.com \
    --cc=wangkefeng.wang@huawei.com \
    --cc=yury.norov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.