nvme-fabrics: error out to unlock the mutex
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
@@ -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
Quoted 25 lines · Chaitanya Kulkarni
Currently, in the
nvmf_host_add()function, if thenvmf_host_alloc()call failed to allocate memory for the host, the code would directly return-ENOMEMwithout unlocking thenvmf_hosts_mutex. This could lead to potential issues with mutex synchronization.Fix that error handling mechanism by jumping to the
out_unlocklabel whennvmf_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 <[email protected]>Reported-by Julia Lawall <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>--- drivers/nvme/host/fabrics.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/nvme/host/fabrics.c +0
-0@@ -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
-2host =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
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
-2host =nvmf_host_alloc (hostnqn, id); -if (!host) -return ERR_PTR (-ENOMEM ); +if (!host) { + host =ERR_PTR (-ENOMEM ); + goto out_unlock; + }
Looks good:
Quoted 25 lines · Chaitanya Kulkarni
Currently, in the
nvmf_host_add()function, if thenvmf_host_alloc()call failed to allocate memory for the host, the code would directly return-ENOMEMwithout unlocking thenvmf_hosts_mutex. This could lead to potential issues with mutex synchronization.Fix that error handling mechanism by jumping to the
out_unlocklabel whennvmf_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 <[email protected]>Reported-by Julia Lawall <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>--- drivers/nvme/host/fabrics.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)drivers/nvme/host/fabrics.c +0
-0@@ -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
-2host =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,
Quoted 11 lines
Currently, in the
nvmf_host_add()function, if thenvmf_host_alloc()call failed to allocate memory for the host, the code would directly return-ENOMEMwithout unlocking thenvmf_hosts_mutex. This could lead to potential issues with mutex synchronization.Fix that error handling mechanism by jumping to the
out_unlocklabel whennvmf_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
Reported-by kernel test robot <[email protected]>Reported-by Julia Lawall <[email protected]>Signed-off-by Chaitanya Kulkarni <[email protected]>
Can add:
otherwise:
Thanks, applied for nvme-6.5.