Functions like free, rte_free, and rte_mempool_free
already handle NULL pointer so the checks here are not necessary.

Signed-off-by: Stephen Hemminger <step...@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 +++-------
 lib/eal/windows/eal_alarm.c           |  3 +--
 lib/eal/windows/eal_memory.c          |  3 +--
 8 files changed, 14 insertions(+), 30 deletions(-)

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 45d393b3937e..ff44d2124bab 100644
--- a/lib/eal/common/eal_common_options.c
+++ b/lib/eal/common/eal_common_options.c
@@ -1989,12 +1989,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 9c8395ab14d0..68fcf86a2e4c 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;
diff --git a/lib/eal/windows/eal_alarm.c b/lib/eal/windows/eal_alarm.c
index 103c1f909da3..51fe752c16d4 100644
--- a/lib/eal/windows/eal_alarm.c
+++ b/lib/eal/windows/eal_alarm.c
@@ -162,8 +162,7 @@ rte_eal_alarm_set(uint64_t us, rte_eal_alarm_callback 
cb_fn, void *cb_arg)
 fail:
        if (timer != NULL)
                CloseHandle(timer);
-       if (ap != NULL)
-               free(ap);
+       free(ap);
 
 exit:
        rte_eal_trace_alarm_set(us, cb_fn, cb_arg, ret);
diff --git a/lib/eal/windows/eal_memory.c b/lib/eal/windows/eal_memory.c
index 2fd37d97085e..215d768e2c57 100644
--- a/lib/eal/windows/eal_memory.c
+++ b/lib/eal/windows/eal_memory.c
@@ -190,8 +190,7 @@ eal_mem_virt2iova_init(void)
        ret = 0;
 
 exit:
-       if (detail != NULL)
-               free(detail);
+       free(detail);
        if (list != INVALID_HANDLE_VALUE)
                SetupDiDestroyDeviceInfoList(list);
 
-- 
2.34.1

Reply via email to