vhost: small cleanups
cover vhost: small cleanups
This series is a bunch of small cleanups regarding checking return values etc.
regards,
Jens
Jens Freimann (3):
vhost: add missing check strdup() return value
vhost: check return values of pthread_* calls
vhost: check return value of pthread_mutex_init()
lib/librte_vhost/socket.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-)
Signature · 1 line
2.9.4
PATCH 1/3 vhost: add missing check strdup() return value
From: Jens Freimann <[email protected]>
Add a check for strdup() return value and fail gracefully if we get a bad return code.
--- lib/librte_vhost/socket.c | 6 ++++++ 1 file changed, 6 insertions(+)
lib/librte_vhost/socket.c +6 -0
@@ -613,6 +613,12 @@ rte_vhost_driver_register(const char *path, uint64_t flags) goto out;memset (vsocket,0 ,sizeof (struct vhost_user_socket )); vsocket->path =strdup (path); +if (vsocket->path ==NULL ) { +RTE_LOG (ERR ,VHOST_CONFIG , +"error: failed to copy socket path string\n" ); +free (vsocket); + goto out; + }TAILQ_INIT (&vsocket->conn_list);pthread_mutex_init (&vsocket->conn_mutex,NULL ); vsocket->dequeue_zero_copy = flags &RTE_VHOST_USER_DEQUEUE_ZERO_COPY ;
Signature · 1 line
2.9.4
PATCH 2/3 vhost: check return values of pthread_* calls
In reply to Jens FreimannMake sure we catch and log failed calls to pthread functions.
--- lib/librte_vhost/socket.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-)
lib/librte_vhost/socket.c +15 -9
@@ -620,7 +620,12 @@ rte_vhost_driver_register(const char *path, uint64_t flags) goto out; }TAILQ_INIT (&vsocket->conn_list); -pthread_mutex_init (&vsocket->conn_mutex,NULL ); + ret =pthread_mutex_init (&vsocket->conn_mutex,NULL ); +if (ret) { +RTE_LOG (ERR ,VHOST_CONFIG , +"error: failed to init connection mutex\n" ); + goto out_free; + } vsocket->dequeue_zero_copy = flags &RTE_VHOST_USER_DEQUEUE_ZERO_COPY ;/*
@@ -642,10 +647,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) vsocket->reconnect = !(flags &RTE_VHOST_USER_NO_RECONNECT );if (vsocket->reconnect && reconn_tid ==0 ) {if (vhost_user_reconnect_init () <0 ) { -pthread_mutex_destroy (&vsocket->conn_mutex); -free (vsocket->path); -free (vsocket); - goto out; + goto out_mutex; } } }else {
@@ -653,14 +655,18 @@ rte_vhost_driver_register(const char *path, uint64_t flags) } ret =create_unix_socket (vsocket);if (ret <0 ) { -pthread_mutex_destroy (&vsocket->conn_mutex); -free (vsocket->path); -free (vsocket); - goto out; + goto out_mutex; } vhost_user.vsockets[vhost_user.vsocket_cnt++] = vsocket; +out_mutex: +if (pthread_mutex_destroy (&vsocket->conn_mutex)) +RTE_LOG (ERR ,VHOST_CONFIG , +"error: failed to destroy connection mutex\n" ); +out_free: +free (vsocket->path); +free (vsocket); out:pthread_mutex_unlock (&vhost_user.mutex);
Signature · 1 line
2.9.4
Re: [PATCH 2/3] vhost: check return values of pthread_* calls
lib/librte_vhost/socket.c rte_vhost_driver_register(const char *path, uint64_t flags) · line 666
Quoted 4 lines · Jens Freimann
lib/librte_vhost/socket.c +4
-0+out_mutex: +if (pthread_mutex_destroy (&vsocket->conn_mutex)) +RTE_LOG (ERR ,VHOST_CONFIG , +"error: failed to destroy connection mutex\n" );
One minor comment though: {} should be used for one signle statement spawning more than one lines. See section "1.6.2. Control Statements and Loops":
http://dpdk.org/doc/guides/contributing/coding_style.html
Anyway, I fixed while apply.
--yliu
Re: [PATCH 2/3] vhost: check return values of pthread_* calls
Quoted 11 lines · Yuanhan Liu
lib/librte_vhost/socket.c rte_vhost_driver_register(const char *path, uint64_t flags) · line 666
Quoted 4 lines · Jens Freimann
lib/librte_vhost/socket.c +4
-0+out_mutex: +if (pthread_mutex_destroy (&vsocket->conn_mutex)) +RTE_LOG (ERR ,VHOST_CONFIG , +"error: failed to destroy connection mutex\n" );One minor comment though: {} should be used for one signle statement spawning more than one lines. See section "1.6.2. Control Statements and Loops":
Sorry, checkpatch didn't complain. I'll make sure to add the parentheses in the future.
Quoted 1 line
Anyway, I fixed while apply.
Thanks!
regards,
Jens
PATCH 3/3 vhost: check return value of pthread_mutex_init()
In reply to Jens FreimannCheck return value of pthread_mutex_init(). Also destroy mutex in case of other erros before returning.
--- lib/librte_vhost/socket.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
lib/librte_vhost/socket.c +10 -2
@@ -445,13 +445,21 @@ vhost_user_reconnect_init(void) {int ret; -pthread_mutex_init (&reconn_list.mutex,NULL ); + ret =pthread_mutex_init (&reconn_list.mutex,NULL ); +if (ret <0 ) { +RTE_LOG (ERR ,VHOST_CONFIG ,"failed to initialize mutex" ); +return ret; + }TAILQ_INIT (&reconn_list.head); ret =pthread_create (&reconn_tid,NULL , vhost_user_client_reconnect,NULL ); -if (ret <0 ) +if (ret <0 ) {RTE_LOG (ERR ,VHOST_CONFIG ,"failed to create reconnect thread" ); +if (pthread_mutex_destroy (&reconn_list.mutex)) +RTE_LOG (ERR ,VHOST_CONFIG , +"failed to destroy reconnect mutex" ); + }return ret; }
Signature · 1 line
2.9.4
Quoted 1 line · Jens Freimann
This series is a bunch of small cleanups regarding checking return values etc.
Series applied to dpdk-next-virtio. You probably need update your script (if you are using one) about my email address.
Thanks.
--yliu
Quoted 5 lines · Yuanhan Liu
Quoted 1 line · Jens Freimann
This series is a bunch of small cleanups regarding checking return values etc.
Series applied to dpdk-next-virtio. You probably need update your script (if you are using one) about my email address.
Sorry, thought I already did. Fixed now.
regards,
Jens