[PATCH] net/virtio: check return value when calling pthread_mutex_init

Sunyang Wu sunyang.wu at jaguarmicro.com
Fri Dec 20 02:53:26 CET 2024


Add validation for the return value of the pthread_mutex_init.

Signed-off-by: Sunyang Wu <sunyang.wu at jaguarmicro.com>
---
 drivers/net/virtio/virtio_user/virtio_user_dev.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/virtio/virtio_user/virtio_user_dev.c b/drivers/net/virtio/virtio_user/virtio_user_dev.c
index 2997d2bd26..00272cf802 100644
--- a/drivers/net/virtio/virtio_user/virtio_user_dev.c
+++ b/drivers/net/virtio/virtio_user/virtio_user_dev.c
@@ -735,8 +735,13 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
 		     enum virtio_user_backend_type backend_type)
 {
 	uint64_t backend_features;
+	int ret;
 
-	pthread_mutex_init(&dev->mutex, NULL);
+	ret = pthread_mutex_init(&dev->mutex, NULL);
+	if (ret) {
+		PMD_INIT_LOG(ERR, "(%s) init dev mutex failed", dev->path);
+		return ret;
+	}
 	strlcpy(dev->path, path, PATH_MAX);
 
 	dev->started = 0;
-- 
2.19.0.rc0.windows.1



More information about the dev mailing list