From nobody Mon Apr 6 07:36:34 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (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 EB8A93644C4 for ; Thu, 5 Mar 2026 22:44:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772750673; cv=none; b=OGvnL0MNNxr/M3nhF40AMipXi1uBWXOqFtAk6vGi9c9vuM7k/fl2iweytxGaXN//L73y+A/7AvYpmAapIrUmNg5O/bJUl4GUCfxBmN9ou2eP6d3FPdnefg6oHDZ8HPKZcowpNYX68t0Ae1rV/H81qiD1GxV6B7MwjwB3uCLGoxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772750673; c=relaxed/simple; bh=V8OViAIFO175+fJwVfJPKOAp+3BYH7KDrPqR+lYwjBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Bu9/IQ478ndRixOmsBLvQeILWT7QXAdWtp0IPhqwVh8rvsd85UtBXa7vkX7Ftxu/I/aDF8OiIt3FupwoeWaU4P8OclPn1Th1VLXes8zV9dvOizoQVGcQ5lgZ+3Q/XCSWMcWKdOA71EIAD0d7eriDqKgEL/05+cSi/KScNFtzs70= 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=XlQyfeFF; arc=none smtp.client-ip=209.85.210.182 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="XlQyfeFF" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-824ac5d28f9so8721969b3a.0 for ; Thu, 05 Mar 2026 14:44:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772750671; x=1773355471; 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=nOmbFn8ywU95rp5pZjzICmiW6tw+/7i3nDvDUHUWrQE=; b=XlQyfeFFyHR14UEl0UZvCtuGiaj6jQ7Rcal1+1j50h+Pp3qlQBEEV7JNCrYJAeJOr8 8PRIbuWvebeXkW/aCJVKk7UBFJ8SropWlcc/aa7JweFAP2kp3/wGo3Hsp8cwBsWp3c3O JTcdYaXiR5Tn5qSv+5Jti6epVYnmsBLu1+D7taoQANu4EAVGWUCPCimQMCDguv6xHz3i hzAqAc1Pt5z19CdyqRzycz16s3b0ih6wyXgbhTCMedf7uoAhXeqHUkgl2KVFL5MQ8Au5 YwV1mVOP66iFV/b56OD7Ua8h039FedCZ4V4oIfVfCsNnnhoLW1pOJ5FhkjpHvXheNT31 uxJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772750671; x=1773355471; 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=nOmbFn8ywU95rp5pZjzICmiW6tw+/7i3nDvDUHUWrQE=; b=e9Yvg7DPCIEsQHRXlhmCzBwIQFmH+33FMTk03qBUyeO1mxs9eOx9CklSEAMpFFVgbT t1AgoXq8cv1bpMYAIwWqOTmCtzEqhA6l7OPt2XCfBelwdwMgtPAhAj8I2TYyBlxHqcUN AtMfSeA2IaXCG8HNH9ZNkkCpm/i54eosCrVUsb8wZ+hKfR31KARSSI1fu0gDX7cVMgcv 2GgKWWemnxJ3sj6tSRb+DdxsEij3u5ZsC0qLeNvnldRYuzPQQ6shulR7F1Yu+PixHjyk hUSHWtSml0mf9JssLvW8z7nAIOYx0E1NxXfXnd1ymaQr2ZpTLWlNVzPA+vL5+uIJIHY5 5qIw== X-Forwarded-Encrypted: i=1; AJvYcCXReHKZHs7oUtuyALAGjV6FJ56++MXVRvFwM0Ydm9PdCHYKeSIpHS0hDng0GJIDeSYDox2ln8/HoEka0U8=@vger.kernel.org X-Gm-Message-State: AOJu0YyvWwl5uYK5pJFxNlEP47P46IfORrFQA3c2AU/VGWQA4a/3c52g 57QzvRB37IytpVDkAF5tg78zKy1AJk8iB2hL62eoGjgAzL5c2otuCJnU X-Gm-Gg: ATEYQzzB61ddfF7whgV1eYzkpOr3/KJYqYVIJjGojlTFbuFV1WkpH7zyywmJaWIpbFE QRj/kSCC8X4Uy+SOV92UgAeK05hCxUZUzhAZg3atWPiClBIyjpRWSj89NDzSpYvR97vDLimmNLA mQX2PXa9gyfWOyonih6+pL1KZcGNTks/syFKl+SCrInMDXBzDQ1+G7yNVPqqxmiD/E6jzeQTdXy CUP/+cGrPwu9oFBZr/mIDoBCIxPGSkm5JB4XMLujqZl+bsXTYUOgS8RLBuOI1ZoG2iLE9Qh2MLG GKh0Nh4Ro5lJhy317gofovxK9IcauBBx0OPxV0o6Kz8VlWklNhQzeD4W6akyfDqKfh19/tXwWvX d2Xn/xAFihpyvhCkGTwJmm5Z8bX5L4x0iI12Ynrk007QGQKgc1XTLw2UObjdNOfbRzOxy/nMr2U ZaSEn1bkG4iaLd9PITUxx/zhVb638SjNoXfpANL+FnvZy5Ls9XlzqCiQ== X-Received: by 2002:a05:6a21:6b12:b0:394:65bb:d1b9 with SMTP id adf61e73a8af0-39858fdbd15mr159399637.20.1772750671359; Thu, 05 Mar 2026 14:44:31 -0800 (PST) Received: from ryzen ([2601:644:8000:56f5::8bd]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c738877202fsm3565477a12.25.2026.03.05.14.44.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Mar 2026 14:44:30 -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: [PATCHv2 2/2] mtd: concat: replace alloc + calloc with 1 alloc Date: Thu, 5 Mar 2026 14:44:10 -0800 Message-ID: <20260305224410.14251-3-rosenp@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260305224410.14251-1-rosenp@gmail.com> References: <20260305224410.14251-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 | 8 +------- drivers/mtd/mtdconcat.c | 5 +---- include/linux/mtd/concat.h | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/mtd/mtd_virt_concat.c b/drivers/mtd/mtd_virt_concat.c index 33f9a63dd450..b56f2431974b 100644 --- a/drivers/mtd/mtd_virt_concat.c +++ b/drivers/mtd/mtd_virt_concat.c @@ -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