Skip to contentSkip to conversation

nvme-fabrics: error out to unlock the mutex

PATCH Applied Chaitanya Kulkarni 6 participants 6 messages Jun 2, 2023 – Jun 9, 2023 NVMe

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvme-fabrics: error out to unlock the mutex

Currently, in the nvmf_host_add() function, if the nvmf_host_alloc() call failed to allocate memory for the host, the code would directly return -ENOMEM without unlocking the nvmf_hosts_mutex. This could lead to potential issues with mutex synchronization.

Fix that error handling mechanism by jumping to the out_unlock label when nvmf_host_alloc() fails. This ensures that the mutex is unlocked before returning the error code. The updated code enhances avoids possible deadlocks.

---
 drivers/nvme/host/fabrics.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/fabrics.c +4 -2
index b1fa27b60917..c4345d1d98aa 100644
@@ -92,8 +92,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
 	}
 
 	host = nvmf_host_alloc(hostnqn, id);
-	if (!host)
-		return ERR_PTR(-ENOMEM);
+	if (!host) {
+		host = ERR_PTR(-ENOMEM);
+		goto out_unlock;
+	}
 
 	list_add_tail(&host->list, &nvmf_hosts);
 out_unlock:
Signature · 1 line
2.40.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Chaitanya Kulkarni

Currently, in the nvmf_host_add() function, if the nvmf_host_alloc() call failed to allocate memory for the host, the code would directly return -ENOMEM without unlocking the nvmf_hosts_mutex. This could lead to potential issues with mutex synchronization.

Fix that error handling mechanism by jumping to the out_unlock label when nvmf_host_alloc() fails. This ensures that the mutex is unlocked before returning the error code. The updated code enhances avoids possible deadlocks.

---
 drivers/nvme/host/fabrics.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/fabrics.c +0 -0
index b1fa27b60917..c4345d1d98aa 100644
@@ -92,8 +92,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
 	}
 

drivers/nvme/host/fabrics.c static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id) · line 101

Quoted 10 lines
drivers/nvme/host/fabrics.c +4 -2
 	host = nvmf_host_alloc(hostnqn, id);
-	if (!host)
-		return ERR_PTR(-ENOMEM);
+	if (!host) {
+		host = ERR_PTR(-ENOMEM);
+		goto out_unlock;
+	}
 
 	list_add_tail(&host->list, &nvmf_hosts);
 out_unlock:

Looks good, thanks.

Quoted 4 lines

--
2.40.0

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Chaitanya Kulkarni

drivers/nvme/host/fabrics.c static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id) · line 98

Quoted 7 lines · Chaitanya Kulkarni
drivers/nvme/host/fabrics.c +4 -2
 	host = nvmf_host_alloc(hostnqn, id);
-	if (!host)
-		return ERR_PTR(-ENOMEM);
+	if (!host) {
+		host = ERR_PTR(-ENOMEM);
+		goto out_unlock;
+	}

Looks good:

Reviewed-by on v1 1/1
#3 lore raw
In reply to Chaitanya Kulkarni
Quoted 25 lines · Chaitanya Kulkarni

Currently, in the nvmf_host_add() function, if the nvmf_host_alloc() call failed to allocate memory for the host, the code would directly return -ENOMEM without unlocking the nvmf_hosts_mutex. This could lead to potential issues with mutex synchronization.

Fix that error handling mechanism by jumping to the out_unlock label when nvmf_host_alloc() fails. This ensures that the mutex is unlocked before returning the error code. The updated code enhances avoids possible deadlocks.

---
  drivers/nvme/host/fabrics.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/fabrics.c +0 -0
index b1fa27b60917..c4345d1d98aa 100644
@@ -92,8 +92,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
  	}
 

drivers/nvme/host/fabrics.c static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id) · line 101

Quoted 10 lines
drivers/nvme/host/fabrics.c +4 -2
  	host = nvmf_host_alloc(hostnqn, id);
-	if (!host)
-		return ERR_PTR(-ENOMEM);
+	if (!host) {
+		host = ERR_PTR(-ENOMEM);
+		goto out_unlock;
+	}
 
  	list_add_tail(&host->list, &nvmf_hosts);
  out_unlock:

Looks good,

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to Chaitanya Kulkarni
Quoted 11 lines

Currently, in the nvmf_host_add() function, if the nvmf_host_alloc() call failed to allocate memory for the host, the code would directly return -ENOMEM without unlocking the nvmf_hosts_mutex. This could lead to potential issues with mutex synchronization.

Fix that error handling mechanism by jumping to the out_unlock label when nvmf_host_alloc() fails. This ensures that the mutex is unlocked before returning the error code. The updated code enhances avoids possible deadlocks.

Quoted 4 lines

Can add:

Fixes f0cebf82004d ("nvme-fabrics: prevent overriding of existing host")

otherwise: