Skip to contentSkip to conversation

nvmem: core: Fix a resource leak on error in nvmem_add_cells_from_of()

PATCH Applied Dan Carpenter 2 participants 2 messages Dec 19, 2020 – Jan 5, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: core: Fix a resource leak on error in nvmem_add_cells_from_of()

This doesn't call of_node_put() on the error path so it leads to a memory leak.

Fixes 0749aa25af82 ("nvmem: core: fix regression in of_nvmem_cell_get()")

---
The kfree_const() could just be replaced with kfree(). Someone got over excited converting things from kfree() to kfree_const().

 drivers/nvmem/core.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvmem/core.c +1 -0
index 177f5bf27c6d..68ae6f24b57f 100644
@@ -713,6 +713,7 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
 				cell->name, nvmem->stride);
 			/* Cells already added will be freed later. */
 			kfree_const(cell->name);
+			of_node_put(cell->np);
 			kfree(cell);
 			return -EINVAL;
 		}
Signature · 1 line
2.29.2
#1 lore raw
Quoted 5 lines · Dan Carpenter

This doesn't call of_node_put() on the error path so it leads to a memory leak.

Fixes 0749aa25af82 ("nvmem: core: fix regression in of_nvmem_cell_get()")

Applied, thanks

--srini

Quoted 20 lines

---
The kfree_const() could just be replaced with kfree(). Someone got over excited converting things from kfree() to kfree_const().

  drivers/nvmem/core.c | 1 +
  1 file changed, 1 insertion(+)
drivers/nvmem/core.c +1 -0
index 177f5bf27c6d..68ae6f24b57f 100644
@@ -713,6 +713,7 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem)
  				cell->name, nvmem->stride);
  			/* Cells already added will be freed later. */
  			kfree_const(cell->name);
+			of_node_put(cell->np);
  			kfree(cell);
  			return -EINVAL;
  		}