Message ID | 20240209183128.10273-1-erick.archer@gmx.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-59805-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp1065224dyd; Fri, 9 Feb 2024 11:02:31 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVReBLvyCKLmCcil1oDEEEXLZxHfflsvuc4VUDH+us7GEwNxcJlZ388eh4ea8d781JMACUI8ujjHRFhEE1KesO0Q6ezDQ== X-Google-Smtp-Source: AGHT+IHHNRRnul2MfnOr2kyqkWGV2TLP+hXmm0qamr6NPRWti4wJqZ/FokV9SImRuVw3zQyeD8Aj X-Received: by 2002:a17:902:c1cb:b0:1d9:c876:b82f with SMTP id c11-20020a170902c1cb00b001d9c876b82fmr120810plc.30.1707505351044; Fri, 09 Feb 2024 11:02:31 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707505351; cv=pass; d=google.com; s=arc-20160816; b=f0ql56Ok4HeBUhqkSB9lQRwvxyM/Ihk1/W9X2op+uLK88na+cECNNAgSY5ciKfR2+I +FRYWO6W3YdqzHPyVckjGUhLXQxFA6bmk6FUMKV2YurDorf09IdmjCWLEiOroSkmuQRY q6XH25zaXKUNy6zfs2UH7/+6V6f3cxoAwF/QaSvMulODVANOsMSl2CiY+TSkPQnTonBg W7Rh1g6g5BAR3DB7rf6wuopVyx+MiemzwkeTNtQwuYhORXbUKJdFSqAXAYomt3zcixqk vJvn5WQhyfnsx+/Rz65FDCmAvHU67DTw4rUTD8CARWRE6yJU1sHFrZkgnL9EtoQysvGo gyvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=ui-outboundreport:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=IE81ql47aInr4DO/oDax9O5ftrQbLdZdyh+84kTYzU0=; fh=OH+0neplPn+V2otofV6sZXRnOtusMV6u093/rtfaG1c=; b=ckxVbX2xGaCrkCVI5A+j48aJMEQsBF9ZLd6TPCIwm3K5SrKGy5yVOSsyZgDnm6h0/m ZKBRPo76vklADU/nnsCMup7y2XRTGhxU42aZNSopIwpOfoCLDkOYjGGI3UjaGOD2lZiN 5C01Fx2Lm9Fha1JGl2vIiQHz+AZlA3WjdHpP8tZjnDT83E3EflKNyw5iexEBQucmwyk4 Za3mnJFOtiBksy5Q8VThsuKXfGWTof8o7b9KuxfdqHWWIQPhuUG5M2FSYqN7Z76lYXDE eji071QBVsLSzo1QACL7ccpW91HngWsgiI3uS3htFJ54tPuQwoW7CQS8eaoSDayE3qS7 b+YA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=IjUxgM1K; arc=pass (i=1 spf=pass spfdomain=gmx.com dkim=pass dkdomain=gmx.com dmarc=pass fromdomain=gmx.com); spf=pass (google.com: domain of linux-kernel+bounces-59805-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59805-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com X-Forwarded-Encrypted: i=2; AJvYcCVBIRMeRZGI6NzfoJMVvd1G6+HEOSnmAXw/nwTzr9mhjiBmYOw+mjqoHqGljarQPglXt2Em4WvcUyjxmFBYRPa+kNhetQ== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k1-20020a170902c40100b001d955aef796si2097495plk.478.2024.02.09.11.02.30 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Feb 2024 11:02:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-59805-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=IjUxgM1K; arc=pass (i=1 spf=pass spfdomain=gmx.com dkim=pass dkdomain=gmx.com dmarc=pass fromdomain=gmx.com); spf=pass (google.com: domain of linux-kernel+bounces-59805-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-59805-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 468D9B2134A for <ouuuleilei@gmail.com>; Fri, 9 Feb 2024 18:33:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 027D08289B; Fri, 9 Feb 2024 18:32:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b="IjUxgM1K" Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1842D5478B; Fri, 9 Feb 2024 18:32:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=212.227.17.21 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707503524; cv=none; b=VpCFGtC4oYGfnYGBQyH2ZOpQooci5z8CORgE5UoETg3kSdv8nubLZzTm25OGCOgJPR4oAVp6kS8ecOWyq9oKBc54nhO+fTVFnimnGyW5WT9Unnestpjs3yQei1JMzS1toL+9EuVEjSfDY9dKeuN6GW5Lan5qUvrsFlUu6pu0sO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707503524; c=relaxed/simple; bh=Lm6QEmxYFtHMAzQ013WgLkguXgBWkgyz8h5irU3s7uk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=bIV34MBImjLgXQ0ggiSfoWqJ5Oi2h8BIwZKkVnFHBdp3WOsDBlUAbnGc7BYFOIcKdKHuVPCPSuWcR1pnF36eVrFD20byUJnz2WKXxnGU5qt5gYmmBW7ygqKy8bY4DxYneRQjvEUkFLBpWCf0uI2Y/de7wAkATJwbQkqlHCCG9t0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com; spf=pass smtp.mailfrom=gmx.com; dkim=pass (2048-bit key) header.d=gmx.com header.i=erick.archer@gmx.com header.b=IjUxgM1K; arc=none smtp.client-ip=212.227.17.21 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=gmx.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmx.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.com; s=s31663417; t=1707503503; x=1708108303; i=erick.archer@gmx.com; bh=Lm6QEmxYFtHMAzQ013WgLkguXgBWkgyz8h5irU3s7uk=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=IjUxgM1KUEA4+SU/oU9vYEvsUSF5P1uUmsqB/zO1mJUdY/RDcF7J9EZKrO/SMsXV X6G8iPpPThxtYswAbSlMmyVhn8/sMxxcfRPHi+8xVls2ZuR6HtygWdkNgdE1gbxqa W/zhKX53UV7mulnMLeNP/Qh6YT+nvHyunaCkzwddL3jXeezPaF0xICRRveQfuRhIk 36KB43DxddnP10FmErLekxV12FixzvJS19FwQmjJXO/oVCpCuO0fSzxzo0dFRN02t UBp1wfqFGN25PU6ceNcdHjpOmZBEThXOHafTOvH0CEYE48Uq75gZlcL+SWHwAwYIq idEEbLGbe4Uu3pD2Ww== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([79.157.194.183]) by mail.gmx.net (mrgmx105 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mof57-1rF61e0PM1-00p27r; Fri, 09 Feb 2024 19:31:43 +0100 From: Erick Archer <erick.archer@gmx.com> To: Florian Fainelli <florian.fainelli@broadcom.com>, Thomas Gleixner <tglx@linutronix.de>, "Gustavo A. R. Silva" <gustavoars@kernel.org> Cc: Erick Archer <erick.archer@gmx.com>, linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Broadcom internal kernel review list <bcm-kernel-feedback-list@broadcom.com>, linux-arm-kernel@lists.infradead.org, linux-hardening@vger.kernel.org Subject: [PATCH] irqchip/irq-bcm7038-l1: Prefer struct_size over open coded arithmetic Date: Fri, 9 Feb 2024 19:31:28 +0100 Message-Id: <20240209183128.10273-1-erick.archer@gmx.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:HHE2RklMAgct5mWgoo5roJAE0JNG1ajQPkAW3/w0TU9s7QMGYgc lJppmFsPQYybduHX/bzeNYbj5G4Jt1opcVxoboa+zy5EijRyvzU2sNMr6g8OnyasblpGe0/ NGfu19G/ZifHfDH7yN5YgoW2GJP13JUug+Toed+qXU3eOpPRQ7Udu+DGUDZIIviO+LpRlI8 CurrQGSZ3Uz135e/IeOwQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:aiXGABC/NJE=;4XdU1nSuxoQ18FFKIQEs4U+lHlc hnrMxh53rZP5AGJs/zAZa4gPYCJJ6CZAO1PNSQO6fWONDxbmN4sMcnUAmeeK7mxs0riAVEb6N +L3qsDbnW3rpyXtcPGXT6VOJv6bie+CyfGmPHYeR15B7g5siFCDLCuFcSXq28Qcil2vEz9uv/ y9xsLOFDrxfhtP6UuJhXum9NLbuTjVbE2U7juaIMj7rSKNL01m7c/uFdqO1UJlRVj21FZbZm+ wQYIj3TnTyRSkZwFdXDYKYvTdtoDd9GSgdt23Aft+z8mMwdaYS09wLqHe6ITSZbbZiJ7kKKF+ Hrhk5TwalPX1bQA1mLOmJLRsL4pzRipkBOUVNuqqRYzN2cpHT6X8yWtlhfQZQpAmvHkd0LOKj QK7iuiIrJ1UjUdH4wNwMXSaM6908KrPR24S3uK+Yc5Fz07JwyENal/qJ3GXGYpBiQpnDKNstY yENOkSpspL8S3fcXdxW/VT2YIZhPjhtXz+/yYIIAp7+e6Yxxn70glGZCJIqr9qORbsV+hYMpG Yi6qC2ljuDrr45DUNVSFjjftmGl8JxVLsL6azqLeF3SydEAhrQbxa1oYCpXiLcdDgdIdZV+RC ud86Xow3FZSyL/SwMpZy0a+zu4RuLKjKNtz7CMwSKw8Dgl702quBQQmvCiCJk9SxowOjLHEZV PcrTNjEP/8vc0YMsSXD5CwcbI481OdAmt6nlkL54O0K0+N8Oxx7B0+8L1YeQdE7qeP0YbxPrk 1at286ZydYRlE1FBe18hqvblFXsRQrL2V35i9HggNLoz3CGRsPLBjfPtZTK/sB4113VMCB9JP Nan18YywG4/5JieXd8VJG1jpKerA5Xy11E1pmMrnadea0= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790447938228214795 X-GMAIL-MSGID: 1790449130937715780 |
Series |
irqchip/irq-bcm7038-l1: Prefer struct_size over open coded arithmetic
|
|
Commit Message
Erick Archer
Feb. 9, 2024, 6:31 p.m. UTC
This is an effort to get rid of all multiplications from allocation
functions in order to prevent integer overflows [1].
As the cpu variable is a pointer to "struct bcm7038_l1_cpu" and this
structure ends in a flexible array:
struct bcm7038_l1_cpu {
void __iomem *map_base;
u32 mask_cache[];
};
the preferred way in the kernel is to use the struct_size() helper to
do the arithmetic instead of the argument "size + count * size" in the
kzalloc() function.
This way, the code is more readable and more safer.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1]
Link: https://github.com/KSPP/linux/issues/162 [2]
Signed-off-by: Erick Archer <erick.archer@gmx.com>
---
drivers/irqchip/irq-bcm7038-l1.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.25.1
Comments
On Fri, Feb 09, 2024 at 07:31:28PM +0100, Erick Archer wrote: > This is an effort to get rid of all multiplications from allocation > functions in order to prevent integer overflows [1]. > > As the cpu variable is a pointer to "struct bcm7038_l1_cpu" and this > structure ends in a flexible array: > > struct bcm7038_l1_cpu { > void __iomem *map_base; > u32 mask_cache[]; > }; > > the preferred way in the kernel is to use the struct_size() helper to > do the arithmetic instead of the argument "size + count * size" in the > kzalloc() function. > > This way, the code is more readable and more safer. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] > Link: https://github.com/KSPP/linux/issues/162 [2] > > Signed-off-by: Erick Archer <erick.archer@gmx.com> Yeah, looks right to me. Reviewed-by: Kees Cook <keescook@chromium.org>
On 2/9/2024 10:31 AM, Erick Archer wrote: > This is an effort to get rid of all multiplications from allocation > functions in order to prevent integer overflows [1]. > > As the cpu variable is a pointer to "struct bcm7038_l1_cpu" and this > structure ends in a flexible array: > > struct bcm7038_l1_cpu { > void __iomem *map_base; > u32 mask_cache[]; > }; > > the preferred way in the kernel is to use the struct_size() helper to > do the arithmetic instead of the argument "size + count * size" in the > kzalloc() function. > > This way, the code is more readable and more safer. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [1] > Link: https://github.com/KSPP/linux/issues/162 [2] > > Signed-off-by: Erick Archer <erick.archer@gmx.com> Reviewed-by: Florian Fainelli <florian.fainelli@broadcom.com>
diff --git a/drivers/irqchip/irq-bcm7038-l1.c b/drivers/irqchip/irq-bcm7038-l1.c index 24ca1d656adc..36e71af054e9 100644 --- a/drivers/irqchip/irq-bcm7038-l1.c +++ b/drivers/irqchip/irq-bcm7038-l1.c @@ -249,7 +249,7 @@ static int __init bcm7038_l1_init_one(struct device_node *dn, return -EINVAL; } - cpu = intc->cpus[idx] = kzalloc(sizeof(*cpu) + n_words * sizeof(u32), + cpu = intc->cpus[idx] = kzalloc(struct_size(cpu, mask_cache, n_words), GFP_KERNEL); if (!cpu) return -ENOMEM;