[PATCH] nvme-fabrics: error out to unlock the mutex

Julia Lawall julia.lawall at inria.fr
Thu Jun 1 22:42:24 PDT 2023



On Thu, 1 Jun 2023, Chaitanya Kulkarni wrote:

> 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 at intel.com>
> Reported-by: Julia Lawall <julia.lawall at inria.fr>
> Closes: https://lore.kernel.org/r/202306020909.MTUEBeIa-lkp@intel.com/
> Signed-off-by: Chaitanya Kulkarni <kch at 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:

Looks good, thanks.

Reviewed-by: Julia Lawall <julia.lawall at inria.fr>



> --
> 2.40.0
>
>



More information about the Linux-nvme mailing list