From patchwork Sat Feb 5 17:10:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12736161 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 92E4FC433F5 for ; Sat, 5 Feb 2022 17:12:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=cXNI+l/D8gGTXa0pdX0NtGA7K218yYYURX4aKEQNLmE=; b=XcuGoFcMS4WFoj UnJXzkxp/tFXyZrgGjIwRUA54T4E/UgwYp5cbGm8iOxwL0OBg8aXw3I0owbCOGNgDxj//JCh+4mCy DsqfVp0WR3Xjeu5ENmRjoe6hMu0rILiOxI2+DmOG3YuOwxyrgfA7IPdNxKsT3yhruM5eJPNtQKGpC hvhOf15/iLMtrBhNdtrVeVMDiMglMrj4CiLOJpZNkeZjj/lenKkalur/Sg7FaC2yhPhmuEluGRDfQ Y4bhacvgg2XJBzqUu8IAXKJ2aRk0AwUfucG47C8NbH0h1ntA98cRjVvdXTdX8991aBcQ3GuV9Eyvx jT2ZmDJ6zRmvbYv6dXxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nGOak-006rMq-Uy; Sat, 05 Feb 2022 17:11:19 +0000 Received: from smtp08.smtpout.orange.fr ([80.12.242.130] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nGOag-006rK2-Cf for linux-arm-kernel@lists.infradead.org; Sat, 05 Feb 2022 17:11:16 +0000 Received: from pop-os.home ([90.126.236.122]) by smtp.orange.fr with ESMTPA id GOaSngReQxHdTGOaSnEh5w; Sat, 05 Feb 2022 18:11:02 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sat, 05 Feb 2022 18:11:02 +0100 X-ME-IP: 90.126.236.122 From: Christophe JAILLET To: Will Deacon , Robin Murphy , Joerg Roedel Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [PATCH 1/2] iommu/arm-smmu-v3: Avoid open coded arithmetic in memory allocation Date: Sat, 5 Feb 2022 18:10:59 +0100 Message-Id: X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220205_091114_594964_9A454B7D X-CRM114-Status: GOOD ( 11.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org kmalloc_array()/kcalloc() should be used to avoid potential overflow when a multiplication is needed to compute the size of the requested memory. So turn a devm_kzalloc()+explicit size computation into an equivalent devm_kcalloc(). Signed-off-by: Christophe JAILLET Acked-by: Robin Murphy --- This is NOT compile tested. I don't have the needed cross compiling tools. --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 6dc6d8b6b368..14d06aad0726 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2981,10 +2981,10 @@ static int arm_smmu_init_l1_strtab(struct arm_smmu_device *smmu) { unsigned int i; struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg; - size_t size = sizeof(*cfg->l1_desc) * cfg->num_l1_ents; void *strtab = smmu->strtab_cfg.strtab; - cfg->l1_desc = devm_kzalloc(smmu->dev, size, GFP_KERNEL); + cfg->l1_desc = devm_kcalloc(smmu->dev, cfg->num_l1_ents, + sizeof(*cfg->l1_desc), GFP_KERNEL); if (!cfg->l1_desc) return -ENOMEM; From patchwork Sat Feb 5 17:11:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 12736160 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 4782BC433EF for ; Sat, 5 Feb 2022 17:12:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TKIQsrQgOjVE5cWWVbXKm3Ve6Xqnhhta8gP/Z4CE0tM=; b=z32mpF0UtQaNlv BiNKoEheukLGbED6kx6tNSlvRpziotkULkhn4iT+Rte7uRRI1muRP7cIEEB4yTmC2rilXJm7LGyoe dZNRwhj+mpWvFDwe5gdaZq63jpnK+L0rwkfurHnuchAcYE9ioe7u/f/hapbOnDnmhDJoLj5eol/Vl WLX6i5Fbm5emi35eqhombrS8v3gksEDfcTlvHtYBhAGL6yVXN+njHl0AALhmhRg6LL32MW+C9+wQT E4XN1gAjJEajJlvdGHTM1xRGMwciNeAOkZpWH03JzzWMLrUpxOthRco+0W1RDUtwgJqWVRVIJA52h w9Lx6y+7V2SUed5k2C3A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nGOau-006rOU-04; Sat, 05 Feb 2022 17:11:28 +0000 Received: from smtp08.smtpout.orange.fr ([80.12.242.130] helo=smtp.smtpout.orange.fr) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nGOai-006rLA-2l for linux-arm-kernel@lists.infradead.org; Sat, 05 Feb 2022 17:11:17 +0000 Received: from pop-os.home ([90.126.236.122]) by smtp.orange.fr with ESMTPA id GOadngRjHxHdTGOadnEh74; Sat, 05 Feb 2022 18:11:11 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sat, 05 Feb 2022 18:11:11 +0100 X-ME-IP: 90.126.236.122 From: Christophe JAILLET To: Will Deacon , Robin Murphy , Joerg Roedel Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org Subject: [PATCH 2/2] iommu/arm-smmu-v3: Simplify memory allocation Date: Sat, 5 Feb 2022 18:11:10 +0100 Message-Id: <018afc7c92ae4132ac901b088b72ab5979256a9e.1644081032.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220205_091116_282269_212F1223 X-CRM114-Status: GOOD ( 10.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use devm_bitmap_zalloc() instead of hand writing it. Signed-off-by: Christophe JAILLET --- This is NOT compile tested. I don't have the needed cross compiling tools. --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 14d06aad0726..ba0e7f1f7dbf 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -2911,12 +2911,6 @@ static int arm_smmu_init_one_queue(struct arm_smmu_device *smmu, return 0; } -static void arm_smmu_cmdq_free_bitmap(void *data) -{ - unsigned long *bitmap = data; - bitmap_free(bitmap); -} - static int arm_smmu_cmdq_init(struct arm_smmu_device *smmu) { int ret = 0; @@ -2927,13 +2921,13 @@ static int arm_smmu_cmdq_init(struct arm_smmu_device *smmu) atomic_set(&cmdq->owner_prod, 0); atomic_set(&cmdq->lock, 0); - bitmap = (atomic_long_t *)bitmap_zalloc(nents, GFP_KERNEL); + bitmap = (atomic_long_t *)devm_bitmap_zalloc(smmu->dev, nents, + GFP_KERNEL); if (!bitmap) { dev_err(smmu->dev, "failed to allocate cmdq bitmap\n"); ret = -ENOMEM; } else { cmdq->valid_map = bitmap; - devm_add_action(smmu->dev, arm_smmu_cmdq_free_bitmap, bitmap); } return ret;