Skip to content

Commit 900095b

Browse files
Chaitanya Kulkarnikeithbusch
authored andcommitted
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: f0cebf8 ("nvme-fabrics: prevent overriding of existing host") 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> Reviewed-by: Julia Lawall <julia.lawall@inria.fr> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent bdbfcd5 commit 900095b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/nvme/host/fabrics.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ static struct nvmf_host *nvmf_host_add(const char *hostnqn, uuid_t *id)
9292
}
9393

9494
host = nvmf_host_alloc(hostnqn, id);
95-
if (!host)
96-
return ERR_PTR(-ENOMEM);
95+
if (!host) {
96+
host = ERR_PTR(-ENOMEM);
97+
goto out_unlock;
98+
}
9799

98100
list_add_tail(&host->list, &nvmf_hosts);
99101
out_unlock:

0 commit comments

Comments
 (0)