[PATCH 06/10] nvmem: release write protection when the provider disconnects

From: srini

Date: Tue Dec 01 2026 - 18:27:29 EST


From: James Hilliard <james.hilliard1@xxxxxxxxx>

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: 6a7b4134fb7a ("nvmem: protect nvmem_device::ops with SRCU")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
Signed-off-by: Srinivas Kandagatla <srini@xxxxxxxxxx>
---
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 0bfe26ed86f9..b334a64b85fc 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -563,7 +563,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);
@@ -913,6 +912,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