[PATCH v2 04/11] nvmem: release write protection when the provider disconnects
From: James Hilliard
Date: Thu Nov 19 2026 - 11:43:28 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 7d75076cda49..8c9dfd2e2a63 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -564,7 +564,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);
@@ -912,6 +911,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