[v2,09/83] lib/vhost: remove unnecessary NULL checks

Message ID 20220124174719.14417-10-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series remove unnecessary null checks |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Jan. 24, 2022, 5:46 p.m. UTC
  Remove redundant NULL pointer checks before free functions
found by nullfree.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/vhost/iotlb.c        | 3 +--
 lib/vhost/vhost_crypto.c | 6 ++----
 lib/vhost/vhost_user.c   | 9 +++------
 3 files changed, 6 insertions(+), 12 deletions(-)
  

Comments

Chenbo Xia Jan. 27, 2022, 5:52 a.m. UTC | #1
Hi Stephen,

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Tuesday, January 25, 2022 1:46 AM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Maxime Coquelin
> <maxime.coquelin@redhat.com>; Xia, Chenbo <chenbo.xia@intel.com>
> Subject: [PATCH v2 09/83] lib/vhost: remove unnecessary NULL checks

Title should be: vhost: remove unnecessary NULL checks

With this fixed:

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>

> 
> Remove redundant NULL pointer checks before free functions
> found by nullfree.cocci
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/vhost/iotlb.c        | 3 +--
>  lib/vhost/vhost_crypto.c | 6 ++----
>  lib/vhost/vhost_user.c   | 9 +++------
>  3 files changed, 6 insertions(+), 12 deletions(-)
> 
> diff --git a/lib/vhost/iotlb.c b/lib/vhost/iotlb.c
> index 82bdb84526ea..d6b8c0a396b5 100644
> --- a/lib/vhost/iotlb.c
> +++ b/lib/vhost/iotlb.c
> @@ -315,8 +315,7 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
> 
>  	/* If already created, free it and recreate */
>  	vq->iotlb_pool = rte_mempool_lookup(pool_name);
> -	if (vq->iotlb_pool)
> -		rte_mempool_free(vq->iotlb_pool);
> +	rte_mempool_free(vq->iotlb_pool);
> 
>  	vq->iotlb_pool = rte_mempool_create(pool_name,
>  			IOTLB_CACHE_SIZE, sizeof(struct vhost_iotlb_entry), 0,
> diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c
> index 926b5c0bd94a..012e0cefdeba 100644
> --- a/lib/vhost/vhost_crypto.c
> +++ b/lib/vhost/vhost_crypto.c
> @@ -1498,10 +1498,8 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
>  	return 0;
> 
>  error_exit:
> -	if (vcrypto->session_map)
> -		rte_hash_free(vcrypto->session_map);
> -	if (vcrypto->mbuf_pool)
> -		rte_mempool_free(vcrypto->mbuf_pool);
> +	rte_hash_free(vcrypto->session_map);
> +	rte_mempool_free(vcrypto->mbuf_pool);
> 
>  	rte_free(vcrypto);
> 
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index 5eb1dd681231..23a0e3fb3600 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -489,8 +489,7 @@ vhost_user_set_vring_num(struct virtio_net **pdev,
>  	}
> 
>  	if (vq_is_packed(dev)) {
> -		if (vq->shadow_used_packed)
> -			rte_free(vq->shadow_used_packed);
> +		rte_free(vq->shadow_used_packed);
>  		vq->shadow_used_packed = rte_malloc_socket(NULL,
>  				vq->size *
>  				sizeof(struct vring_used_elem_packed),
> @@ -502,8 +501,7 @@ vhost_user_set_vring_num(struct virtio_net **pdev,
>  		}
> 
>  	} else {
> -		if (vq->shadow_used_split)
> -			rte_free(vq->shadow_used_split);
> +		rte_free(vq->shadow_used_split);
> 
>  		vq->shadow_used_split = rte_malloc_socket(NULL,
>  				vq->size * sizeof(struct vring_used_elem),
> @@ -516,8 +514,7 @@ vhost_user_set_vring_num(struct virtio_net **pdev,
>  		}
>  	}
> 
> -	if (vq->batch_copy_elems)
> -		rte_free(vq->batch_copy_elems);
> +	rte_free(vq->batch_copy_elems);
>  	vq->batch_copy_elems = rte_malloc_socket(NULL,
>  				vq->size * sizeof(struct batch_copy_elem),
>  				RTE_CACHE_LINE_SIZE, vq->numa_node);
> --
> 2.30.2
  

Patch

diff --git a/lib/vhost/iotlb.c b/lib/vhost/iotlb.c
index 82bdb84526ea..d6b8c0a396b5 100644
--- a/lib/vhost/iotlb.c
+++ b/lib/vhost/iotlb.c
@@ -315,8 +315,7 @@  vhost_user_iotlb_init(struct virtio_net *dev, int vq_index)
 
 	/* If already created, free it and recreate */
 	vq->iotlb_pool = rte_mempool_lookup(pool_name);
-	if (vq->iotlb_pool)
-		rte_mempool_free(vq->iotlb_pool);
+	rte_mempool_free(vq->iotlb_pool);
 
 	vq->iotlb_pool = rte_mempool_create(pool_name,
 			IOTLB_CACHE_SIZE, sizeof(struct vhost_iotlb_entry), 0,
diff --git a/lib/vhost/vhost_crypto.c b/lib/vhost/vhost_crypto.c
index 926b5c0bd94a..012e0cefdeba 100644
--- a/lib/vhost/vhost_crypto.c
+++ b/lib/vhost/vhost_crypto.c
@@ -1498,10 +1498,8 @@  rte_vhost_crypto_create(int vid, uint8_t cryptodev_id,
 	return 0;
 
 error_exit:
-	if (vcrypto->session_map)
-		rte_hash_free(vcrypto->session_map);
-	if (vcrypto->mbuf_pool)
-		rte_mempool_free(vcrypto->mbuf_pool);
+	rte_hash_free(vcrypto->session_map);
+	rte_mempool_free(vcrypto->mbuf_pool);
 
 	rte_free(vcrypto);
 
diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 5eb1dd681231..23a0e3fb3600 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -489,8 +489,7 @@  vhost_user_set_vring_num(struct virtio_net **pdev,
 	}
 
 	if (vq_is_packed(dev)) {
-		if (vq->shadow_used_packed)
-			rte_free(vq->shadow_used_packed);
+		rte_free(vq->shadow_used_packed);
 		vq->shadow_used_packed = rte_malloc_socket(NULL,
 				vq->size *
 				sizeof(struct vring_used_elem_packed),
@@ -502,8 +501,7 @@  vhost_user_set_vring_num(struct virtio_net **pdev,
 		}
 
 	} else {
-		if (vq->shadow_used_split)
-			rte_free(vq->shadow_used_split);
+		rte_free(vq->shadow_used_split);
 
 		vq->shadow_used_split = rte_malloc_socket(NULL,
 				vq->size * sizeof(struct vring_used_elem),
@@ -516,8 +514,7 @@  vhost_user_set_vring_num(struct virtio_net **pdev,
 		}
 	}
 
-	if (vq->batch_copy_elems)
-		rte_free(vq->batch_copy_elems);
+	rte_free(vq->batch_copy_elems);
 	vq->batch_copy_elems = rte_malloc_socket(NULL,
 				vq->size * sizeof(struct batch_copy_elem),
 				RTE_CACHE_LINE_SIZE, vq->numa_node);