Skip to content

Commit edcf2fb

Browse files
mwallegregkh
authored andcommitted
nvmem: core: fix device node refcounting
In of_nvmem_cell_get(), of_get_next_parent() is used on cell_np. This will decrement the refcount on cell_np, but cell_np is still used later in the code. Use of_get_parent() instead and of_node_put() in the appropriate places. Fixes: 69aba79 ("nvmem: Add a simple NVMEM framework for consumers") Fixes: 7ae6478 ("nvmem: core: rework nvmem cell instance creation") Cc: [email protected] Signed-off-by: Michael Walle <[email protected]> Signed-off-by: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ab3428c commit edcf2fb

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/nvmem/core.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,16 +1237,21 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
12371237
if (!cell_np)
12381238
return ERR_PTR(-ENOENT);
12391239

1240-
nvmem_np = of_get_next_parent(cell_np);
1241-
if (!nvmem_np)
1240+
nvmem_np = of_get_parent(cell_np);
1241+
if (!nvmem_np) {
1242+
of_node_put(cell_np);
12421243
return ERR_PTR(-EINVAL);
1244+
}
12431245

12441246
nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
12451247
of_node_put(nvmem_np);
1246-
if (IS_ERR(nvmem))
1248+
if (IS_ERR(nvmem)) {
1249+
of_node_put(cell_np);
12471250
return ERR_CAST(nvmem);
1251+
}
12481252

12491253
cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np);
1254+
of_node_put(cell_np);
12501255
if (!cell_entry) {
12511256
__nvmem_device_put(nvmem);
12521257
return ERR_PTR(-ENOENT);

0 commit comments

Comments
 (0)