diff mbox series

[v2,03/83] eal: remove unnecessary NULL checks

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

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Jan. 24, 2022, 5:45 p.m. UTC
Functions like free() already handle NULL pointer so
the checks here are not necessary.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/common/eal_common_devargs.c   |  6 ++----
 lib/eal/common/eal_common_memzone.c   |  3 +--
 lib/eal/common/eal_common_options.c   |  9 +++------
 lib/eal/common/eal_common_trace_ctf.c |  6 ++----
 lib/eal/freebsd/eal.c                 |  4 +---
 lib/eal/linux/eal.c                   | 10 +++-------
 6 files changed, 12 insertions(+), 26 deletions(-)
diff mbox series

Patch

diff --git a/lib/eal/common/eal_common_devargs.c b/lib/eal/common/eal_common_devargs.c
index 8c7650cf6c27..69004b0a2d2f 100644
--- a/lib/eal/common/eal_common_devargs.c
+++ b/lib/eal/common/eal_common_devargs.c
@@ -161,8 +161,7 @@  rte_devargs_layers_parse(struct rte_devargs *devargs,
 
 get_out:
 	for (i = 0; i < RTE_DIM(layers); i++) {
-		if (layers[i].kvlist)
-			rte_kvargs_free(layers[i].kvlist);
+		rte_kvargs_free(layers[i].kvlist);
 	}
 	if (ret != 0) {
 		if (allocated_data) {
@@ -285,8 +284,7 @@  rte_devargs_reset(struct rte_devargs *da)
 {
 	if (da == NULL)
 		return;
-	if (da->data)
-		free(da->data);
+	free(da->data);
 	da->data = NULL;
 }
 
diff --git a/lib/eal/common/eal_common_memzone.c b/lib/eal/common/eal_common_memzone.c
index ecde9441ee90..9a0c5309ac7e 100644
--- a/lib/eal/common/eal_common_memzone.c
+++ b/lib/eal/common/eal_common_memzone.c
@@ -300,8 +300,7 @@  rte_memzone_free(const struct rte_memzone *mz)
 
 	rte_rwlock_write_unlock(&mcfg->mlock);
 
-	if (addr != NULL)
-		rte_free(addr);
+	rte_free(addr);
 
 	rte_eal_trace_memzone_free(name, addr, ret);
 	return ret;
diff --git a/lib/eal/common/eal_common_options.c b/lib/eal/common/eal_common_options.c
index 1cfdd75f3b79..09b7b17ffa06 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -1962,12 +1962,9 @@  compute_ctrl_threads_cpuset(struct internal_config *internal_cfg)
 int
 eal_cleanup_config(struct internal_config *internal_cfg)
 {
-	if (internal_cfg->hugefile_prefix != NULL)
-		free(internal_cfg->hugefile_prefix);
-	if (internal_cfg->hugepage_dir != NULL)
-		free(internal_cfg->hugepage_dir);
-	if (internal_cfg->user_mbuf_pool_ops_name != NULL)
-		free(internal_cfg->user_mbuf_pool_ops_name);
+	free(internal_cfg->hugefile_prefix);
+	free(internal_cfg->hugepage_dir);
+	free(internal_cfg->user_mbuf_pool_ops_name);
 
 	return 0;
 }
diff --git a/lib/eal/common/eal_common_trace_ctf.c b/lib/eal/common/eal_common_trace_ctf.c
index 33e419aac7fb..3b83bcdf57fd 100644
--- a/lib/eal/common/eal_common_trace_ctf.c
+++ b/lib/eal/common/eal_common_trace_ctf.c
@@ -52,8 +52,7 @@  meta_copy(char **meta, int *offset, char *str, int rc)
 	return rc;
 
 free_str:
-	if (str)
-		free(str);
+	free(str);
 	return -ENOMEM;
 }
 
@@ -291,8 +290,7 @@  trace_metadata_create(void)
 	return 0;
 
 fail:
-	if (meta)
-		free(meta);
+	free(meta);
 	return -EBADF;
 }
 
diff --git a/lib/eal/freebsd/eal.c b/lib/eal/freebsd/eal.c
index a1cd2462db1b..00ba32f1d664 100644
--- a/lib/eal/freebsd/eal.c
+++ b/lib/eal/freebsd/eal.c
@@ -544,9 +544,7 @@  eal_parse_args(int argc, char **argv)
 				RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n");
 			else {
 				/* free old ops name */
-				if (internal_conf->user_mbuf_pool_ops_name !=
-						NULL)
-					free(internal_conf->user_mbuf_pool_ops_name);
+				free(internal_conf->user_mbuf_pool_ops_name);
 
 				internal_conf->user_mbuf_pool_ops_name =
 						ops_name;
diff --git a/lib/eal/linux/eal.c b/lib/eal/linux/eal.c
index 60b49248388e..f8e39b7e4277 100644
--- a/lib/eal/linux/eal.c
+++ b/lib/eal/linux/eal.c
@@ -730,8 +730,7 @@  eal_parse_args(int argc, char **argv)
 				RTE_LOG(ERR, EAL, "Could not store hugepage directory\n");
 			else {
 				/* free old hugepage dir */
-				if (internal_conf->hugepage_dir != NULL)
-					free(internal_conf->hugepage_dir);
+				free(internal_conf->hugepage_dir);
 				internal_conf->hugepage_dir = hdir;
 			}
 			break;
@@ -743,8 +742,7 @@  eal_parse_args(int argc, char **argv)
 				RTE_LOG(ERR, EAL, "Could not store file prefix\n");
 			else {
 				/* free old prefix */
-				if (internal_conf->hugefile_prefix != NULL)
-					free(internal_conf->hugefile_prefix);
+				free(internal_conf->hugefile_prefix);
 				internal_conf->hugefile_prefix = prefix;
 			}
 			break;
@@ -804,9 +802,7 @@  eal_parse_args(int argc, char **argv)
 				RTE_LOG(ERR, EAL, "Could not store mbuf pool ops name\n");
 			else {
 				/* free old ops name */
-				if (internal_conf->user_mbuf_pool_ops_name !=
-						NULL)
-					free(internal_conf->user_mbuf_pool_ops_name);
+				free(internal_conf->user_mbuf_pool_ops_name);
 
 				internal_conf->user_mbuf_pool_ops_name =
 						ops_name;