diff options
author | Bartosz Golaszewski <bgolaszewski@baylibre.com> | 2020-03-10 16:22:49 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-03-19 09:41:02 +0300 |
commit | f7d8d7dcd978382dd1dd36e240dcddbfa6697796 (patch) | |
tree | ce7d283ef9fc4fdb1ef2083acd50b4b2a84723ec /drivers/nvmem | |
parent | 31c6ff51fdce7c507e1015bf5cefda8505a13809 (diff) | |
download | linux-f7d8d7dcd978382dd1dd36e240dcddbfa6697796.tar.xz |
nvmem: fix memory leak in error path
We need to free the ida mapping and nvmem struct if the write-protect
GPIO lookup fails.
Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin")
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20200310132257.23358-7-srinivas.kandagatla@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/nvmem')
-rw-r--r-- | drivers/nvmem/core.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 503da67dde06..2758d90d63b7 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -353,8 +353,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) else nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp", GPIOD_OUT_HIGH); - if (IS_ERR(nvmem->wp_gpio)) - return ERR_CAST(nvmem->wp_gpio); + if (IS_ERR(nvmem->wp_gpio)) { + ida_simple_remove(&nvmem_ida, nvmem->id); + rval = PTR_ERR(nvmem->wp_gpio); + kfree(nvmem); + return ERR_PTR(rval); + } kref_init(&nvmem->refcnt); INIT_LIST_HEAD(&nvmem->cells); |