mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mtd: ubi: nvmem: Fix device_node leak in ubi_nvmem_add()
@ 2026-10-27  9:15 Vishal Satle
  2026-10-27  9:18 ` Daniel Golle
  2026-10-27 11:18 ` Zhihao Cheng
  0 siblings, 2 replies; 3+ messages in thread
From: Vishal Satle @ 2026-10-27  9:15 UTC (permalink / raw)
  To: Richard Weinberger, Daniel Golle, Miquel Raynal, Vignesh Raghavendra
  Cc: Zhihao Cheng, linux-mtd, linux-kernel, stable, Vishal Satle

ubi_nvmem_add() calls of_get_child_by_name() to verify that the UBI
volume device node contains an "nvmem-layout" subnode.
of_get_child_by_name() returns a pointer to the child device_node
with its reference count incremented.

Because the returned pointer was only evaluated as a boolean condition
and not retained or put, the reference count of the "nvmem-layout" node
was leaked whenever an NVMEM-enabled UBI volume was registered.

Assign the child node to a local variable and release it with
of_node_put() once existence has been validated.

Fixes: 34a5d8525b6a ("mtd: ubi: add NVMEM support")
Cc: stable@vger.kernel.org
Signed-off-by: Vishal Satle <vishalsatleit24@gmail.com>
---
 drivers/mtd/ubi/nvmem.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/ubi/nvmem.c b/drivers/mtd/ubi/nvmem.c
index 2dade9727..15737d511 100644
--- a/drivers/mtd/ubi/nvmem.c
+++ b/drivers/mtd/ubi/nvmem.c
@@ -61,6 +61,7 @@ static int ubi_nvmem_reg_read(void *priv, unsigned int from,
 static int ubi_nvmem_add(struct ubi_volume_info *vi)
 {
 	struct device_node *np = dev_of_node(vi->dev);
+	struct device_node *layout;
 	struct nvmem_config config = {};
 	struct ubi_nvmem *unv;
 	int ret;
@@ -68,9 +69,12 @@ static int ubi_nvmem_add(struct ubi_volume_info *vi)
 	if (!np)
 		return 0;
 
-	if (!of_get_child_by_name(np, "nvmem-layout"))
+	layout = of_get_child_by_name(np, "nvmem-layout");
+	if (!layout)
 		return 0;
 
+	of_node_put(layout);
+
 	if (WARN_ON_ONCE(vi->usable_leb_size <= 0) ||
 	    WARN_ON_ONCE(vi->size <= 0))
 		return -EINVAL;
-- 
2.51.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-10-27 11:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-27  9:15 [PATCH] mtd: ubi: nvmem: Fix device_node leak in ubi_nvmem_add() Vishal Satle
2026-10-27  9:18 ` Daniel Golle
2026-10-27 11:18 ` Zhihao Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®