[PATCH 1/3] nvmet: prevent redundant enable/disable of nvmet_port

Max Gurtovoy mgurtovoy at nvidia.com
Sat Sep 20 16:49:41 PDT 2025


Add early return checks in nvmet_enable_port() and nvmet_disable_port()
to avoid redundant operations if the port is already enabled or
disabled.

Signed-off-by: Max Gurtovoy <mgurtovoy at nvidia.com>
---
 drivers/nvme/target/core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 0dd7bd99afa3..9f5159f04bbd 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -317,6 +317,9 @@ int nvmet_enable_port(struct nvmet_port *port)
 
 	lockdep_assert_held(&nvmet_config_sem);
 
+	if (port->enabled)
+		return 0;
+
 	if (port->disc_addr.trtype == NVMF_TRTYPE_MAX)
 		return -EINVAL;
 
@@ -382,6 +385,9 @@ void nvmet_disable_port(struct nvmet_port *port)
 
 	lockdep_assert_held(&nvmet_config_sem);
 
+	if (!port->enabled)
+		return;
+
 	port->enabled = false;
 	port->tr_ops = NULL;
 
-- 
2.18.1




More information about the Linux-nvme mailing list