[PATCH v4 6/6] lib/vhost: remove check around pthread_mutex_init()

Maxime Coquelin maxime.coquelin at redhat.com
Tue Jan 14 09:48:48 CET 2025



On 1/14/25 8:50 AM, Ariel Otilibili wrote:
>> pthread_mutex_init always returns 0. The other mutex functions
>> return 0 on success and a non-zero error code on error.
> 
> Link: https://man7.org/linux/man-pages/man3/pthread_mutex_lock.3.html
> Bugzilla ID: 1586
> Cc: Maxime Coquelin <maxime.coquelin at redhat.com>
> Cc: Chenbo Xia <chenbox at nvidia.com>
> Signed-off-by: Ariel Otilibili <otilibil at eurecom.fr>
> Acked-by: Stephen Hemminger <stephen at networkplumber.org>
> ---
>   lib/vhost/socket.c | 14 ++------------
>   1 file changed, 2 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/vhost/socket.c b/lib/vhost/socket.c
> index d29d15494c8e..531aa8adc06c 100644
> --- a/lib/vhost/socket.c
> +++ b/lib/vhost/socket.c
> @@ -498,11 +498,7 @@ vhost_user_reconnect_init(void)
>   {
>   	int ret;
>   
> -	ret = pthread_mutex_init(&reconn_list.mutex, NULL);
> -	if (ret < 0) {
> -		VHOST_CONFIG_LOG("thread", ERR, "%s: failed to initialize mutex", __func__);
> -		return ret;
> -	}
> +	pthread_mutex_init(&reconn_list.mutex, NULL);
>   	TAILQ_INIT(&reconn_list.head);
>   
>   	ret = rte_thread_create_internal_control(&reconn_tid, "vhost-reco",
> @@ -921,11 +917,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
>   		goto out;
>   	}
>   	TAILQ_INIT(&vsocket->conn_list);
> -	ret = pthread_mutex_init(&vsocket->conn_mutex, NULL);
> -	if (ret) {
> -		VHOST_CONFIG_LOG(path, ERR, "failed to init connection mutex");
> -		goto out_free;
> -	}
> +	pthread_mutex_init(&vsocket->conn_mutex, NULL);
>   
>   	if (!strncmp("/dev/vduse/", path, strlen("/dev/vduse/")))
>   		vsocket->is_vduse = true;
> @@ -1034,8 +1026,6 @@ rte_vhost_driver_register(const char *path, uint64_t flags)
>   	if (pthread_mutex_destroy(&vsocket->conn_mutex)) {
>   		VHOST_CONFIG_LOG(path, ERR, "failed to destroy connection mutex");
>   	}
> -out_free:
> -	vhost_user_socket_mem_free(vsocket);
>   out:
>   	pthread_mutex_unlock(&vhost_user.mutex);
>   

Reviewed-by: Maxime Coquelin <maxime.coquelin at redhat.com>

Thanks,
Maxime



More information about the dev mailing list