[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <E1pCkdG-004huq-0l@rmk-PC.armlinux.org.uk>
Date: Tue, 03 Jan 2023 16:59:22 +0000
From: "Russell King (Oracle)" <rmk+kernel@...linux.org.uk>
To: Srinivas Kandagatla <srinivas.kandagatla@...aro.org>
Cc: Bartosz Golaszewski <bgolaszewski@...libre.com>,
Gaosheng Cui <cuigaosheng1@...wei.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
Maxime Ripard <mripard@...nel.org>,
Hector Martin <marcan@...can.st>
Subject: [PATCH v3 2/5] nvmem: core: initialise nvmem->id early
Bartosz Golaszewski <bgolaszewski@...libre.com>,Gaosheng Cui <cuigaosheng1@...wei.com>,Greg Kroah-Hartman <gregkh@...uxfoundation.org>,linux-arm-kernel@...ts.infradead.org,linux-kernel@...r.kernel.org,Maxime Ripard <mripard@...nel.org>, Hector Martin <marcan@...can.st>
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")
Signed-off-by: Russell King (Oracle) <rmk+kernel@...linux.org.uk>
---
drivers/nvmem/core.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index bf11e0c36d60..c1a40d9c3825 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -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)
@@ -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;
--
2.30.2
Powered by blists - more mailing lists