Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1794948lqe; Mon, 8 Apr 2024 23:41:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXj6V91peqJgY0LCngp7M4TaO6WunI0Ietzvx2rdvc8aOZ6X/mHZ6ngMBQEMUMEhGWjvFLr1VG5LfM5dgcrrIUgwEehmVKO46fA9s6XzQ== X-Google-Smtp-Source: AGHT+IGSy2vuXMm/N+68XMl4u54k5R2uEfy843+uoThHutX2fN2V8KksJMhz+FaEKSw+td+HmVcr X-Received: by 2002:a05:620a:2953:b0:78d:50ad:7d5 with SMTP id n19-20020a05620a295300b0078d50ad07d5mr2873697qkp.6.1712644866675; Mon, 08 Apr 2024 23:41:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712644866; cv=pass; d=google.com; s=arc-20160816; b=upp1tdHq3DnS0NEwIWfIi7GywcqxhzT+Z7i7mVojpseqMDZQ1Bkw+XwCsYb9nL/AkU 3tR9rpIULJP7qJ01MYjkwrKgwCzNAny6HSSdsH37870fVOqebb9qtFigprY/IHdkF8I2 qOXXshZtx2dOPGLD5ucr6ZHcV+XzK9mAKPGLH0GmpJMOROxz1x0JHqQt2w3AGhkgkeKw uj7M7yf5AowieSvhL8rJpSMRRCKP6PGV0ahKlIl4gSB40xK4dS78ndrFRZ/C6AgTY/4p yTY3r/5Gvd/1GW0DKu+yzdw2IIuJwA83U+wg04z8R0bPNYic+KVIfk7ZYTagVgYZTTJR 1VNA== 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=0jM/2z26pHl1ahZGM5qsx5eHbqGHFWgwdLhCwXDhXfU=; fh=41Kga8p/jkcZ5CZHD2j4nD+ViS6HGhk+IVaQJWJ5MRw=; b=rORgUzOqaaBfs+gJQ2uX4vRMt9P5U73HVrgKPZ7S4ZUxaY7ZSDlpCMfEYxdSgF8Yrg N9HxyNHbir1D9rCY79Bv+gDS/08eejlKl4MR+A6qq5I9/YzTy6HzhXdaTuLq6V46ffPE fu37NJizRfs3HnPXLfYqXw6XkorA2AmZQCtWv0dgWmyChdUneVUQJnFHPrkTEdHu2SF+ hZ+whWuRVDsnFBBTX3p1L6JqVPKit9/bUJ994cep3SeMdfgTtz7/dDqn6JVhwEHULmTi 7BcSEnE8Drg0a5P0rzTuPh1ebE271Bp5zL/l0+9uAIjIiMBovgFjOhQkYRNX0o1GROcp pvhQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XH5Ev4Go; 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-136311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136311-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z10-20020ae9e60a000000b0078d33603c90si9585136qkf.711.2024.04.08.23.41.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 23:41:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136311-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=@bootlin.com header.s=gm1 header.b=XH5Ev4Go; 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-136311-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136311-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 669651C216F1 for ; Tue, 9 Apr 2024 06:41:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5F56174431; Tue, 9 Apr 2024 06:41:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="XH5Ev4Go" Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 1DC8031A66; Tue, 9 Apr 2024 06:40:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712644860; cv=none; b=V+H/4so7/71J5dy13CL6L5zMC9uYYXrzpIp/IORuQ3JiuN4ykBfbJZUUcmM/LD3lROOxACEayDPPUxUeuROz/sp9OeQuFWGWHo9oIQzfajpj/fn9vw8HJ4pqdqROBAL1D9o9KH5+r6BV8jtZYvnhcylQaGmfbWtgTAjlckpDTMM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712644860; c=relaxed/simple; bh=GZxSAXRKtbGww5a6qfLWU9cez/PQgMG8rq5k8imZh/8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eNu4TEsBkXatl3OkaB5cI/x3k+QIb3g7kuC2Q6/Tws/Yk8mWAId3iqgupjbvfboYKWItkYhxIQjfSFmN8N+Xj+sKY33vYy7KWNvLFQig7RA4FWmzvzAoLyHPUcaaof5NDxV5+IdJTAW+rcQ+TMD5GaH4+VrqOHpq4vW4ade6Wmk= 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=XH5Ev4Go; arc=none smtp.client-ip=217.70.183.197 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 DD3C91C0006; Tue, 9 Apr 2024 06:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1712644855; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0jM/2z26pHl1ahZGM5qsx5eHbqGHFWgwdLhCwXDhXfU=; b=XH5Ev4GoCWiNGeuljZR2mZAVid1756rDIx9BMDPGPJEPuz/AnpYxKPJM5z4XBXWaP8nema Yoi+rYt/q0fY3akBTuLWmv1cxWW07fpVH1EIhtEyXQWB+rVPB+HzeMmvcMseHZwBPJIO6G P3fKNhH2aeb9DBvtR4t7LTO78ZhXyewJegqV4ze33Xtmwo0+DdHWcnju35j4Wtd2IdP8Bq BQycnPZP0DNTe7cpvXpFNUc+bXfxp36lrm23IXP88OOU4zzrBiur6rZTdAcy9JVi/j8NZO BC49GccZpVP6CKy5JtO8Hmca6lIrXkqwUlokzBzQ8P2iLNB5gFJiZokID1zF3g== From: Miquel Raynal To: Erick Archer , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Kees Cook , "Gustavo A. R. Silva" Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] mtd: maps: sa1100-flash: Prefer struct_size over open coded arithmetic Date: Tue, 9 Apr 2024 08:40:51 +0200 Message-Id: <20240409064051.91775-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: 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'3ef4600f12269d489933b3835fe8d43621e4ee6c' Content-Transfer-Encoding: 8bit X-GND-Sasl: miquel.raynal@bootlin.com On Sat, 2024-03-30 at 17:55:35 UTC, Erick Archer wrote: > This is an effort to get rid of all multiplications from allocation > functions in order to prevent integer overflows [1][2]. > > As the "info" variable is a pointer to "struct sa_info" and this > structure ends in a flexible array: > > struct sa_info { > [...] > struct sa_subdev_info subdev[]; > }; > > the preferred way in the kernel is to use the struct_size() helper to > do the arithmetic instead of the calculation "size + size * count" in > the kzalloc() function. > > This way, the code is more readable and safer. > > This code was detected with the help of Coccinelle, and audited and > modified manually. > > 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 Applied to https://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git mtd/next, thanks. Miquel