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

Message ID 20250114075033.2027286-7-otilibil@eurecom.fr (mailing list archive)
State Accepted
Delegated to: Stephen Hemminger
Headers
Series remove check around pthread_mutex_init() |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS

Commit Message

Ariel Otilibili-Anieli Jan. 14, 2025, 7:50 a.m. UTC
> 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@redhat.com>
Cc: Chenbo Xia <chenbox@nvidia.com>
Signed-off-by: Ariel Otilibili <otilibil@eurecom.fr>
Acked-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/vhost/socket.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
  

Comments

Maxime Coquelin Jan. 14, 2025, 8:48 a.m. UTC | #1
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@redhat.com>
> Cc: Chenbo Xia <chenbox@nvidia.com>
> Signed-off-by: Ariel Otilibili <otilibil@eurecom.fr>
> Acked-by: Stephen Hemminger <stephen@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@redhat.com>

Thanks,
Maxime
  
Ariel Otilibili-Anieli Jan. 14, 2025, 11:03 a.m. UTC | #2
Hello Maxime,

On Tuesday, January 14, 2025 09:48 CET, Maxime Coquelin <maxime.coquelin@redhat.com> wrote:

> 
> 
> On 1/14/25 8:50 AM, Ariel Otilibili wrote:
> 
> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> 
Thanks!

Have a good day,
Ariel
> Thanks,
> Maxime
>
  

Patch

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);