Skip to content

Commit 3bd747c

Browse files
Russell King (Oracle)gregkh
authored andcommitted
nvmem: core: initialise nvmem->id early
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") Cc: [email protected] Signed-off-by: Russell King (Oracle) <[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]>
1 parent c151d5e commit 3bd747c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/nvmem/core.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
770770
return ERR_PTR(rval);
771771
}
772772

773+
nvmem->id = rval;
774+
773775
if (config->wp_gpio)
774776
nvmem->wp_gpio = config->wp_gpio;
775777
else if (!config->ignore_wp)
@@ -785,7 +787,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
785787
kref_init(&nvmem->refcnt);
786788
INIT_LIST_HEAD(&nvmem->cells);
787789

788-
nvmem->id = rval;
789790
nvmem->owner = config->owner;
790791
if (!nvmem->owner && config->dev->driver)
791792
nvmem->owner = config->dev->driver->owner;

0 commit comments

Comments
 (0)