Skip to contentSkip to conversation

nvmem: core: add missing of_node_put after calling of_parse_phandle

PATCH New Peter Chen 1 participant 1 message Aug 12, 2016 NVMEM framework

lore
Share & tools
lore

Peter Chen

author
#0 lore raw

PATCH 1/1 nvmem: core: add missing of_node_put after calling of_parse_phandle

of_node_put needs to be called when the device node which is got from of_parse_phandle has finished using.

Cc Srinivas Kandagatla <[email protected]>
Cc Maxime Ripard <[email protected]>
---
 drivers/nvmem/core.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/nvmem/core.c +12 -3
index 965911d..ea51472 100644
@@ -619,6 +619,7 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
 
 	struct device_node *nvmem_np;
 	int index;
+	struct nvmem_device *nvmem;
 
 	index = of_property_match_string(np, "nvmem-names", id);
 
@@ -626,7 +627,9 @@ struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *id)
 	if (!nvmem_np)
 		return ERR_PTR(-EINVAL);
 
-	return __nvmem_device_get(nvmem_np, NULL, NULL);
+	nvmem = __nvmem_device_get(nvmem_np, NULL, NULL);
+	of_node_put(nvmem_np);
+	return nvmem;
 }
 EXPORT_SYMBOL_GPL(of_nvmem_device_get);
 #endif
@@ -768,12 +771,16 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
 		return ERR_PTR(-EINVAL);
 
 	nvmem_np = of_get_next_parent(cell_np);
-	if (!nvmem_np)
+	if (!nvmem_np) {
+		of_node_put(cell_np);
 		return ERR_PTR(-EINVAL);
+	}
 
 	nvmem = __nvmem_device_get(nvmem_np, NULL, NULL);
-	if (IS_ERR(nvmem))
+	if (IS_ERR(nvmem)) {
+		of_node_put(cell_np);
 		return ERR_CAST(nvmem);
+	}
 
 	addr = of_get_property(cell_np, "reg", &len);
 	if (!addr || (len < 2 * sizeof(u32))) {
@@ -813,6 +820,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np,
 	}
 
 	nvmem_cell_add(cell);
+	of_node_put(cell_np);
 
 	return cell;
 
@@ -821,6 +829,7 @@ err_sanity:
 
 err_mem:
 	__nvmem_device_put(nvmem);
+	of_node_put(cell_np);
 
 	return ERR_PTR(rval);
 }
Signature · 1 line
1.9.1