]> git.droids-corp.org - dpdk.git/commitdiff
remove unneeded tests for NULL when freeing
authorDavid Marchand <david.marchand@6wind.com>
Thu, 21 Jan 2016 11:23:19 +0000 (12:23 +0100)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 27 Jan 2016 14:34:48 +0000 (15:34 +0100)
free() already handles NULL pointer.

Signed-off-by: David Marchand <david.marchand@6wind.com>
14 files changed:
app/test/test_devargs.c
app/test/test_link_bonding.c
app/test/test_pci.c
app/test/test_ring.c
drivers/net/xenvirt/rte_eth_xenvirt.c
drivers/net/xenvirt/rte_mempool_gntalloc.c
examples/ip_pipeline/cpu_core_map.c
examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c
examples/vhost_xen/vhost_monitor.c
examples/vhost_xen/xenstore_parse.c
lib/librte_eal/common/eal_common_devargs.c
lib/librte_eal/linuxapp/eal/eal_memory.c
lib/librte_ether/rte_ethdev.c
lib/librte_kvargs/rte_kvargs.c

index 049f32d43f5ea13a39fd0b297b6167bcef21ff14..e5a9aa0bac7697472c784a1d278d89b7d1b490f0 100644 (file)
@@ -48,8 +48,7 @@ static void free_devargs_list(void)
        while (!TAILQ_EMPTY(&devargs_list)) {
                devargs = TAILQ_FIRST(&devargs_list);
                TAILQ_REMOVE(&devargs_list, devargs, next);
-               if (devargs->args)
-                       free(devargs->args);
+               free(devargs->args);
                free(devargs);
        }
 }
index 2d989586b2e7875c9283b15cb7daffc8e9b2a365..7cbc289140e36f42813a2c09cd65336f53207cc1 100644 (file)
@@ -4023,10 +4023,8 @@ test_close_bonded_device(void)
 static void
 testsuite_teardown(void)
 {
-       if (test_params->pkt_eth_hdr != NULL) {
-               free(test_params->pkt_eth_hdr);
-               test_params->pkt_eth_hdr = NULL;
-       }
+       free(test_params->pkt_eth_hdr);
+       test_params->pkt_eth_hdr = NULL;
 
        /* Clean up and remove slaves from bonded device */
        remove_slaves_and_stop_bonded_device();
index 5530d9974a3c10456192e0ddd94b0be516cb6c0b..0ed357e66ed81c7052121da003d9dfe8722a7a60 100644 (file)
@@ -139,8 +139,7 @@ static void free_devargs_list(void)
        while (!TAILQ_EMPTY(&devargs_list)) {
                devargs = TAILQ_FIRST(&devargs_list);
                TAILQ_REMOVE(&devargs_list, devargs, next);
-               if (devargs->args)
-                       free(devargs->args);
+               free(devargs->args);
                free(devargs);
        }
 }
index e5614de739f9a33ca6d6648ea9973d02c5f779d7..943c350cf078791f11fe98600ca9211262caedae 100644 (file)
@@ -471,17 +471,13 @@ test_ring_basic(void)
        if (ret != 0)
                goto fail;
 
-       if (src)
-               free(src);
-       if (dst)
-               free(dst);
+       free(src);
+       free(dst);
        return 0;
 
  fail:
-       if (src)
-               free(src);
-       if (dst)
-               free(dst);
+       free(src);
+       free(dst);
        return -1;
 }
 
@@ -759,17 +755,13 @@ test_ring_burst_basic(void)
                goto fail;
 
        /* Free memory before test completed */
-       if (src)
-               free(src);
-       if (dst)
-               free(dst);
+       free(src);
+       free(dst);
        return 0;
 
  fail:
-       if (src)
-               free(src);
-       if (dst)
-               free(dst);
+       free(src);
+       free(dst);
        return -1;
 }
 
@@ -1168,17 +1160,13 @@ test_ring_stats(void)
        memset(&r->stats[lcore_id], 0, sizeof(r->stats[lcore_id]));
 
        /* Free memory before test completed */
-       if (src)
-               free(src);
-       if (dst)
-               free(dst);
+       free(src);
+       free(dst);
        return 0;
 
 fail:
-       if (src)
-               free(src);
-       if (dst)
-               free(dst);
+       free(src);
+       free(dst);
        return -1;
 #endif
 }
index 3353bcbab2c2f8ab4a984ac71b280b7feaf4576d..3f318063fe7167bcb901147527c258528514418b 100644 (file)
@@ -431,10 +431,8 @@ gntalloc_vring_create(int queue_type, uint32_t size, int vtidx)
                va = NULL;
        }
 out:
-       if (pa_arr)
-               free(pa_arr);
-       if (gref_arr)
-               free(gref_arr);
+       free(pa_arr);
+       free(gref_arr);
 
        return va;
 }
index 0585f08603e92b0b737807b19f14ca07b4cb3523..7bfbfda3a132dd25aa74785d56dffe34a2dab530 100644 (file)
@@ -229,15 +229,12 @@ mmap_failed:
                        munmap(gnt_arr[i].va, pg_sz);
        }
 out:
-       if (gnt_arr)
-               free(gnt_arr);
+       free(gnt_arr);
        if (orig_va)
                munmap(orig_va, sz);
        if (mp == NULL) {
-               if (gref_arr)
-                       free(gref_arr);
-               if (pa_arr)
-                       free(pa_arr);
+               free(gref_arr);
+               free(pa_arr);
 
                /* some gref has already been de-allocated from the list in the driver,
                 * so dealloc one by one, and it is safe to deallocate twice
index 331b946e47fb1343edb655b6fe88e9c0f9fc305c..2a91f31a15cec07c328b8040762eaec1f5b83a21 100644 (file)
@@ -488,6 +488,5 @@ cpu_core_map_get_lcore_id(struct cpu_core_map *map,
 void
 cpu_core_map_free(struct cpu_core_map *map)
 {
-       if (map)
-               free(map);
+       free(map);
 }
index e808e791b6c37fd93136ac32ec3921b2439ba1ec..ac80fc6467ba5da4b1f0de85f20b43dea575a70d 100644 (file)
@@ -333,10 +333,8 @@ pipeline_fc_parse_args(struct pipeline_flow_classification *p,
        return 0;
 
 error_parse:
-       if (key_mask_str != NULL)
-               free(key_mask_str);
-       if (p->key_mask != NULL)
-               free(p->key_mask);
+       free(key_mask_str);
+       free(p->key_mask);
        return -1;
 }
 
index a891c56771f57769501725f53c323738a4221eb4..7cc5c2fbd2273de75b993a9118f40542134f6495 100644 (file)
@@ -296,8 +296,7 @@ virtio_net_config_ll *new_device(unsigned int virtio_idx, struct xen_guest *gues
        add_config_ll_entry(new_ll_dev);
        return new_ll_dev;
 err:
-       if (new_ll_dev)
-               free(new_ll_dev);
+       free(new_ll_dev);
        rte_free(virtqueue_rx);
        rte_free(virtqueue_tx);
 
index eb629e2d2942fec4bdcb19503907f63fd6380327..26d2432084dac611562c446a7443e963bdb698ff 100644 (file)
@@ -203,8 +203,7 @@ xen_free_gntnode(struct xen_gntnode *gntnode)
 {
        if (gntnode == NULL)
                return;
-       if (gntnode->gnt_info)
-               free(gntnode->gnt_info);
+       free(gntnode->gnt_info);
        free(gntnode);
 }
 
@@ -286,14 +285,10 @@ parse_gntnode(int dom_id, char *path)
        return gntnode;
 
 err:
-       if (gnt)
-               free(gnt);
-       if (gntnode)
-               free(gntnode);
-       if (gref_list)
-               free(gref_list);
-       if (buf)
-               free(buf);
+       free(gnt);
+       free(gntnode);
+       free(gref_list);
+       free(buf);
        return NULL;
 }
 
@@ -412,8 +407,7 @@ parse_mpool_va(struct xen_mempool *mempool)
        }
        ret = 0;
 out:
-       if (buf)
-               free(buf);
+       free(buf);
        return ret;
 }
 
@@ -460,8 +454,7 @@ cleanup_mempool(struct xen_mempool *mempool)
        }
        mempool->pindex = NULL;
 
-       if (mempool->mempfn_tbl)
-               free(mempool->mempfn_tbl);
+       free(mempool->mempfn_tbl);
        mempool->mempfn_tbl = NULL;
 }
 
@@ -559,8 +552,7 @@ xen_map_vringflag(struct xen_vring *vring)
        free(buf);
        return 0;
 err:
-       if (buf)
-               free(buf);
+       free(buf);
        if (vring->flag) {
                munmap(vring->flag, pg_sz);
                vring->flag = NULL;
@@ -622,8 +614,7 @@ cleanup_vring(struct xen_vring *vring)
        }
        vring->rx_pindex = NULL;
 
-       if (vring->rxpfn_tbl)
-               free(vring->rxpfn_tbl);
+       free(vring->rxpfn_tbl);
        vring->rxpfn_tbl = NULL;
 
        if (vring->txvring_addr) {
@@ -644,8 +635,7 @@ cleanup_vring(struct xen_vring *vring)
        }
        vring->tx_pindex = NULL;
 
-       if (vring->txpfn_tbl)
-               free(vring->txpfn_tbl);
+       free(vring->txpfn_tbl);
        vring->txpfn_tbl = NULL;
 
        if (vring->flag) {
@@ -680,8 +670,7 @@ xen_parse_etheraddr(struct xen_vring *vring)
                goto out;
        ret = 0;
 out:
-       if (buf)
-               free(buf);
+       free(buf);
        return ret;
 }
 
index 5d075d043618c8c12dbe7066e54e0485d301b1b4..2bfe54a194c0f1f457ca2f4bab8fab5a84ad360a 100644 (file)
@@ -120,8 +120,7 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str)
        return 0;
 
 fail:
-       if (buf)
-               free(buf);
+       free(buf);
        if (devargs) {
                free(devargs->args);
                free(devargs);
index 48c6175350b989e831ec12361e8f5daee766e34a..6008533b0ddfb1ad66a7bd74134347c8ef2a093b 100644 (file)
@@ -1404,8 +1404,7 @@ rte_eal_hugepage_init(void)
        return 0;
 
 fail:
-       if (tmp_hp)
-               free(tmp_hp);
+       free(tmp_hp);
        return -1;
 }
 
index ed971b49092b7aeac53d75efecb9049fd268cbda..af990e27945c30e0863bb848819f52e40026e883 100644 (file)
@@ -586,10 +586,8 @@ rte_eth_dev_attach_vdev(const char *vdevargs, uint8_t *port_id)
 
        ret = 0;
 end:
-       if (name)
-               free(name);
-       if (args)
-               free(args);
+       free(name);
+       free(args);
 
        if (ret < 0)
                RTE_LOG(ERR, EAL, "Driver, cannot attach the device\n");
index c2dd0513361fac17c56e6f8ffd3c69f4ceb340a2..8d56abd4c8bee40be83c756730693c29ce09b156 100644 (file)
@@ -177,9 +177,7 @@ rte_kvargs_free(struct rte_kvargs *kvlist)
        if (!kvlist)
                return;
 
-       if (kvlist->str != NULL)
-               free(kvlist->str);
-
+       free(kvlist->str);
        free(kvlist);
 }