Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp518594rbb; Sat, 24 Feb 2024 10:21:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWUNvq6DgdH9yLsK13rxK1xvPJoa/UyVMai0c8NxhDYfZzJFDjXwrM30/B64kfxlQOnbOjvCaNU2vfmNsH4XzdjzONr3+CQwcdf1yxYrw== X-Google-Smtp-Source: AGHT+IHLrIxf2WGh2TPhjbEhIPOiS1RpdXv+q3m3xhmLEvND+VDnwl3c7NJWH1zq7VpjszbsCHGT X-Received: by 2002:a62:5ec7:0:b0:6e4:aca:ce0d with SMTP id s190-20020a625ec7000000b006e40acace0dmr2980252pfb.31.1708798865704; Sat, 24 Feb 2024 10:21:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708798865; cv=pass; d=google.com; s=arc-20160816; b=edg5xAI01T+29ZHxPqwp1AIOXEzJD1txzYM0Z0mKrQ37XedLuNHpvsU3hjJyDZ0/7f 63Lt9l4aFDzX5CKnHmUKK+sqPEC7VXScpzX5Xb8lbrP+Chg9U60PHgVtTsLy3bGV8mij bBZZtcGrClm7pQIz+BkbW8xp5aA/PGmVfb/4NzR7mAxpTi5spabeXzgwrkS44/XKPsWi qv0eMah0ObAJfzLNAZ97+G3OxcbXIXAsUfzwd24Btai/kjdSo03nPlKKf9+kIyj28Wo+ uhAT/iv2fc9jWyj9cf7g94wZYJVyfXpI7SflFqLj5vDZtPt7Y7lFPHGrAPZYJ+my7xwP rICA== 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=yZ2RNuTdn58OeLUeASD4xIZSkgrf/HrgzPl+TGv6sGg=; fh=+6A/t8qn5Sb112Ta3HM8G9NUQ6tda76uIBYFpMMy4yA=; b=WclbXP+l9//FmncuyJCMUBcNjPbgfUS0kjRI+CHiFQPt1Fiu0dxKiVGp8pDD0KvdVm Ch8Dugcx3SAnlz+dDtLWNA9GOm8MAU1Z92nywwzvTP0muPC4r05LVb4XeyNdlV4YHzIF MlyDHUB00Fvcs9SElRLtALKLOkbU+W+3zBilahK/NlcWBBbQ9ZhaDu1jX5qi0GDnlnhd AQ/ccYF/7lv3PHTiCUSqsEzpzN0ibBLsiFeZaVM3xWl228JZUiqOkhXQ2tWmEmP0AuPP CA937wb3Nvv4UVWQ6VZRkfqM0pGvfN4HObpygXnkjPP193Z8Bh8cmVEL+97vsrrcUC3Z tTBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=IEP426xT; 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-79789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79789-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=gmx.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id p7-20020a63f447000000b005df433fcb8fsi1155939pgk.133.2024.02.24.10.21.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 10:21:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-79789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.com header.s=s31663417 header.b=IEP426xT; 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-79789-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-79789-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 66B01281CDF for ; Sat, 24 Feb 2024 18:21:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3CF54D10A; Sat, 24 Feb 2024 18:20:34 +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="IEP426xT" 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 84D514CE04; Sat, 24 Feb 2024 18:20:30 +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=1708798834; cv=none; b=C7HClWI68Q3JcL/XUcialeue4YpSNBWPjgAY6xWHcGshDW3w3pBguPe9SCAYyJah5aGDf1JzAcGQE+Tv0ZdPalhfF1lMsvoaHEuIYsaDCfktLoZI1wEu0Y+h1LplV+bTXVP+PrrS1SnecstMXeNjTgbsI+x/MRDmtEd0h7dSCzA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708798834; c=relaxed/simple; bh=HLdtFuwBDRNLRQYjgEwBZfjetsumFZP9EINs5eu8Ui0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=qxlRoVwAQO1HoEPqf/rH3aJKbNOxAmj7EAljzJyMQJa+hURysmf8qNvEauIrfeQqN4DRp0ntlUGSS/9JgDU9urwUPwwAr0KtMm9BJScMeOGOJLePt+EVERfaTp1W5/EmXlDz1JxHZmOWJI3lWWuacyPRxE6tNv5VNjA25v+yvlA= 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=IEP426xT; 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=1708798805; x=1709403605; i=erick.archer@gmx.com; bh=HLdtFuwBDRNLRQYjgEwBZfjetsumFZP9EINs5eu8Ui0=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=IEP426xTmej+7wKw+cfrPlRcwHyTD2bo6IKM9j8f4FRW9IH91ACv+ZZ1oR3ljs8/ jzGmx3XrzB5p21J2sX+RFH2XbY99Ji8EnAMnX+wVs7fNLy25JjsA09DAIoYOx2ge0 z67MXv0gRBZhaq2tJjVTIeA3YNcACLUjmpnuKNAQpGAvQ0IYwBm+fW/Dt395Th5M2 0vl+c565fUx5qBgLxOpU3glRVvsS7UrIVxOSqfufnbf1fwBqcJhgMz1dltAmbKJbr k4NAwiyp5iAXL/cFjXQzEXIcbeWD/8QO9NKBkqOTooOHrwh0FoI+6XPTtC5LfkmcE 4OKqJ3OJdITMBpYLNw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from localhost.localdomain ([79.157.194.183]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mzyuc-1qjUQ638qs-00wzVL; Sat, 24 Feb 2024 19:20:05 +0100 From: Erick Archer To: Chandrashekar Devegowda , Chiranjeevi Rapolu , Liu Haijun , M Chetan Kumar , Ricardo Martinez , Loic Poulain , Sergey Ryazanov , Johannes Berg , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Gustavo A. R. Silva" , Kees Cook Cc: Erick Archer , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH] net: wwan: t7xx: Prefer struct_size over open coded arithmetic Date: Sat, 24 Feb 2024 19:19:32 +0100 Message-Id: <20240224181932.2720-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:Zqwqz6nr2f2W88YDtxj5s173lC+WL8Q3S4fkpDNb1BxCayF7w1B hiCsPIspmSeo9iD2LNzgyOJJHCXzOZK9RUcL/lcMGu3szbUEieZxyCk7aITHWPn7rAqhg5T XMbRQYVfUl73uwaX3hZiEp9ssE/TFiYTLsCvjHa9X7FnAK3/MR5hXC2FrIpTIL7SH9uIvZX x6DXFyrAcH//mveWSeAMQ== X-Spam-Flag: NO UI-OutboundReport: notjunk:1;M01:P0:H68dJOmZMmY=;ChL+qRCgvBIQRtWHzfugkT2SI+x +Oi5d92008y1yW13c9DyKvLTBUnq8BrfHQxxe4JNI3mdQv3/A6xOPpkdibF5VA3UzCusMrVKp zyCD9mgiwg9b6J5nntqh2zG0U3qvfWGehEFhfpKb6KR106FlFfFh/QOtolxgv44VOD5amdtFU DxoEEqDnC9rhmLI+BblRg+ndf/8KF8NCvlmuSpRYlGiB/4towQTW4cBmMzf1iCmMOenzkClIo +xcZEnxGcaN/kcYqYu7sQXHjBiPqVYXFGlst2TbuX4tN16RIoufpiuEb6O6OvgMAYEj8IfqtA SIVdkuLcsw/MMIsO6LRS6SPprEGJ/XBzWmjnhBrYrJ9sfhrvlvuUUWik3Ez/hvNdb1IUKrda8 FdPQ3Ll0jS3MgCiehwqX+7URUqirCX27rHv2447iD4gV7WIeie6PUo2H8aqNs5ccV0XErA700 I0NFCSCKj3E8MKQSmKv/ahbtjjFLcn3nwMi+vDPW4Cwrxdk3chqIv37pWsqeHl9sffEm2diZ3 3zI26HBTz/i8jWm/V2us69meMXliDX7s6yDSU3vPOR2xtxxAlR3GM0Nvt0x8XU08ezOEmBuN4 sYVAySeTgDD+DpHh8vjTff84tfABOXYogOLfFsPBSOnh6jmV3owJCScKfndCeatsurWkRloW4 kuvWTlMi6LxB1wJGnFlD4GstSHVaiYFYbGyChZ46yV6N+CYFs/Q8AXnnOCkdAoO5Vkfrb7/+E wrBaV2fyfF2Z+r+zf3k3kY34l8bp+RcU6wrxQOOttNoJ/upP38pvBe3BNXNQyVGWlD19YO7N/ qsK5qexm6Y6XWfZcqex7o4fysVoq7JLhrF63tUdBRLxcY= This is an effort to get rid of all multiplications from allocation functions in order to prevent integer overflows [1][2]. As the "port_prox" variable is a pointer to "struct port_proxy" and this structure ends in a flexible array: struct port_proxy { [...] struct t7xx_port ports[]; }; the preferred way in the kernel is to use the struct_size() helper to do the arithmetic instead of the argument "size + size * count" in the devm_kzalloc() function. This way, the code is more readable and 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/160 [2] Signed-off-by: Erick Archer =2D-- drivers/net/wwan/t7xx/t7xx_port_proxy.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/net/wwan/t7xx/t7xx_port_proxy.c b/drivers/net/wwan/t7= xx/t7xx_port_proxy.c index 8f5e01705af2..7d6388bf1d7c 100644 =2D-- a/drivers/net/wwan/t7xx/t7xx_port_proxy.c +++ b/drivers/net/wwan/t7xx/t7xx_port_proxy.c @@ -543,8 +543,10 @@ static int t7xx_proxy_alloc(struct t7xx_modem *md) struct device *dev =3D &md->t7xx_dev->pdev->dev; struct port_proxy *port_prox; - port_prox =3D devm_kzalloc(dev, sizeof(*port_prox) + - sizeof(struct t7xx_port) * T7XX_MAX_POSSIBLE_PORTS_NUM, + port_prox =3D devm_kzalloc(dev, + struct_size(port_prox, + ports, + T7XX_MAX_POSSIBLE_PORTS_NUM), GFP_KERNEL); if (!port_prox) return -ENOMEM; =2D- 2.25.1