812-v6.2-0013-nvmem-core-fix-device-node-refcounting.patch 1.6 KB

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