From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7570C433F5 for ; Fri, 17 Dec 2021 08:38:46 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8B80683EBD; Fri, 17 Dec 2021 08:38:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id AgpDrv9jL5Ap; Fri, 17 Dec 2021 08:38:45 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp1.osuosl.org (Postfix) with ESMTPS id 888F483EB6; Fri, 17 Dec 2021 08:38:45 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 727E7C002F; Fri, 17 Dec 2021 08:38:45 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9E950C0039 for ; Fri, 17 Dec 2021 08:38:43 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 7F59A83EF2 for ; Fri, 17 Dec 2021 08:38:43 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XDBw1gdVoRmE for ; Fri, 17 Dec 2021 08:38:42 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by smtp1.osuosl.org (Postfix) with ESMTPS id BF78983EB6 for ; Fri, 17 Dec 2021 08:38:42 +0000 (UTC) X-IronPort-AV: E=McAfee;i="6200,9189,10200"; a="325999627" X-IronPort-AV: E=Sophos;i="5.88,213,1635231600"; d="scan'208";a="325999627" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Dec 2021 00:38:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,213,1635231600"; d="scan'208";a="662786053" Received: from allen-box.sh.intel.com ([10.239.159.118]) by fmsmga001.fm.intel.com with ESMTP; 17 Dec 2021 00:38:40 -0800 From: Lu Baolu To: Joerg Roedel Subject: [PATCH 1/4] iommu/vt-d: Use bitmap_zalloc() when applicable Date: Fri, 17 Dec 2021 16:38:14 +0800 Message-Id: <20211217083817.1745419-2-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211217083817.1745419-1-baolu.lu@linux.intel.com> References: <20211217083817.1745419-1-baolu.lu@linux.intel.com> MIME-Version: 1.0 Cc: Kefeng Wang , Kees Cook , Yury Norov , =?UTF-8?q?Ma=C3=ADra=20Canal?= , Nick Desaulniers , iommu@lists.linux-foundation.org, Christophe JAILLET X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" From: Christophe JAILLET '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 Link: https://lore.kernel.org/r/cb7a3e0a8d522447a06298a4f244c3df072f948b.1635018498.git.christophe.jaillet@wanadoo.fr Signed-off-by: Lu Baolu --- 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