[PATCH 04/11] nvmem: release write protection when the provider disconnects
From: James Hilliard
Date: Tue Nov 17 2026 - 14:39:05 EST
Retained NVMEM consumers keep the device allocation alive after unregister.
Keeping the write-protect GPIO until final device release prevents a
replacement provider from requesting the same GPIO.
Release it after draining provider callbacks, when no write can still
use it. Do this for registration failures as well as unregister.
Fixes: 2a127da461a9 ("nvmem: add support for the write-protect pin")
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
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 c41266241f3f..65d89498edeb 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -584,7 +584,6 @@ static void nvmem_release(struct device *dev)
{
struct nvmem_device *nvmem = to_nvmem_device(dev);
- gpiod_put(nvmem->wp_gpio);
nvmem_device_remove_all_cells(nvmem);
ida_free(&nvmem_ida, nvmem->id);
of_node_put(nvmem->dev.of_node);
@@ -922,6 +921,8 @@ static void nvmem_disconnect(struct nvmem_device *nvmem)
ops = rcu_replace_pointer(nvmem->ops, NULL,
lockdep_is_held(&nvmem_mutex));
synchronize_srcu(&nvmem->srcu);
+ gpiod_put(nvmem->wp_gpio);
+ nvmem->wp_gpio = NULL;
kfree(ops);
}
--
2.53.0