From: Rosen Penev <rosenp@gmail.com>
To: linux-mtd@lists.infradead.org
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
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 1/2] mtd: virt_concat: use single allocation for node
Date: Thu, 5 Mar 2026 14:44:09 -0800 [thread overview]
Message-ID: <20260305224410.14251-2-rosenp@gmail.com> (raw)
In-Reply-To: <20260305224410.14251-1-rosenp@gmail.com>
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 <rosenp@gmail.com>
---
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..33f9a63dd450 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(count);
};
/**
@@ -133,7 +133,6 @@ int mtd_virt_concat_destroy(struct mtd_info *mtd)
for (idx = 0; idx < item->count; idx++)
of_node_put(item->nodes[idx]);
- kfree(item->nodes);
kfree(item);
}
return 0;
@@ -167,16 +166,11 @@ static int mtd_virt_concat_create_item(struct device_node *parts,
return 0;
}
- item = kzalloc(sizeof(*item), GFP_KERNEL);
+ item = kzalloc_flex(*item, nodes, count, GFP_KERNEL);
if (!item)
return -ENOMEM;
item->count = count;
- item->nodes = kcalloc(count, sizeof(*item->nodes), GFP_KERNEL);
- if (!item->nodes) {
- kfree(item);
- return -ENOMEM;
- }
/*
* The partition in which "part-concat-next" property
@@ -216,7 +210,6 @@ void mtd_virt_concat_destroy_items(void)
for (i = 0; i < item->count; i++)
of_node_put(item->nodes[i]);
- kfree(item->nodes);
kfree(item);
}
}
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-03-05 22:44 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 22:44 [PATCHv2 0/2] mtd: concat: use flex array Rosen Penev
2026-03-05 22:44 ` Rosen Penev [this message]
2026-03-05 22:44 ` [PATCHv2 2/2] mtd: concat: replace alloc + calloc with 1 alloc Rosen Penev
2026-03-11 15:25 ` [PATCHv2 0/2] mtd: concat: use flex array Miquel Raynal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260305224410.14251-2-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=gustavoars@kernel.org \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox