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

Stephen Hemminger stephen at networkplumber.org
Fri Dec 20 06:24:12 CET 2024


On Fri, 20 Dec 2024 09:53:26 +0800
Sunyang Wu <sunyang.wu at jaguarmicro.com> wrote:

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

This is wasted and dead code.
The man page for pthread_mutex_init explicitly says:

RETURN VALUE
       pthread_mutex_init  always  returns  0. 


More information about the dev mailing list