Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] nvme-fabrics: error out to unlock the mutex
@ 2023-06-02  5:37 Chaitanya Kulkarni
  2023-06-02  5:42 ` Julia Lawall
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Chaitanya Kulkarni @ 2023-06-02  5:37 UTC (permalink / raw)
  To: linux-nvme
  Cc: kbusch, axboe, hch, sagi, Chaitanya Kulkarni, kernel test robot,
	Julia Lawall

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.

Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Julia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/r/202306020909.MTUEBeIa-lkp@intel.com/
Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/nvme/host/fabrics.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index b1fa27b60917..c4345d1d98aa 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -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:
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-09 15:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-02  5:37 [PATCH] nvme-fabrics: error out to unlock the mutex Chaitanya Kulkarni
2023-06-02  5:42 ` Julia Lawall
2023-06-02 15:03 ` Christoph Hellwig
2023-06-04  0:38 ` Max Gurtovoy
2023-06-05 22:40 ` Sagi Grimberg
2023-06-09 15:38 ` Keith Busch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox