diff options
author | Russell King (Oracle) <rmk+kernel@armlinux.org.uk> | 2023-01-27 13:40:08 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-02-15 19:22:20 +0300 |
commit | bb875f0a34e775500f74bfaedf72e049733d9211 (patch) | |
tree | 3b406fc894d95ea75e1b6a7d26cc8352ccc7af92 | |
parent | b591abac78e25269b12e3d7170c99463f8c5cb02 (diff) | |
download | linux-bb875f0a34e775500f74bfaedf72e049733d9211.tar.xz |
nvmem: core: initialise nvmem->id early
commit 3bd747c7ea13cb145f0d84444e00df928b0842d9 upstream.
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: f7d8d7dcd978 ("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>
-rw-r--r-- | drivers/nvmem/core.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 21d89d80d083..4126c7002fc8 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -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; |