Skip to content

Commit

Permalink
nvmem: core: fix device node refcounting
Browse files Browse the repository at this point in the history
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: stable@vger.kernel.org
Signed-off-by: Michael Walle <michael@walle.cc>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230127104015.23839-8-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Michael Walle authored and Greg Kroah-Hartman committed Jan 28, 2023
1 parent ab3428c commit edcf2fb
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions drivers/nvmem/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,16 +1237,21 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id)
if (!cell_np)
return ERR_PTR(-ENOENT);

nvmem_np = of_get_next_parent(cell_np);
if (!nvmem_np)
nvmem_np = of_get_parent(cell_np);
if (!nvmem_np) {
of_node_put(cell_np);
return ERR_PTR(-EINVAL);
}

nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
of_node_put(nvmem_np);
if (IS_ERR(nvmem))
if (IS_ERR(nvmem)) {
of_node_put(cell_np);
return ERR_CAST(nvmem);
}

cell_entry = nvmem_find_cell_entry_by_node(nvmem, cell_np);
of_node_put(cell_np);
if (!cell_entry) {
__nvmem_device_put(nvmem);
return ERR_PTR(-ENOENT);
Expand Down

0 comments on commit edcf2fb

Please sign in to comment.