[dpdk-dev,2/3] vhost: check return values of pthread_* calls

Message ID 20170704085043.3662-3-jfreimann@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply patch file failure

Commit Message

Jens Freimann July 4, 2017, 8:50 a.m. UTC
  Make sure we catch and log failed calls to pthread
functions.

Signed-off-by: Jens Freimann <jfreimann@redhat.com>
---
 lib/librte_vhost/socket.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
  

Comments

Yuanhan Liu July 4, 2017, 9:17 a.m. UTC | #1
On Tue, Jul 04, 2017 at 10:50:42AM +0200, Jens Freimann wrote:
> +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
  
Jens Freimann July 4, 2017, 9:28 a.m. UTC | #2
On Tue, Jul 04, 2017 at 05:17:28PM +0800, Yuanhan Liu wrote:
>On Tue, Jul 04, 2017 at 10:50:42AM +0200, Jens Freimann wrote:
>> +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

Sorry, checkpatch didn't complain. I'll make sure to add the
parentheses in the future. 

>Anyway, I fixed while apply.

Thanks! 

regards,
Jens
  

Patch

diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index 42b25d3..7b5df6f 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -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);