From patchwork Tue Jan 25 02:13:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 12723161 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 E4CD0C433F5 for ; Tue, 25 Jan 2022 02:08:34 +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:Subject:Cc:To: From:Date: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=5EO6KkYoT9BklHVxTMskdyb1CG76s1bT6T1tj4r0QpY=; b=WaoqFCli3bh0Dx aRlqR6UdhziTmkFOsPiaHikiDziJZJoQW0Wi8sqbSRHFCCF3yoe8EBdzfQZyZ1ZSr8m+uf6a6k2M0 /QTyeeHdHFDw0S29NaDZvLAUjLDwrbKryUBaMoqcGuOByIWrPps9J+CpRRojCopcJJ18wiI88E+tx 6x7yX4cXZZlmheGXKJnFr6JCKU4kVYP4EyKX2+6c/KZ+4JeyNbQQBdj8lhOojrNP5tD+wNlVn4+We naM/lHu3DzrWsIC08LxS9g6K+NC6fykUMMZDwI6G52q2oO2k4G3r5uBbB1yJGhhN86oWAqqKZzH+1 bGO0In/5trr/WWkIj79w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nCBEs-006ABp-Vo; Tue, 25 Jan 2022 02:07:19 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nCBEp-006ABE-Fw for linux-arm-kernel@lists.infradead.org; Tue, 25 Jan 2022 02:07:17 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 8B0A9CE140F; Tue, 25 Jan 2022 02:07:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 134C2C340E4; Tue, 25 Jan 2022 02:07:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643076429; bh=DkmaCtzsHaDPBE4tP0CtUwloyPGdoHeaJw6+TrZcPzc=; h=Date:From:To:Cc:Subject:From; b=fXK5sTtrVfnVn9wHuKkp4/rZufg1I6xX1vRxBNJOygtNroA6BHGiOv81djcwLhJgW SfuJU613oVo8CugT8dJMFR5+0eiuKV447klDxPHHqkBr00bX/b9f5sQXYfjss6r0H3 fVWE5PYcxyuehvkkkvaM0keZPgJFP4sBvnpq51lG4/CkI27q9yxaqimKs/aX+q7gw/ OYwoPwjYVB9GnJSY6UHSA5hlt5Fjfdj4MEeR4lY4DQAD3xuu+yCK/m08LZh6zcOJQc mdCrIF1lyVRos9YXbp7rff0KNtE4hnK9QHWS/dCRw18rmMOThBeVBLtmAafKL3U/sG gMZjZFsNheXIQ== Date: Mon, 24 Jan 2022 20:13:53 -0600 From: "Gustavo A. R. Silva" To: Ohad Ben-Cohen , Bjorn Andersson , Baolin Wang , Maxime Coquelin , Alexandre Torgue Cc: linux-remoteproc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] hwspinlock: stm32: Use struct_size() helper in devm_kzalloc() Message-ID: <20220125021353.GA29777@embeddedor> MIME-Version: 1.0 Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220124_180715_755247_23673D18 X-CRM114-Status: GOOD ( 12.75 ) 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 Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/hwspinlock/stm32_hwspinlock.c:84:32: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Baolin Wang --- drivers/hwspinlock/stm32_hwspinlock.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/hwspinlock/stm32_hwspinlock.c b/drivers/hwspinlock/stm32_hwspinlock.c index 5bd11a7fab65..716ad4401249 100644 --- a/drivers/hwspinlock/stm32_hwspinlock.c +++ b/drivers/hwspinlock/stm32_hwspinlock.c @@ -73,15 +73,14 @@ static int stm32_hwspinlock_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct stm32_hwspinlock *hw; void __iomem *io_base; - size_t array_size; int i, ret; io_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(io_base)) return PTR_ERR(io_base); - array_size = STM32_MUTEX_NUM_LOCKS * sizeof(struct hwspinlock); - hw = devm_kzalloc(dev, sizeof(*hw) + array_size, GFP_KERNEL); + hw = devm_kzalloc(dev, struct_size(hw, bank.lock, STM32_MUTEX_NUM_LOCKS), + GFP_KERNEL); if (!hw) return -ENOMEM;