nvmem: core: Fix device reference leak

__nvmem_device_get() make use of bus_find_device() to get the relevant
device and this function increase the reference count of the device
found, however this is not accounted for anywhere. Fix
__nvmem_device_get() and __nvmem_device_put() to properly release this
reference count.

Signed-off-by: Alban Bedel <albeu@free.fr>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Alban Bedel 2019-01-28 15:55:05 +00:00 committed by Greg Kroah-Hartman
parent 95b65195d5
commit 73e9dc4d56

View File

@ -811,6 +811,7 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
"could not increase module refcount for cell %s\n", "could not increase module refcount for cell %s\n",
nvmem_dev_name(nvmem)); nvmem_dev_name(nvmem));
put_device(&nvmem->dev);
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
@ -821,6 +822,7 @@ static struct nvmem_device *__nvmem_device_get(struct device_node *np,
static void __nvmem_device_put(struct nvmem_device *nvmem) static void __nvmem_device_put(struct nvmem_device *nvmem)
{ {
put_device(&nvmem->dev);
module_put(nvmem->owner); module_put(nvmem->owner);
kref_put(&nvmem->refcnt, nvmem_device_release); kref_put(&nvmem->refcnt, nvmem_device_release);
} }