]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
nvmem: core: fix missing of_node_put() in of_nvmem_device_get()
authorVadym Kochan <vadym.kochan@plvision.eu>
Thu, 17 Sep 2020 13:44:37 +0000 (14:44 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 Oct 2020 09:11:23 +0000 (10:11 +0100)
[ Upstream commit b1c194dcdb1425fa59eec61ab927cfff33096149 ]

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.")
Signed-off-by: Vadym Kochan <vadym.kochan@plvision.eu>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20200917134437.16637-5-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/nvmem/core.c

index 6cd3edb2eaf65feebcadf4f4cfce40a22e355eaf..204a515d8bc5dbb3564847f4392b7031ce75782f 100644 (file)
@@ -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