mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nvmem: core: Fix memleak in nvmem_add_cells_from_dt error path
@ 2024-09-11 12:06 Ruihai Zhou
  2024-09-11 12:27 ` Greg KH
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ruihai Zhou @ 2024-09-11 12:06 UTC (permalink / raw)
  To: srinivas.kandagatla, gregkh, msp, zhou.ruihai; +Cc: linux-kernel

In the nvmem_add_cells_from_dt(), if the devicetree 'bits' property
is outside of the valid range, the info.name alloc by kasprintf will
cause memleak. Just free before return from nvmem_add_cells_from_dt
in the error path.

Fixes: def3173d4f17 ("nvmem: core: Print error on wrong bits DT property")
Signed-off-by: Ruihai Zhou <zhou.ruihai@qq.com>
---
 drivers/nvmem/core.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 516dfd861b9f..ce71bee5e1a9 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -826,6 +826,7 @@ static int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_nod
 			info.nbits = be32_to_cpup(addr);
 			if (info.bit_offset >= BITS_PER_BYTE || info.nbits < 1) {
 				dev_err(dev, "nvmem: invalid bits on %pOF\n", child);
+				kfree(info.name);
 				of_node_put(child);
 				return -EINVAL;
 			}
-- 
2.31.1


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

end of thread, other threads:[~2024-09-11 19:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-11 12:06 [PATCH] nvmem: core: Fix memleak in nvmem_add_cells_from_dt error path Ruihai Zhou
2024-09-11 12:27 ` Greg KH
2024-09-11 13:05 ` Markus Elfring
2024-09-11 13:09   ` Greg Kroah-Hartman
2024-09-11 19:46 ` Markus Schneider-Pargmann

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®