From nobody Fri Apr 10 01:06:05 2026 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 8015737B3E9 for ; Wed, 4 Mar 2026 22:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772662553; cv=none; b=JbRby1KnIubJBSnD8DUh5pg+CzEB4aK/xloN9MACSee/qPxP/r0VXzt0/maaor6DrOXh6C8uA7/Mhq7s5KPSzVMB8EcGuCJ5uzm9x6nX7G4aL/OZBb4i6AfYGCoNItb7x/E9wFO8xS0mxa1lgRJlGKesO7e5928l/n2IAjb9DiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772662553; c=relaxed/simple; bh=lo4wY5ljrci9jyi+y6+SkBX2n4ucfM5inr+hJJjPnL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BT7nbXGgeQWSCxfxt5wQpGrKq2fi7swmaikP02gtKswyPAiPjGcS996jBeK11K8nDbOl88PKzkPZ4LKy0rxlwwnzweBJYbHPa9IqYNU1Ut+N/SGwi+vYf5H03uAVj1FlwyH6eO+IbgQBMjYlrTgT3vaUG2bDxLvfolncFj76OkI= 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=G0xBW/Co; arc=none smtp.client-ip=209.85.210.179 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="G0xBW/Co" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-823c56765fdso3828971b3a.1 for ; Wed, 04 Mar 2026 14:15:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772662550; x=1773267350; 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=8CfzrWus7cpldnCjcicm+ZA4TLtGttdNpR4LRwnpAfg=; b=G0xBW/Cog140sp4AOIAlduHWjHqaOSr4bH4/z2n7DuTKWofbmA5EA0dtxcFOOaOX9a 7aksIcvkQsGe10Bl4U/nJp99/deMzTkxDHsgK5CcBMQ3R/j4mnrJi/s/iEwUWpfy5GHs gTkPBOTD0gmGStB0nV5svOmiuraXCPG/7l+RWAt7HfGCu3gkbQ8xsFIDt00Ty9NjB9YR 2UCdMNHd6kRwiCfAM5WwkBmqde0s4V6CxojFw/nCkJGiolmWxr9jnrv4Khe2bXcyGgrS jcI7OU1r7/K0ShpU2LtHFG0iQ+tc7Ngp/+3SUFMh3W3XqbdqPb8RRrll86vexnSiNj7P nbxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772662550; x=1773267350; 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=8CfzrWus7cpldnCjcicm+ZA4TLtGttdNpR4LRwnpAfg=; b=pLLOnsqqFwGrp4X0wi8vfdnGDCuBv8Xd6XtWKPZ3PbMFcLhoAzM962ebuvQhWlnFtd N3fM7zAtVka3xLpLn0j8048C9JfbMeN+ktNlKss8orJweQK2sM0+pbR/vN500KCRoe3H 3lbd7L3anO0MQfNSFAjcHjT6pPvJRRESo16/KI347cOGvFJfwFNhiHNHlyVbWmnp8lQ6 nwp4L4hTdTUXVh7sOWiTwmFDUqoOcMU0NMeHnYJ1BO7LCnGbXRVgPLr9IHXeEPqejfZb yZxKJ2M+V5HGM06/s5ft97zbe6CLx03cdjzCBpYdOadSHq6YbwDeOzMFuM+q4q4Qe8oA bsmg== X-Forwarded-Encrypted: i=1; AJvYcCVS2Vf40Jl0gRv9U5Psg3t+qDNWkr5Q7ljKzxI5rEp3VrXTa/rnRRt8DCyXzhJfdN4gr8oqpWYjkqgd9AY=@vger.kernel.org X-Gm-Message-State: AOJu0Ywsdn0amB+sJm8tgjU8rC2lBocoW6I+8hEudtD0618NNs7n2hUk P90FI1wHcRbjBpcbo0ucJ9Q9inrk3xPMoDkBDngdRNUlRUJM0IV0vEE9 X-Gm-Gg: ATEYQzy5zka6M1yxFiPvuis6XOD3uYnTtu0MdmuUzjjWdyNZeT+7HhRD2qluQLzh7oF DkVhklFQp0ZyUdI4gz/vs0ZYhKNAMl+tFmxj9vEytTdJyjpo0YTFkjddUVgfZTHVCCArxraSy8Z PIQJ+iy8LdSmG4VRj6HdRqB/O+cCfZJBbUw82dceCNlRMWB8lwXncq5DM7Ymx4FOA6ocXwMPGEk ChC2Xkg0HMvZngjp7u6lYiy5puGt2STVOCAzlpctqhsZFD6l4BV7vAo3UGeTK3AyzI+UtYbTjTz UKmeNYO/g3Foe6Y7FDlrrWZUwGHeIYFDHocBrXW7xLvdLk+GWbHSHh1d9XzVJVttaVIBb25nTgE AViThxwLvedtKlOx2jjfx9TpxBL+FFaPoS293pD8RwO0pDqTNBoova5b88GAdAqat+6mKzEpnDM GHBFt6zT93U3p3+P5nAvkCyk4X0DOjd+GW2EEL44kLc85Y0HbHNSmxbg== X-Received: by 2002:a05:6a20:3282:b0:38d:f6d7:963d with SMTP id adf61e73a8af0-3982e268f33mr3006564637.57.1772662549713; Wed, 04 Mar 2026 14:15:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Mar 2026 14:15:49 -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 1/2] mtd: virt_concat: use single allocation for node Date: Wed, 4 Mar 2026 14:15:29 -0800 Message-ID: <20260304221530.15018-2-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" Simpler to reason about and avoids having to free nodes separately. Also add __counted_by attribute for extra runtime analysis. Signed-off-by: Rosen Penev --- drivers/mtd/mtd_virt_concat.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/mtd_virt_concat.c b/drivers/mtd/mtd_virt_concat.c index aea88d1c9bc5..89e223edac6a 100644 --- a/drivers/mtd/mtd_virt_concat.c +++ b/drivers/mtd/mtd_virt_concat.c @@ -31,8 +31,8 @@ static LIST_HEAD(concat_node_list); struct mtd_virt_concat_node { struct list_head head; unsigned int count; - struct device_node **nodes; struct mtd_concat *concat; + struct device_node *nodes[] __counted_by(nodes); }; =20 /** @@ -133,7 +133,6 @@ int mtd_virt_concat_destroy(struct mtd_info *mtd) for (idx =3D 0; idx < item->count; idx++) of_node_put(item->nodes[idx]); =20 - kfree(item->nodes); kfree(item); } return 0; @@ -167,16 +166,11 @@ static int mtd_virt_concat_create_item(struct device_= node *parts, return 0; } =20 - item =3D kzalloc(sizeof(*item), GFP_KERNEL); + item =3D kzalloc_flex(*item, nodes, count, GFP_KERNEL); if (!item) return -ENOMEM; =20 item->count =3D count; - item->nodes =3D kcalloc(count, sizeof(*item->nodes), GFP_KERNEL); - if (!item->nodes) { - kfree(item); - return -ENOMEM; - } =20 /* * The partition in which "part-concat-next" property @@ -216,7 +210,6 @@ void mtd_virt_concat_destroy_items(void) for (i =3D 0; i < item->count; i++) of_node_put(item->nodes[i]); =20 - kfree(item->nodes); kfree(item); } } --=20 2.53.0