DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/3] vhost: small cleanups
@ 2017-07-04  8:50 Jens Freimann
  2017-07-04  8:50 ` [dpdk-dev] [PATCH 1/3] vhost: add missing check strdup() return value Jens Freimann
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Jens Freimann @ 2017-07-04  8:50 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, maxime.coquelin

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

-- 
2.9.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-dev] [PATCH 1/3] vhost: add missing check strdup() return value
  2017-07-04  8:50 [dpdk-dev] [PATCH 0/3] vhost: small cleanups Jens Freimann
@ 2017-07-04  8:50 ` Jens Freimann
  2017-07-04  8:50 ` [dpdk-dev] [PATCH 2/3] vhost: check return values of pthread_* calls Jens Freimann
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: Jens Freimann @ 2017-07-04  8:50 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, maxime.coquelin

From: Jens Freimann <jfreiman@redhat.com>

Add a check for strdup() return value and fail gracefully if we
get a bad return code.

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-dev] [PATCH 2/3] vhost: check return values of pthread_* calls
  2017-07-04  8:50 [dpdk-dev] [PATCH 0/3] vhost: small cleanups Jens Freimann
  2017-07-04  8:50 ` [dpdk-dev] [PATCH 1/3] vhost: add missing check strdup() return value Jens Freimann
@ 2017-07-04  8:50 ` Jens Freimann
  2017-07-04  9:17   ` Yuanhan Liu
  2017-07-04  8:50 ` [dpdk-dev] [PATCH 3/3] vhost: check return value of pthread_mutex_init() Jens Freimann
  2017-07-04  9:15 ` [dpdk-dev] [PATCH 0/3] vhost: small cleanups Yuanhan Liu
  3 siblings, 1 reply; 8+ messages in thread
From: Jens Freimann @ 2017-07-04  8:50 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, maxime.coquelin

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

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-dev] [PATCH 3/3] vhost: check return value of pthread_mutex_init()
  2017-07-04  8:50 [dpdk-dev] [PATCH 0/3] vhost: small cleanups Jens Freimann
  2017-07-04  8:50 ` [dpdk-dev] [PATCH 1/3] vhost: add missing check strdup() return value Jens Freimann
  2017-07-04  8:50 ` [dpdk-dev] [PATCH 2/3] vhost: check return values of pthread_* calls Jens Freimann
@ 2017-07-04  8:50 ` Jens Freimann
  2017-07-04  9:15 ` [dpdk-dev] [PATCH 0/3] vhost: small cleanups Yuanhan Liu
  3 siblings, 0 replies; 8+ messages in thread
From: Jens Freimann @ 2017-07-04  8:50 UTC (permalink / raw)
  To: dev; +Cc: yuanhan.liu, maxime.coquelin

Check return value of pthread_mutex_init(). Also destroy
mutex in case of other erros before returning.

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

diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c
index 7b5df6f..83ef943 100644
--- a/lib/librte_vhost/socket.c
+++ b/lib/librte_vhost/socket.c
@@ -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;
 }
-- 
2.9.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH 0/3] vhost: small cleanups
  2017-07-04  8:50 [dpdk-dev] [PATCH 0/3] vhost: small cleanups Jens Freimann
                   ` (2 preceding siblings ...)
  2017-07-04  8:50 ` [dpdk-dev] [PATCH 3/3] vhost: check return value of pthread_mutex_init() Jens Freimann
@ 2017-07-04  9:15 ` Yuanhan Liu
  2017-07-04  9:23   ` Jens Freimann
  3 siblings, 1 reply; 8+ messages in thread
From: Yuanhan Liu @ 2017-07-04  9:15 UTC (permalink / raw)
  To: Jens Freimann; +Cc: dev, maxime.coquelin

On Tue, Jul 04, 2017 at 10:50:40AM +0200, Jens Freimann wrote:
> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH 2/3] vhost: check return values of pthread_* calls
  2017-07-04  8:50 ` [dpdk-dev] [PATCH 2/3] vhost: check return values of pthread_* calls Jens Freimann
@ 2017-07-04  9:17   ` Yuanhan Liu
  2017-07-04  9:28     ` Jens Freimann
  0 siblings, 1 reply; 8+ messages in thread
From: Yuanhan Liu @ 2017-07-04  9:17 UTC (permalink / raw)
  To: Jens Freimann; +Cc: dev, maxime.coquelin

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH 0/3] vhost: small cleanups
  2017-07-04  9:15 ` [dpdk-dev] [PATCH 0/3] vhost: small cleanups Yuanhan Liu
@ 2017-07-04  9:23   ` Jens Freimann
  0 siblings, 0 replies; 8+ messages in thread
From: Jens Freimann @ 2017-07-04  9:23 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: dev, maxime.coquelin

On Tue, Jul 04, 2017 at 05:15:23PM +0800, Yuanhan Liu wrote:
>On Tue, Jul 04, 2017 at 10:50:40AM +0200, Jens Freimann wrote:
>> 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 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-dev] [PATCH 2/3] vhost: check return values of pthread_* calls
  2017-07-04  9:17   ` Yuanhan Liu
@ 2017-07-04  9:28     ` Jens Freimann
  0 siblings, 0 replies; 8+ messages in thread
From: Jens Freimann @ 2017-07-04  9:28 UTC (permalink / raw)
  To: Yuanhan Liu; +Cc: dev, maxime.coquelin

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 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-07-04  9:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-04  8:50 [dpdk-dev] [PATCH 0/3] vhost: small cleanups Jens Freimann
2017-07-04  8:50 ` [dpdk-dev] [PATCH 1/3] vhost: add missing check strdup() return value Jens Freimann
2017-07-04  8:50 ` [dpdk-dev] [PATCH 2/3] vhost: check return values of pthread_* calls Jens Freimann
2017-07-04  9:17   ` Yuanhan Liu
2017-07-04  9:28     ` Jens Freimann
2017-07-04  8:50 ` [dpdk-dev] [PATCH 3/3] vhost: check return value of pthread_mutex_init() Jens Freimann
2017-07-04  9:15 ` [dpdk-dev] [PATCH 0/3] vhost: small cleanups Yuanhan Liu
2017-07-04  9:23   ` Jens Freimann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).