Skip to contentSkip to conversation

nvmem: core: fix missing of_node_put() in of_nvmem_device_get()

PATCH In review Vadym Kochan 2 participants 2 messages Sep 15, 2020 – Sep 16, 2020 NVMEM framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: core: fix missing of_node_put() in of_nvmem_device_get()

of_parse_phandle() returns device_node with incremented ref count which needs to be decremented by of_node_put() when device_node is not used.

Fixes e2a5402ec7c6 ("nvmem: Add nvmem_device based consumer apis.")
---
 drivers/nvmem/core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/nvmem/core.c +4 -1
index 6cd3edb2eaf6..204a515d8bc5 100644
@@ -835,6 +835,7 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
 {
 
 	struct device_node *nvmem_np;
+	struct nvmem_device *nvmem;
 	int index = 0;
 
 	if (id)
@@ -844,7 +845,9 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
 	if (!nvmem_np)
 		return ERR_PTR(-ENOENT);
 
-	return __nvmem_device_get(nvmem_np, device_match_of_node);
+	nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
+	of_node_put(nvmem_np);
+	return nvmem;
 }
 EXPORT_SYMBOL_GPL(of_nvmem_device_get);
 #endif
Signature · 1 line
2.17.1
#1 lore raw
Quoted 9 lines · Vadym Kochan

of_parse_phandle() returns device_node with incremented ref count which needs to be decremented by of_node_put() when device_node is not used.

Fixes e2a5402ec7c6 ("nvmem: Add nvmem_device based consumer apis.")
---
  drivers/nvmem/core.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)

Applied thanks,

--srini

Quoted 25 lines
drivers/nvmem/core.c +4 -1
index 6cd3edb2eaf6..204a515d8bc5 100644
@@ -835,6 +835,7 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
  {
 
  	struct device_node *nvmem_np;
+	struct nvmem_device *nvmem;
  	int index = 0;
 
  	if (id)
@@ -844,7 +845,9 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
  	if (!nvmem_np)
  		return ERR_PTR(-ENOENT);
 
-	return __nvmem_device_get(nvmem_np, device_match_of_node);
+	nvmem = __nvmem_device_get(nvmem_np, device_match_of_node);
+	of_node_put(nvmem_np);
+	return nvmem;
  }
  EXPORT_SYMBOL_GPL(of_nvmem_device_get);
  #endif