[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <tencent_C3AF1A5AA6C84EC8AFBC9434383912612209@qq.com>
Date: Wed, 11 Sep 2024 20:06:55 +0800
From: Ruihai Zhou <zhou.ruihai@...com>
To: srinivas.kandagatla@...aro.org,
gregkh@...uxfoundation.org,
msp@...libre.com,
zhou.ruihai@...com
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH] nvmem: core: Fix memleak in nvmem_add_cells_from_dt error path
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@...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
Powered by blists - more mailing lists