Skip to content

Commit

Permalink
nvmem: core: initialise nvmem->id early
Browse files Browse the repository at this point in the history
The error path for wp_gpio attempts to free the IDA nvmem->id, but
this has yet to be assigned, so will always be zero - leaking the
ID allocated by ida_alloc(). Fix this by moving the initialisation
of nvmem->id earlier.

Fixes: f7d8d7d ("nvmem: fix memory leak in error path")
Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
  • Loading branch information
Russell King (Oracle) authored and Srinivas Kandagatla committed Jan 3, 2023
1 parent 8dc69d2 commit 6d6afa7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/nvmem/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
return ERR_PTR(rval);
}

nvmem->id = rval;

if (config->wp_gpio)
nvmem->wp_gpio = config->wp_gpio;
else if (!config->ignore_wp)
Expand All @@ -785,7 +787,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
kref_init(&nvmem->refcnt);
INIT_LIST_HEAD(&nvmem->cells);

nvmem->id = rval;
nvmem->owner = config->owner;
if (!nvmem->owner && config->dev->driver)
nvmem->owner = config->dev->driver->owner;
Expand Down

0 comments on commit 6d6afa7

Please sign in to comment.