提交 3bd747c7 编写于 作者: R Russell King (Oracle) 提交者: Greg Kroah-Hartman

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: f7d8d7dc ("nvmem: fix memory leak in error path")
Cc: stable@vger.kernel.org
Signed-off-by: NRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Signed-off-by: NSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Link: https://lore.kernel.org/r/20230127104015.23839-4-srinivas.kandagatla@linaro.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 c151d5ed
...@@ -770,6 +770,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) ...@@ -770,6 +770,8 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
return ERR_PTR(rval); return ERR_PTR(rval);
} }
nvmem->id = rval;
if (config->wp_gpio) if (config->wp_gpio)
nvmem->wp_gpio = config->wp_gpio; nvmem->wp_gpio = config->wp_gpio;
else if (!config->ignore_wp) else if (!config->ignore_wp)
...@@ -785,7 +787,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) ...@@ -785,7 +787,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
kref_init(&nvmem->refcnt); kref_init(&nvmem->refcnt);
INIT_LIST_HEAD(&nvmem->cells); INIT_LIST_HEAD(&nvmem->cells);
nvmem->id = rval;
nvmem->owner = config->owner; nvmem->owner = config->owner;
if (!nvmem->owner && config->dev->driver) if (!nvmem->owner && config->dev->driver)
nvmem->owner = config->dev->driver->owner; nvmem->owner = config->dev->driver->owner;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册