From: Vishal Satle <vishalsatleit24@gmail.com>
To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com
Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org, Vishal Satle <vishalsatleit24@gmail.com>
Subject: [PATCH] mtd: virt_concat: Fix device_node reference leaks in mtd_virt_concat_create_item()
Date: Tue, 27 Oct 2026 16:13:45 +0530 [thread overview]
Message-ID: <20261027104345.172612-1-vishalsatleit24@gmail.com> (raw)
In mtd_virt_concat_create_item(), several device_node reference count leaks
and lifecycle bugs exist:
1. of_parse_phandle() returns a device_node with its refcount incremented.
The validation loop calls mtd_is_part_concat() directly on the returned
pointer without releasing it, leaking the node reference on every
iteration and on early return.
2. item->nodes[0] is assigned directly from parts without acquiring a
reference via of_node_get(). However, mtd_virt_concat_destroy_items()
and mtd_virt_concat_destroy() call of_node_put() on all item->nodes,
and mtd_virt_concat_node_create() drops its own reference on parts in
the next iteration of of_find_node_with_property(), leading to an
underflow / premature release of parts.
3. If kzalloc_flex() fails for concat, the error path frees item without
releasing the acquired references in item->nodes[0..count-1].
Fix these issues by releasing next after mtd_is_part_concat() in the
validation loop, taking a reference with of_node_get() when assigning
item->nodes[0], and releasing all acquired node references if concat
allocation fails.
Signed-off-by: Vishal Satle <vishalsatleit24@gmail.com>
---
drivers/mtd/mtd_virt_concat.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/mtd/mtd_virt_concat.c b/drivers/mtd/mtd_virt_concat.c
index 40b300021..6abc88251 100644
--- a/drivers/mtd/mtd_virt_concat.c
+++ b/drivers/mtd/mtd_virt_concat.c
@@ -163,7 +163,11 @@ static int mtd_virt_concat_create_item(struct device_node *parts,
int i;
for (i = 0; i < (count - 1); i++) {
- if (mtd_is_part_concat(of_parse_phandle(parts, CONCAT_PROP, i)))
+ struct device_node *next = of_parse_phandle(parts, CONCAT_PROP, i);
+ bool is_concat = mtd_is_part_concat(next);
+
+ of_node_put(next);
+ if (is_concat)
return 0;
}
@@ -178,13 +182,15 @@ static int mtd_virt_concat_create_item(struct device_node *parts,
* is defined is the first device in the list of concat
* devices.
*/
- item->nodes[0] = parts;
+ item->nodes[0] = of_node_get(parts);
for (i = 1; i < count; i++)
item->nodes[i] = of_parse_phandle(parts, CONCAT_PROP, (i - 1));
concat = kzalloc_flex(*concat, subdev, count);
if (!concat) {
+ for (i = 0; i < count; i++)
+ of_node_put(item->nodes[i]);
kfree(item);
return -ENOMEM;
}
--
2.53.0
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
reply other threads:[~2026-10-27 10:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261027104345.172612-1-vishalsatleit24@gmail.com \
--to=vishalsatleit24@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=stable@vger.kernel.org \
--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