Skip to contentSkip to conversation

nvmem: core: fix GPIO descriptor resource leak

PATCH In review Haotian Zhang 2 participants 2 messages Oct 28, 2025 – Nov 10, 2025 NVMEM framework

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmem: core: fix GPIO descriptor resource leak

The driver calls gpiod_get_optional() in nvmem_register() but never calls gpiod_put() in nvmem_device_release() or in the register error path. This leads to a GPIO descriptor resource leak.

Add gpiod_put() in nvmem_device_release() and in the register error path to fix the resource leak.

Fixes 2a127da461a9 ("nvmem: add support for the write-protect pin")
---
 drivers/nvmem/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nvmem/core.c +2 -0
index 387c88c55259..597598db88f4 100644
@@ -1043,6 +1043,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (config->compat)
 		nvmem_sysfs_remove_compat(nvmem, config);
 err_put_device:
+	gpiod_put(nvmem->wp_gpio);
 	put_device(&nvmem->dev);
 
 	return ERR_PTR(rval);
@@ -1062,6 +1063,7 @@ static void nvmem_device_release(struct kref *kref)
 
 	nvmem_device_remove_all_cells(nvmem);
 	nvmem_destroy_layout(nvmem);
+	gpiod_put(nvmem->wp_gpio);
 	device_unregister(&nvmem->dev);
 }
 
Signature · 1 line
2.50.1.windows.1
#1 lore raw
Quoted 8 lines · Haotian Zhang

The driver calls gpiod_get_optional() in nvmem_register() but never calls gpiod_put() in nvmem_device_release() or in the register error path. This leads to a GPIO descriptor resource leak.

Add gpiod_put() in nvmem_device_release() and in the register error path to fix the resource leak.

Fixes 2a127da461a9 ("nvmem: add support for the write-protect pin")

Missing cc stable

--srini> Signed-off-by: Haotian Zhang <[email protected]>

Quoted 24 lines
---
 drivers/nvmem/core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/nvmem/core.c +2 -0
index 387c88c55259..597598db88f4 100644
@@ -1043,6 +1043,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 	if (config->compat)
 		nvmem_sysfs_remove_compat(nvmem, config);
 err_put_device:
+	gpiod_put(nvmem->wp_gpio);
 	put_device(&nvmem->dev);
 
 	return ERR_PTR(rval);
@@ -1062,6 +1063,7 @@ static void nvmem_device_release(struct kref *kref)
 
 	nvmem_device_remove_all_cells(nvmem);
 	nvmem_destroy_layout(nvmem);
+	gpiod_put(nvmem->wp_gpio);
 	device_unregister(&nvmem->dev);
 }