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: f0cebf82004d ("nvme-fabrics: prevent overriding of existing host") Reported-by: kernel test robot <[email protected]> Reported-by: Julia Lawall <[email protected]> Closes: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Julia Lawall <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Max Gurtovoy <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Keith Busch <[email protected]>
1 parent bdbfcd5 commit 900095b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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)