Skip to content

Commit

Permalink
nvmem: fix memory leak in error path
Browse files Browse the repository at this point in the history
We need to free the ida mapping and nvmem struct if the write-protect
GPIO lookup fails.

Fixes: 2a127da ("nvmem: add support for the write-protect pin")
Signed-off-by: Bartosz Golaszewski <[email protected]>
Signed-off-by: Srinivas Kandagatla <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
brgl authored and gregkh committed Mar 19, 2020
1 parent 31c6ff5 commit f7d8d7d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/nvmem/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f7d8d7d

Please sign in to comment.