Skip to contentSkip to conversation

nvmem: layouts: sl28vpd: Fix np reference leak in sl28vpd_add_cells()

PATCH In review Wentao Liang 2 participants 2 messages Sep 17

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

PATCH 1/1 nvmem: layouts: sl28vpd: Fix np reference leak in sl28vpd_add_cells()

of_get_child_by_name() returns a node with an elevated reference count. nvmem_add_one_cell() only takes ownership of that reference on success, so the caller must drop it when the call fails. Add the missing of_node_put() before returning so that info.np is not leaked.

Fixes d9fae023fe86 ("nvmem: layouts: sl28vpd: Add new layout driver")
---
 drivers/nvmem/layouts/sl28vpd.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvmem/layouts/sl28vpd.c +1 -0
index e93b020b0836..79de1e6947d0 100644
@@ -126,6 +126,7 @@ static int sl28vpd_add_cells(struct nvmem_layout *layout)
 
 		ret = nvmem_add_one_cell(nvmem, &info);
 		if (ret) {
+			of_node_put(info.np);
 			of_node_put(layout_np);
 			return ret;
 		}
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 8 lines · Wentao Liang

of_get_child_by_name() returns a node with an elevated reference count. nvmem_add_one_cell() only takes ownership of that reference on success, so the caller must drop it when the call fails. Add the missing of_node_put() before returning so that info.np is not leaked.

Fixes d9fae023fe86 ("nvmem: layouts: sl28vpd: Add new layout driver")

There was already a patch fixing this:

https://lore.kernel.org/r/[email protected]/

-michael