Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp1606711rdb; Sat, 10 Feb 2024 08:55:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVoGhyzrAJI+aYeTwoumTA40qGIWYCVtzAtwAx3jBm138JRFrctHddkNkAGVvJbDBus8M3VnJhtVRvrh0Y0mAiiV1SXqHavry6sZV5gvw== X-Google-Smtp-Source: AGHT+IH5o48dvqYySBT/YYVMVd9y7eYG39X7uliaUFY+htJqfnUND0B0a1PQwEEzYzSKDPy3lLIm X-Received: by 2002:a05:6a21:2d05:b0:19e:b53a:579 with SMTP id tw5-20020a056a212d0500b0019eb53a0579mr2609657pzb.5.1707584099801; Sat, 10 Feb 2024 08:54:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707584099; cv=pass; d=google.com; s=arc-20160816; b=NsTlJ6mr+DJk/jWWx0AbqdynWU6Rbw1VEM7H2cbmludF2IakZQFw2F5jAUT+t/lMzr 4QQ00tLvLbQIFq6w+sxq6P1mL4GYoaIVMrsYidorVDsmfg8BZKP+mm60VIG8+eVDNZAB An1OGU8NFGwf4cTGtN3lDuAOV1I5wLJhH5YEjp8v81eoQ1I+4hUxucHGP0jg67rmFSgj zqL4fRJpbU9YVF3eIy02mgMME9AJkphI7MSBDiPYBo18MmeisYO7ZphJUy9wMt9QHbgx X6tcgck1XA7+QOFqz/Pz1UbCwtJrIEZ3yyLxwHTd7ha2qXfNKvUvTsBKggiZnnDyQMaN y+eA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=tEoQxh0SDX6LhIBHxa1o+jGxPnr7GiGz8Kpi2C96DZY=; fh=U5Bgnjs6Kmo7bnvjfjYxJHqlrCdPx5WXXskd5TQp2ho=; b=pxKLZO0eqtSYyEUk6WThfIooEEsnjJwZYBmuzwvSkrCsW+tKuIYgWrERRAE6e1YUK8 P6akAM+MfWr45Buse9FkDvI9Xg23Bzz6UWAcMQVvy/6RZ5FZjxLxklJRVJXwe+BenIzZ 7A09haR2UIHEzvULtTEIfe3ZE5DvA+uY6hfTJEr8CrxNH7Uqg75C8sZp0GocN6KZCLfV +8o6LhQrDCE1lZLztdVOf+KdH4y21a7I2YKqqm8Kx12Py7vELjYpegLPeZjQfv3z1bvV NnNKvDADj1lkRjeaj7cioUPAzGBDDtIM9b3AWKVfFymho96bIULajAJLALhUHpqcBoAc svVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=pzUct+xJ; arc=pass (i=1 spf=pass spfdomain=embeddedor.com dkim=pass dkdomain=embeddedor.com); spf=pass (google.com: domain of linux-kernel+bounces-60479-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60479-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCVC5/gr3wiZ7565zcynYrOiImOO7wCGHx61VEewdn6eG9Ex07bP/xVXQ8ZaWh2mIXPdD3cZq0b8J4XBaWAb8h3LGHs8A8SSUFx6aW4JLw== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id r14-20020a17090a1bce00b0029692773271si3513823pjr.153.2024.02.10.08.54.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 10 Feb 2024 08:54:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-60479-linux.lists.archive=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=fail header.i=@embeddedor.com header.s=default header.b=pzUct+xJ; arc=pass (i=1 spf=pass spfdomain=embeddedor.com dkim=pass dkdomain=embeddedor.com); spf=pass (google.com: domain of linux-kernel+bounces-60479-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-60479-linux.lists.archive=gmail.com@vger.kernel.org" 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 C1737B2462E for ; Sat, 10 Feb 2024 16:52:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B13465C916; Sat, 10 Feb 2024 16:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=embeddedor.com header.i=@embeddedor.com header.b="pzUct+xJ" Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) (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 4970E20B29 for ; Sat, 10 Feb 2024 16:52:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=44.202.169.33 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707583963; cv=none; b=RRjnLwnucZQp89+TltUVyg/ab85jG5PfBBrtLU81dvm5QIQhQqx66UxQFMlyUVgRkRntifUeDne0GobYmsTHgYqWELtRLzch1f4p75y4BVSKXg2WxFdedxjX+mzBEsKgvC7bI0emZlzrZuFJMEo3xtbG7u06wT/wjFFm+vgdHkY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707583963; c=relaxed/simple; bh=yoZ6jO26gIwzcZY6vg7TXyzEpqXjO6SCow49aXsp1n0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=bSXyWTsCxTOZzlgWb2EThzem6wc5Zf8i/0ZjtoZmpPVLJISjlBIh4Uoqd0P2e+ciaAG9ZiXYnWjtrFvSHS34VnsVPliIOUtmcIpJmtVYzQnR5bNCPXqZdBojvFNVvZoa4JVX3btaocaceTx1KFRv/bLHzdXCkbQQqeVc9WWfMxQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=embeddedor.com; spf=pass smtp.mailfrom=embeddedor.com; dkim=pass (2048-bit key) header.d=embeddedor.com header.i=@embeddedor.com header.b=pzUct+xJ; arc=none smtp.client-ip=44.202.169.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=embeddedor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=embeddedor.com Received: from eig-obgw-5009a.ext.cloudfilter.net ([10.0.29.176]) by cmsmtp with ESMTPS id Ynkkr9s4QAxAkYqanrwRC8; Sat, 10 Feb 2024 16:52:41 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id YqamrvnXbpbBLYqamrftsm; Sat, 10 Feb 2024 16:52:41 +0000 X-Authority-Analysis: v=2.4 cv=OPSE3jaB c=1 sm=1 tr=0 ts=65c7a9d9 a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=VhncohosazJxI00KdYJ/5A==:17 a=IkcTkHD0fZMA:10 a=k7vzHIieQBIA:10 a=wYkD_t78qR0A:10 a=VwQbUJbxAAAA:8 a=NEAV23lmAAAA:8 a=7YfXLusrAAAA:8 a=UFccgQmPsxNMVL67FCoA:9 a=QEXdDO2ut3YA:10 a=1F1461vogZIA:10 a=5kKzt1m56AEA:10 a=AjGcO6oz07-iQ99wixmX:22 a=SLz71HocmBbuEhFRYD3r:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=tEoQxh0SDX6LhIBHxa1o+jGxPnr7GiGz8Kpi2C96DZY=; b=pzUct+xJvY8RJEJgPd9wEOn8J7 knPnoxN+3ygMHpLr1awR+90flpSBlkQihH870kIBwMrc4KKfqtySQpCueQ/dr3wfiITWAUHFHtvzq awO51/AVqmDqRD4dlEmEFY7ajfvym2CE32QZhD0V11CD+NppmGfqNQz4IOwM+rdIvroxJnvknt/jE SNdbysb/FtWPK4UyxtQ5wK7ND0m+GiNVQuDZUP0vkiYFdxUmDk+D4YKiiRr+xLfOoXXhJG1CeG7Hn QWAB0yUaEDSiIJd4Sc3vU+mUS5fLAilI6JB2ekkI4YpkDPV62BCAanWLq5if6zsMad3ed4b1Gr7++ UlKhuw2Q==; Received: from [201.172.172.225] (port=54094 helo=[192.168.15.10]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96.2) (envelope-from ) id 1rYqak-000XHn-1i; Sat, 10 Feb 2024 10:52:38 -0600 Message-ID: <91f29d89-8c9b-46c4-b059-687ea3c57682@embeddedor.com> Date: Sat, 10 Feb 2024 10:52:36 -0600 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mtd: rawnand: Prefer struct_size over open coded arithmetic Content-Language: en-US To: Erick Archer , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Matthias Brugger , AngeloGioacchino Del Regno , Martin Blumenstingl , Heiko Stuebner , =?UTF-8?Q?Philippe_Mathieu-Daud=C3=A9?= , Rob Herring , Li Zetao , =?UTF-8?Q?Uwe_Kleine-K=C3=B6nig?= , "Gustavo A. R. Silva" , Kees Cook Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-hardening@vger.kernel.org References: <20240210161619.12656-1-erick.archer@gmx.com> From: "Gustavo A. R. Silva" In-Reply-To: <20240210161619.12656-1-erick.archer@gmx.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 201.172.172.225 X-Source-L: No X-Exim-ID: 1rYqak-000XHn-1i X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([192.168.15.10]) [201.172.172.225]:54094 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 19 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfISPd1cHrNN3uG8qzmcpm4CQhMbdDRQCdrZfz+uCGWcUe5Cvf4YIFPm3OtUzug3R8MCL/mlNs33LOirIZJ9QaROgzjfGyaO0hetJKQLZ1JqHq7+tml0Z FM0OvivbSZ8s0FI01vKDLmzmKAkmsXITmDXP1gXNBGrv6C+H7BdKiRyLBMSW94CcWmwHEJhlJQKcfs9v7NOQYluu1xxPXl4ikS/MHIS4hikjfsga2e1kTDfY On 2/10/24 10:16, 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 "chip" variable is a pointer to "struct mtk_nfc_nand_chip" and > this structure ends in a flexible array: > > struct mtk_nfc_nand_chip { > [...] > u8 sels[] __counted_by(nsels); > }; > > 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 > devm_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/160 [2] > Signed-off-by: Erick Archer LGTM: Reviewed-by: Gustavo A. R. Silva Thanks! -- Gustavo > --- > drivers/mtd/nand/raw/mtk_nand.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/mtd/nand/raw/mtk_nand.c b/drivers/mtd/nand/raw/mtk_nand.c > index 60198e33d2d5..17477bb2d48f 100644 > --- a/drivers/mtd/nand/raw/mtk_nand.c > +++ b/drivers/mtd/nand/raw/mtk_nand.c > @@ -1356,7 +1356,7 @@ static int mtk_nfc_nand_chip_init(struct device *dev, struct mtk_nfc *nfc, > return -EINVAL; > } > > - chip = devm_kzalloc(dev, sizeof(*chip) + nsels * sizeof(u8), > + chip = devm_kzalloc(dev, struct_size(chip, sels, nsels), > GFP_KERNEL); > if (!chip) > return -ENOMEM; > -- > 2.25.1 > >