nvmem: core: initialise nvmem->id early
commit3bd747c7eaupstream. 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:f7d8d7dcd9("nvmem: fix memory leak in error path") Cc: stable@vger.kernel.org Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> Link: https://lore.kernel.org/r/20230127104015.23839-4-srinivas.kandagatla@linaro.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
b591abac78
commit
bb875f0a34
1 changed files with 2 additions and 1 deletions
|
|
@ -625,6 +625,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
|
||||
|
|
@ -640,7 +642,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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue