From 900095bfbbf6623fbfa9e5ceb3982f293b6f3275 Mon Sep 17 00:00:00 2001 From: Chaitanya Kulkarni Date: Thu, 1 Jun 2023 22:37:13 -0700 Subject: 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. Fixes: f0cebf82004d ("nvme-fabrics: prevent overriding of existing host") Reported-by: kernel test robot Reported-by: Julia Lawall Closes: https://lore.kernel.org/r/202306020909.MTUEBeIa-lkp@intel.com/ Signed-off-by: Chaitanya Kulkarni Reviewed-by: Julia Lawall Reviewed-by: Sagi Grimberg Reviewed-by: Max Gurtovoy Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch --- drivers/nvme/host/fabrics.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'drivers/nvme') 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: -- cgit v1.2.3