diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
index 0ef7b95348b1b..1505c745154e7 100644
--- a/drivers/nvmem/core.c
+++ b/drivers/nvmem/core.c
@@ -638,6 +638,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config)
 						    GPIOD_OUT_HIGH);
 	if (IS_ERR(nvmem->wp_gpio)) {
 		rval = PTR_ERR(nvmem->wp_gpio);
+		nvmem->wp_gpio = NULL;
 		goto err_put_device;
 	}