Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2531504rdb; Mon, 12 Feb 2024 07:51:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXmws0tmXNa2GDGg2LZcGXFWtE772W9ZNs7/Zd49ph17sDF10jT/iQ4dVC9pmIpsv4VsHviBkvwJWY/SiPBTu3gOPoJ1mMLlGSJdZm3SQ== X-Google-Smtp-Source: AGHT+IEUqLgFlfPEAn7VPBtHKFDgAb0lY2P0lGGftshIeHf0tgnWjG9DMky0FpHAGd8JN8WubVRY X-Received: by 2002:ac8:7e83:0:b0:42c:6412:ffe0 with SMTP id w3-20020ac87e83000000b0042c6412ffe0mr11009122qtj.29.1707753065997; Mon, 12 Feb 2024 07:51:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707753065; cv=pass; d=google.com; s=arc-20160816; b=ot9S1ihhsn8LQK9Vq46uXhdiYwMOUP26tkd5Fi3zaLrS1ik+OyAPYxo8KrtYzb90tE f2TTEoONRwnad2Y30VsCsmw2Ax1JXBnYIpTdDaosifeeMjdSDAzNJRXhXFQgpjl16W6H M2WthqrKhULyN0Notcri3hJPF9chuXf5uy5PswCRZouaoYGohGNPGgn5ly+vaAekEDl4 fuxtjx290KNMlkN0jvVsUTkwyz76tdgUiTx8uDXPmh+FB0QV4On1NPNjc7Lbdm6Freby W8LT1eBdbr4Zwe0UsuN4MbB6WH/2s5Q2Lant8/cdhtMbA+UAhOM3XT6ATjDHbLsuxIXd Y4JQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=DKJbvwlkOP1SRi/Z77aD8twgFDCEOZM6sW2cKw9vfP8=; fh=agH3cwQEfFswIRVBe6QiY/jrRK080iHyV6FQgmlSa5s=; b=RQYjinRel40hzUH8N39yK4Qij3NOsEmo0lS/VOrINDqdHRiknK0pehtrjpd+uhgpbb 4P0Yge5BqOYSHOv6I28E/sFQgSC1yMKvOVOW7yYiHYfC5t5aDGpW9oLjjKOoSBVbk9JR JzCh5nXWg5pjObzdr9FUq5CYmIGoRh6Qfo+DVgCy69RHPtJBWu+tn9PLcU7FuIvyQxsq /EnN302ynu3h1RrU4RbmIdltzddlnJlyX6fmTLDLzJKiiA32OEkO9dPt8iqcB6bnUuL6 PBPeWbkhqdOVnEMJ1viVe4ZtfQwAu23/oJhaQjv6EGAthpD0E81DuNEJNzf/MNyUKZ6b axHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SvwmNzT0; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-61922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61922-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCXbjQEUK/v5HlXFYW2kzLYYrxH9HA8Q2eZnd+iYG99/+rxzX0s57LjCTrOC+uea8al8uag1jJ1k1WQzYUaL7ayR+YnbHf7qnZfzFNJgdQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ks18-20020ac86212000000b0042d54d5a4b3si625021qtb.118.2024.02.12.07.51.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 07:51:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=SvwmNzT0; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-61922-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61922-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id B17861C21F27 for ; Mon, 12 Feb 2024 15:51:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0CE3B3CF6C; Mon, 12 Feb 2024 15:51:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SvwmNzT0" Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4FF263CF45; Mon, 12 Feb 2024 15:50:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707753060; cv=none; b=ouYg03WXzA4dbgHwKgfoJB/M4LG96Dl8GnX0IZf5p1fZGp6ap/nZG8Yl6L02B1mP//9DdCA3qoJToLkXMtk5fzmjxx3Cq53U6CbaM4MCuIeyYOW3DvUFSMM/xPg7rN2wsFMQfYLfnlbPbUeEAdOVghNfqSs/tCZq3KeqP3kHvsE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707753060; c=relaxed/simple; bh=xGPVBigagNRNZsOr8Us5qwixX890ZDiKv3BG7ESfd8c=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aj9wDoZuzsPfaV1CYNdpOagGZjNClJTdTl+CSElqY/oBZhJLpwdIrJeO/ZuT66uoR3bNaxCLO+Tk0Smn1rWu0n/ojB6gL3HIzzzfItDLunA24wfasLsUwQkrbm/ZmxPPqiZrevhGqXdwDMRJp1p3CUJGd/MB8Mfrvz+z2Ulwc04= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SvwmNzT0; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-411a6ceada8so2430815e9.3; Mon, 12 Feb 2024 07:50:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707753056; x=1708357856; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=DKJbvwlkOP1SRi/Z77aD8twgFDCEOZM6sW2cKw9vfP8=; b=SvwmNzT0RA9ei8qM5L3z82b1PaJeGy8sT76VQmIY/qkg5unByyq+C4R4Yj05kPBdtU I4yEvicgtx/gFjmh01DWMcQcH+XNI6u2G9I7IbiGJsd3P762yqYYdfvnHXVhJz/FyKfG HxFuLAv11hYIugqm62tdDia74c32mJMHKJjpylue1UOUrXxs/gLqtRFvFKdRs/yjLpxh rW9a75f6O8UAOLGx0x1ixZRq1UgaasHcinr5vMimoxDE4WepUoqgHWE44FfcYIsjTK58 aSKJMU98eEAA+4n8XsTbmPP3SG3FgPHMFaWGSBrFdWeQc/Jq4UQHyJu1I6Uq+D8Mik3t iE1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707753056; x=1708357856; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DKJbvwlkOP1SRi/Z77aD8twgFDCEOZM6sW2cKw9vfP8=; b=LSaKoK50VVx+TAXnMSfHX5EPU7DaEMCoPGqSk1I+Az5L3QNPQLkGIyqW7vBYNTccfB zxYpHL9CD2fLMjFOqk88sRTTkEzy3JBSKrEA4wTHfl5aJb3zIocVwSMyfJ/jWLknr7eW QUXl5MS8Q7nUzKCraz6yi4JBg3b+Vn8pTBjIvfGxILdFSOp0ls2g7hJPYlubIdfyrg/i hydUZaZeqLJfGzB9K76vqjUL5HHkQ2eB+PbhZhPhtNd9paTdPlQarBlGc4ow+eqzblCn kPrT7o1vmvQ9AS2DiABMbeQvZf9tT15LiYetWXRs2MHBGIJiAvOBk9NgUrbB3RgTw2tX xHQQ== X-Forwarded-Encrypted: i=1; AJvYcCUtDDd1vuRU6Qlko9Ohlk9y9RWmQOVxZ8t0twa2avyrANKGNGupu1vzMVzoMQ+7RwsY41QJwdMcdkt7t79ZnJjveoz3sz5Xyw10Aen3NBrFxUkOgcgJvuvvYcHHSzkepl+bY1/F+C95+MIQ3CND X-Gm-Message-State: AOJu0Yy1635NpQKf2U7ehM10np7Xb9UewFQ7wWINvpGTruaC3xTOXRp8 r0XmxIKYSmN7ehMVVRf+7SyuR9X3tXESDHxBR3PuaCIj4jFAMv3E X-Received: by 2002:a05:600c:4f8e:b0:410:7897:6c68 with SMTP id n14-20020a05600c4f8e00b0041078976c68mr5816893wmq.3.1707753056342; Mon, 12 Feb 2024 07:50:56 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXD8geSAWQRDN9wEm603b2P2I5b3hHLLwQxozbSbN9lQC3GeJ1rtH2ArXvmkp3fKlw5svrA2kzag1dDitt1chiYFYYX3/ScuD+vNzYTtZceStz9yc+uZQQUcSqUD4QbIkxT/xnW5F2FDIV/1+TZR8yqPfh3ZyX76+NeuMne3GylIBnKfnWvtuqLfjbUBQsYp8ZIrpGbBieEQ760H/W9k5dLtJWVtGxsMeaZWV+AAqO7eQexjgKwBTwyEG6SW70VB2GIjgL0Y5+7YjcwhWrdlupeCsVeyXHsVcO3jWJ5+kOhwBMYShVe6O7QjfUgjIO8oj7YOiNqtm16Ro3wG3hDmGzF8WBUj0rvGe8voETzjsYfm5cbaXYCY9qGW7XvnMsp3SQp+q5A0BerKef3Ugsq+wPxsB1ftqw48DL4VCiuuWwDfUFo5DvfAXbUt9Pi+QD8tw0E1oDbOw6nlZwrL1WOcNCQYkapgZzda8W/GkUv/uDIR1bjXlOyx1j6afEPPLP0B3Ow0UIkzH73CFIyOSfw+9QzTaRGIVXsmBPWMtfDX39CUh2a3FFHkX6QYNZ2tO7/WYtXgZ1tNK0zakRtRto20y0HXrJVOn8HIxl036q0xjzwI7BmsgWy7Kyt Received: from [192.168.1.135] ([207.188.161.188]) by smtp.gmail.com with ESMTPSA id j36-20020a05600c1c2400b00410833555d5sm8461390wms.21.2024.02.12.07.50.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Feb 2024 07:50:52 -0800 (PST) Message-ID: Date: Mon, 12 Feb 2024 16:50:51 +0100 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 v2] mtd: rawnand: Prefer struct_size over open coded arithmetic Content-Language: en-US, ca-ES, es-ES To: Erick Archer , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , 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: <20240211091633.4545-1-erick.archer@gmx.com> From: Matthias Brugger Autocrypt: addr=matthias.bgg@gmail.com; keydata= xsFNBFP1zgUBEAC21D6hk7//0kOmsUrE3eZ55kjc9DmFPKIz6l4NggqwQjBNRHIMh04BbCMY fL3eT7ZsYV5nur7zctmJ+vbszoOASXUpfq8M+S5hU2w7sBaVk5rpH9yW8CUWz2+ZpQXPJcFa OhLZuSKB1F5JcvLbETRjNzNU7B3TdS2+zkgQQdEyt7Ij2HXGLJ2w+yG2GuR9/iyCJRf10Okq gTh//XESJZ8S6KlOWbLXRE+yfkKDXQx2Jr1XuVvM3zPqH5FMg8reRVFsQ+vI0b+OlyekT/Xe 0Hwvqkev95GG6x7yseJwI+2ydDH6M5O7fPKFW5mzAdDE2g/K9B4e2tYK6/rA7Fq4cqiAw1+u EgO44+eFgv082xtBez5WNkGn18vtw0LW3ESmKh19u6kEGoi0WZwslCNaGFrS4M7OH+aOJeqK fx5dIv2CEbxc6xnHY7dwkcHikTA4QdbdFeUSuj4YhIZ+0QlDVtS1QEXyvZbZky7ur9rHkZvP ZqlUsLJ2nOqsmahMTIQ8Mgx9SLEShWqD4kOF4zNfPJsgEMB49KbS2o9jxbGB+JKupjNddfxZ HlH1KF8QwCMZEYaTNogrVazuEJzx6JdRpR3sFda/0x5qjTadwIW6Cl9tkqe2h391dOGX1eOA 1ntn9O/39KqSrWNGvm+1raHK+Ev1yPtn0Wxn+0oy1tl67TxUjQARAQABzSlNYXR0aGlhcyBC cnVnZ2VyID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vjYyrcyAOarX2X5pvMQvpAMADGf2Z3wrCsDdG25w2HztweUNd9QEprtJG8GNNzMOD4cQ82T a7eGvPWPeXauWJDLVR9jHtWT9Ot3BQgmApLxACvwvD1a69jaFKov28SPHxUCQ9Y1Y/Ct In-Reply-To: <20240211091633.4545-1-erick.archer@gmx.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/02/2024 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 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] > Reviewed-by: Gustavo A. R. Silva > Signed-off-by: Erick Archer Reviewed-by: Matthias Brugger > --- > Changes in v2: > - Add the "Reviewed-by:" tag. > - Fix a spelling error in the commit message. Change "more safer" for > "safer" (Uwe Kleine-König) > --- > 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 >