1 From edcf2fb660526b5ed29f93bd17328a2b4835c8b2 Mon Sep 17 00:00:00 2001
2 From: Michael Walle <michael@walle.cc>
3 Date: Fri, 27 Jan 2023 10:40:12 +0000
4 Subject: [PATCH] nvmem: core: fix device node refcounting
6 In of_nvmem_cell_get(), of_get_next_parent() is used on cell_np. This
7 will decrement the refcount on cell_np, but cell_np is still used later
8 in the code. Use of_get_parent() instead and of_node_put() in the
11 Fixes: 69aba7948cbe ("nvmem: Add a simple NVMEM framework for consumers")
12 Fixes: 7ae6478b304b ("nvmem: core: rework nvmem cell instance creation")
13 Cc: stable@vger.kernel.org
14 Signed-off-by: Michael Walle <michael@walle.cc>
15 Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
16 Link: https://lore.kernel.org/r/20230127104015.23839-8-srinivas.kandagatla@linaro.org
17 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
19 drivers/nvmem/core.c | 11 ++++++++---
20 1 file changed, 8 insertions(+), 3 deletions(-)
22 --- a/drivers/nvmem/core.c
23 +++ b/drivers/nvmem/core.c
24 @@ -1240,16 +1240,21 @@ struct nvmem_cell *of_nvmem_cell_get(str
26 return ERR_PTR(-ENOENT);
28 - nvmem_np = of_get_next_parent(cell_np);
30 + nvmem_np = of_get_parent(cell_np);
32 + of_node_put(cell_np);
33 return ERR_PTR(-EINVAL);
36 nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
37 of_node_put(nvmem_np);
39 + if (IS_ERR(nvmem)) {
40 + of_node_put(cell_np);
41 return ERR_CAST(nvmem);
44 cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np);
45 + of_node_put(cell_np);
47 __nvmem_device_put(nvmem);
48 return ERR_PTR(-ENOENT);