Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1226647rbb; Mon, 26 Feb 2024 02:56:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVGo4CeAgSX21KbpcES3K37fXE94BM391oQjHTSVinwhYHuXQe37xZDnN61YjxvYrTOEoJnfVckRVN4u88AThuhPq2cY7QWCbPa6d9++A== X-Google-Smtp-Source: AGHT+IGsx7gosAqhu0J2ttHGCT6RE2ujo+LOuLVLtAUqjTYecBJIklaF82NeoLS6+FIBT9dgSj2Z X-Received: by 2002:a17:902:a383:b0:1d9:8f6e:86e8 with SMTP id x3-20020a170902a38300b001d98f6e86e8mr5847117pla.69.1708944970856; Mon, 26 Feb 2024 02:56:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708944970; cv=pass; d=google.com; s=arc-20160816; b=SKmQEGpuMXtMXQOIUn9XpBB5Pz9uz1Vyy9Rj6YXbIxrAjInFVqu2VDTsqif4aUypZF VhTHAgJFLE9p/WFsBe9RhIhz3DYCFbs0aBeJe/vCjDQ2iU/1EQzDSfqNU99B44RrqCq2 mC8yvtMtMTdBaWoksai2BXJE6TofFAhvx3lPEq2BxzfDnXyZ+ev/ErVp29kund57cXpK ft0OmPrxWsEaO0J4sExtVWtv4nVpPg+xAzaKINYFTMsJu1sfcc31vLxWQjEyGBkKm8hp zGVUuaeiLhpGpc64nOYTpKGB2GGzJPq6g4PFMGxsIwJhD35ne/4aaZgifMqwpRnDb8AM 28EQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=zL/Tgozd757x0uspKJ/QO1fI2sa1DUP6bzOx+70NEX0=; fh=djURpuNwb5yRU7Y7IYM6kRjCsZRxvVPjj2AKOQghVkw=; b=e+ocWty1DMjo9rhM+7PZ7EYgUag/ZgqFZu3o15nJrpNy9lPuf9ARgcRXC+WiKQqWgc qbjItDt6aJ5hF09fGBRQ7I/7LHZ9WLgVfmjtYshQx300zGqlafUjTsOoAiTeKGn37xoY tyH2IV8yf0pdrP2N4OtjXPTDkR9Cs+7yrNUVoz+wvkVUNJ6U1gFmmRNzOsU/cegjzdF8 BFgzCzXEWoAxYbElE/lA1ZnkkS3UJ94i0Cj+DjOdgWKmkudMtuRG4QjTt8dLFCk+LKLa RwjvLjRn6sRknCBfoZ8G5p0gfNq+ml+MvjbgdJRjHPUDlAPLhjdQs1m/j3E6QlYQdffF C1Kg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=PbNfK+Fe; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-81203-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81203-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i6-20020a170902cf0600b001dc60525a57si3490025plg.449.2024.02.26.02.56.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 02:56:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81203-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=PbNfK+Fe; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-81203-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81203-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.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 3D2D928A426 for ; Mon, 26 Feb 2024 10:50:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44175487BF; Mon, 26 Feb 2024 10:45:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="PbNfK+Fe" Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (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 AA6DC55C01; Mon, 26 Feb 2024 10:44:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.195 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708944301; cv=none; b=RgJSl8+k4xco9Ln9keU4uFxnr5MAp5NHSA4DXxYSSkjsQQx87kn9slSdN4nlrEesaRqpI735Seio/V1hngM8bF10G0uz8ecOdiSDIMHy8mXzP/AViBy3sRc/tIOw3NH7jWjRIFnHCxfRKjGkJWZ/gtiJZEzAV2C81xgPRPa9O90= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708944301; c=relaxed/simple; bh=dbzJ5HplGKB0UbVpYH6JV4HOfKZddkYMfHSn2nxZab8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=b0fwZ3iIk82v86fVw7L5GalhKfSIZzIuTm7/j7ieuhHKuzO68YI3eMiab+jrDYpqB7wFDx3lpzHSdhLPNjIro+8BhcsmY3uhVHcrtaQXBY+zLs5voJZPW/lul7h8MqWtjbNgWMkXsmYczsTAjnOyZqydJgiYvL5wOFbHkXkhCNA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=PbNfK+Fe; arc=none smtp.client-ip=217.70.183.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id F18C060005; Mon, 26 Feb 2024 10:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708944298; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zL/Tgozd757x0uspKJ/QO1fI2sa1DUP6bzOx+70NEX0=; b=PbNfK+FefzTpRRZZaLv6nXskQ+mmjm6jtVHrDL7HRvcQUxrt/ON5CBHIra+IRzW5oSP3mC qL0rcEu5cs9tcn9SnBMBL/eM1OxBZfSwfB/j6BSbxCBBSPT6hoADU1JUblR3QK5LVJSHMF MhmzEaiQP7PPOzilGKqZR8Pxp1pjllqW51/TO2+/XDxIS1lzGDEMpvXjGzbNIOhYVx13eA S/xIGuK89v2kZwSrZJ0PAF4SxW3+AiVnLiFBfq6vNJwE0hVbsNPyME4lPuM/CUu/mGz3z2 4ck9hwW45k2IESMkzf5Mdo+mppFvwVwPNaY81MpS+5bJR5rghPxnyXJmZ74hiA== From: Miquel Raynal 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?Uw?= =?utf-8?q?e_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 Subject: Re: [PATCH v2] mtd: rawnand: Prefer struct_size over open coded arithmetic Date: Mon, 26 Feb 2024 11:44:56 +0100 Message-Id: <20240226104456.490065-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240211091633.4545-1-erick.archer@gmx.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-linux-mtd-patch-notification: thanks X-linux-mtd-patch-commit: b'e395036504c4e19d15ba64543a4c3beca373f7a9' Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-GND-Sasl: miquel.raynal@bootlin.com On Sun, 2024-02-11 at 09:16:33 UTC, 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 > Acked-by: Uwe Kleine-König > Reviewed-by: AngeloGioacchino Del Regno > Reviewed-by: Matthias Brugger Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git nand/next, thanks. Miquel