mirror of
https://github.com/torvalds/linux.git
synced 2024-11-23 12:42:02 +00:00
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: 2a127da461
("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>
This commit is contained in:
parent
31c6ff51fd
commit
f7d8d7dcd9
@ -353,8 +353,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
|
|||||||
else
|
else
|
||||||
nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
|
nvmem->wp_gpio = gpiod_get_optional(config->dev, "wp",
|
||||||
GPIOD_OUT_HIGH);
|
GPIOD_OUT_HIGH);
|
||||||
if (IS_ERR(nvmem->wp_gpio))
|
if (IS_ERR(nvmem->wp_gpio)) {
|
||||||
return ERR_CAST(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);
|
kref_init(&nvmem->refcnt);
|
||||||
INIT_LIST_HEAD(&nvmem->cells);
|
INIT_LIST_HEAD(&nvmem->cells);
|
||||||
|
Loading…
Reference in New Issue
Block a user