From nobody Fri Apr 10 01:06:04 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 099F3369979 for ; Wed, 4 Mar 2026 22:15:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772662554; cv=none; b=RnzXn2c5Q3OJgdKZDXzKnA7fzd1Uq6JFeQEok7xxzTL358WHHgY1CiD6loWBa9ujMe8qyKnJ+tvaj+10xIxM+IbdfPXRGzFILpp9Vw0SI5Cz3ax15FiAGAhzb4z3sS5SYO4/zp83CP28Cafs1Itdn04FbTLg6ZKVX7DdpSRlGC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772662554; c=relaxed/simple; bh=BJvpKKlOTH0Z+xL55mNE8BURDICg+ZGGrGioGa5Lenk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A69RKqlKg0zBqCz0sdFl/84snwecDTLiFUT3d6xmNioCiXgbPS53lscJYAqyKEvILLJCcMw7DUQ+49vSspIcr7PZgxBKE6vGxDfHF5UY3jhuvcC7RcCNiud/BC3lSmgjwTgZjQ3m4G9RgcYvfmaYc/rZaNcREkmZp77gIXS+d88= 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=Cg0Uf/P1; arc=none smtp.client-ip=209.85.210.171 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cg0Uf/P1" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-827390e8a3cso4804385b3a.0 for ; Wed, 04 Mar 2026 14:15:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772662551; x=1773267351; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N6xGxKiEmjafobho7Pm8BBn/5trBV+odB8B7flKPqK4=; b=Cg0Uf/P111yR5kBgi/aD/u7rparPuxQrDrT2gRUDWtb0uQIxOHZuCahJC2uPR4BVG+ L8mld1EBfrSEL4XbRVuBWBLCILcYblVUCoTouWDtesaGGFgge06PZhwr6MeSuAkPRpw5 h+QHUBiYItAdemQf0COHztvqcQjeHZ6mNAix9aZeetMCPM4ApMC0EPg7EKIsI0pkCd9E QNkhyxCkkHm/misXI8ohtvyOdEW56min6jxGnoGp0CP59ZD6u6wqYO1uMK1zmsoMavyN mA+NCJ1XNhObpqSoJG3hG0uG3LG3tGOh1Vv9TodS17GXFrgyfxRNwHsae8ZqELN9M65v ljSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772662551; x=1773267351; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=N6xGxKiEmjafobho7Pm8BBn/5trBV+odB8B7flKPqK4=; b=pMFDHv9XdrWRC4bndeYW4wKOHiUVq8atsKnGOa/+/hMbOtyKTP7Oz8Y1VFjPcX27HK 42NJ3DqU1vDUJWyJJpSd6H6mgng7C2x5plEDoIOhicoVNY7FccUAPkHlGgzBnOQUG4m0 OA9uHbH6eQvXIHnrPkYJYQLcmKdkQYH34tXYbPzfvmlO5m9aV4guv8Reps3CqTwlWtHv +zTJxjY5Z3fNqtSEcaVhrTzvEmVp036UH80DocIBw6+Mr6NHjq+zepzYqQ5JI2nXCa2f JsrDJExLYISnUu6/lMYFvBBd3GuKCjXuv30PBQSw81zlE8pKNG+QvN71md9FKOScIhBC t38g== X-Forwarded-Encrypted: i=1; AJvYcCWFUI8+bTgpYqInXQmdX7bxQ6/hcvxtpeNGsIG/i+yQOxRTYW3F2ozU4IMTY/w2ttjoCJchgaVwKP3yELg=@vger.kernel.org X-Gm-Message-State: AOJu0YwXQQvgUsFjwsnt98Mbw1MmmpsAkhf0lKQB5iK0r7R++c5I/XgD ThzJFwv9PkPJ1/4z1PN7RaeZdh/RneLaHCdRwjvk6FLi9C+KbasXE0GD X-Gm-Gg: ATEYQzwIZ8hScmhwybI4kHGR5f+IJiZxRv5YW7qOPSusZ8DC9vKURintPpDC12DLQaK AaLExwk6w8r4UxQtyq0EK4UYLUzf/KJxYYpsjm8s2O9okLSVuhyHLpZttOYnsdKxgT5+0EhI90m PAhIsH/jCYvEljPKwJBIKXm2j1umcbLizHuxjR5chmJopXhmGStlRapUP6fUFtPTxNZQRDgRsgF vK1AZ+NJHBYWW7IzMczJEnQws8VcTBscDnbO5TxbC6sLWkqy10gqWYEzM1z1VX4oNrTXuWAzOc0 ElTc88FTi/QNsHXBnY5q5VkqkhReI143x22azNgdT6Tbwp2NuAfaQxcKKYRi9gMrmDe32opN3bW 9zsohSL2FhPpFUrUcFW+4MFNUkPyuyiFfwTHSmc4igmSNG0/ICgAInevxgixQ9Dxnb+I7MGKpBW cMimJ+KAYufbeDdkELoaC1wn7HIaSLJGDROuiv7xJWgTyu2fworf4kgA== X-Received: by 2002:a05:6a21:207:b0:394:782c:cb8e with SMTP id adf61e73a8af0-398425c24d9mr73436637.28.1772662551223; Wed, 04 Mar 2026 14:15:51 -0800 (PST) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c70fa6203a6sm17637399a12.8.2026.03.04.14.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 14:15:50 -0800 (PST) From: Rosen Penev To: linux-mtd@lists.infradead.org Cc: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Kees Cook , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org (open list), linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not covered by other areas):Keyword:\b__counted_by(_le|_be)?\b) Subject: [PATCH 2/2] mtd: concat: replace alloc + calloc with 1 alloc Date: Wed, 4 Mar 2026 14:15:30 -0800 Message-ID: <20260304221530.15018-3-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260304221530.15018-1-rosenp@gmail.com> References: <20260304221530.15018-1-rosenp@gmail.com> 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 Content-Type: text/plain; charset="utf-8" A flex array can be used to reduce the allocation to 1. And actually mtdconcat was using the pointer + 1 trick to point to the overallocated area. Better alternatives exist. Signed-off-by: Rosen Penev --- drivers/mtd/mtd_virt_concat.c | 10 ++-------- drivers/mtd/mtdconcat.c | 5 +---- include/linux/mtd/concat.h | 2 +- 3 files changed, 4 insertions(+), 13 deletions(-) diff --git a/drivers/mtd/mtd_virt_concat.c b/drivers/mtd/mtd_virt_concat.c index 89e223edac6a..b56f2431974b 100644 --- a/drivers/mtd/mtd_virt_concat.c +++ b/drivers/mtd/mtd_virt_concat.c @@ -32,7 +32,7 @@ struct mtd_virt_concat_node { struct list_head head; unsigned int count; struct mtd_concat *concat; - struct device_node *nodes[] __counted_by(nodes); + struct device_node *nodes[] __counted_by(count); }; =20 /** @@ -182,18 +182,12 @@ static int mtd_virt_concat_create_item(struct device_= node *parts, for (i =3D 1; i < count; i++) item->nodes[i] =3D of_parse_phandle(parts, CONCAT_PROP, (i - 1)); =20 - concat =3D kzalloc(sizeof(*concat), GFP_KERNEL); + concat =3D kzalloc_flex(*concat, subdev, count, GFP_KERNEL); if (!concat) { kfree(item); return -ENOMEM; } =20 - concat->subdev =3D kcalloc(count, sizeof(*concat->subdev), GFP_KERNEL); - if (!concat->subdev) { - kfree(item); - kfree(concat); - return -ENOMEM; - } item->concat =3D concat; =20 list_add_tail(&item->head, &concat_node_list); diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 241d15235d01..c97167d51fe2 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -627,7 +627,6 @@ struct mtd_info *mtd_concat_create(struct mtd_info *sub= dev[], /* subdevices to c const char *name) { /* name for the new device */ int i; - size_t size; struct mtd_concat *concat; struct mtd_info *subdev_master =3D NULL; uint32_t max_erasesize, curr_erasesize; @@ -640,15 +639,13 @@ struct mtd_info *mtd_concat_create(struct mtd_info *s= ubdev[], /* subdevices to c printk(KERN_NOTICE "into device \"%s\"\n", name); =20 /* allocate the device structure */ - size =3D SIZEOF_STRUCT_MTD_CONCAT(num_devs); - concat =3D kzalloc(size, GFP_KERNEL); + concat =3D kzalloc_flex(*concat, subdev, num_devs, GFP_KERNEL); if (!concat) { printk ("memory allocation error while creating concatenated device \"%s\"\= n", name); return NULL; } - concat->subdev =3D (struct mtd_info **) (concat + 1); =20 /* * Set up the new "super" device's MTD object structure, check for diff --git a/include/linux/mtd/concat.h b/include/linux/mtd/concat.h index 2cd9d48958a8..f8d4d6ac1fc1 100644 --- a/include/linux/mtd/concat.h +++ b/include/linux/mtd/concat.h @@ -18,7 +18,7 @@ struct mtd_concat { struct mtd_info mtd; int num_subdev; - struct mtd_info **subdev; + struct mtd_info *subdev[]; }; =20 struct mtd_info *mtd_concat_create( --=20 2.53.0