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 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 E6907C2BA4C for ; Wed, 26 Jan 2022 08:31:03 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:CC:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=do83ACt3ZBfoMM9umINBj0twUxYXrnxJUiIKgfZITVo=; b=4SlzO7S96rbAna9SRv4JNgF5S9 m8YTuBfPN4kFEdihv+Asqd/riR7i+5/PzomD50Hrs+f7eAXtPYkhv/0zvVMvJFqSsZsl3adWvD+5s pbwKDiRD0Nr6OsJ9biCETnt23MXLKp1C5ybP9uqPXee5jbI6g0LhTWN6S8+St9NBdkBrB/rcA4jMO 9lh1U9e40i/b90fKbG6Ww26B1v5iRgZNMJU99/oeJQmj2uGMjW/Ud2Cbj4xfH8g6K4+G9PY9ZGsvX FIcZDSeQswUZI2qwc3Kq5tcDUgYVlTw11Vu0FHNjrmgVAmqf6+tZs6Is1kbiYazeWPonZU7EirVTF HpgnMt0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nCdgZ-00Ak0A-W8; Wed, 26 Jan 2022 08:29:48 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nCdgV-00AjxU-7S for linux-arm-kernel@lists.infradead.org; Wed, 26 Jan 2022 08:29:45 +0000 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 20Q4eNre021515; Wed, 26 Jan 2022 09:29:25 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=HqDC/OjVj/xPLO7ZZ9W6iTk/stZzn8M/W5EdEzByj68=; b=UWaXSzEyyD9azgCoJykNRixWshb3bYFrPJZJfzcQappHNjLhO6s4e427jgbHBnkojawH HrFmh79edtskl6t3g25fKLMLYWGs5Hg2Mmbv27oM2xPfqPtGD5zeqcg8HKi9jECLipD7 xYBN74zPVpV+85EvqnxlgbWMOizbaeEmanYv8ME9Jjz6zuApT6/w7DKENGSdGQSviQco TaPkaUn7PJgFdJxk1U6a88lQGS+lf6VnynUaZTnobA8C9DL18GQe0Rr21jvxYF/Qoed0 NTPfTMhpf2waUdKzhUuQQ3tBb5+VnEAcmKGvUkMUiwuLuhGhHnPPX/6BIeGxJmeV9MvM ZA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3dtyfw13q9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Jan 2022 09:29:25 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7352310002A; Wed, 26 Jan 2022 09:29:23 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 69D87210F6A; Wed, 26 Jan 2022 09:29:23 +0100 (CET) Received: from lmecxl1091.lme.st.com (10.75.127.49) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Wed, 26 Jan 2022 09:29:22 +0100 Subject: Re: [Linux-stm32] [PATCH][next] hwspinlock: stm32: Use struct_size() helper in devm_kzalloc() To: "Gustavo A. R. Silva" , Ohad Ben-Cohen , Bjorn Andersson , Baolin Wang , Maxime Coquelin , Alexandre Torgue CC: , , , , References: <20220125021353.GA29777@embeddedor> From: Fabien DESSENNE Message-ID: Date: Wed, 26 Jan 2022 09:29:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20220125021353.GA29777@embeddedor> Content-Language: en-US X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-01-26_02,2022-01-25_02,2021-12-02_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220126_002943_814692_1B131918 X-CRM114-Status: GOOD ( 22.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: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Gustavo, Thank you for the patch. I am fine with it with a nit picking comment regarding the non-mandatory 80 characters line break [1]. BR Fabien [1] https://lkml.org/lkml/2020/5/29/1038 On 25/01/2022 03:13, Gustavo A. R. Silva wrote: > 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 > --- > 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); No need from line break here. > if (!hw) > return -ENOMEM; > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel