From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f49.google.com (mail-wm0-f49.google.com [74.125.82.49]) by dpdk.org (Postfix) with ESMTP id 0DD5B8E7B for ; Thu, 21 Jan 2016 12:23:40 +0100 (CET) Received: by mail-wm0-f49.google.com with SMTP id l65so215716060wmf.1 for ; Thu, 21 Jan 2016 03:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=KPgzWVR2TEjesZX0JPoK3y+RAnXwgUq7isHaUTz0AjE=; b=we3e6+m01U2eiVZjOEAxenEAaOpRP+IjXx8V4Q86wTCj5zTkUSuSCwFLyhWthz+HpW 46FZepN8AUnsjWyRK59PeEAWJcla/LlZBWteXNVaiTLjj0jdGwvfW1Erv/aS5f3VqII3 tVk9HTyeDnST1agE6Pm4go6YT0Nb3lmu9CatZtWMRomhmpWE2L7q5oUACcYJJdwwcjSN ny/pWvlVqOGLwSjDduFOsJjhNpJPovktEisfjQeS9Lfbvo5YCTiVNlCbKAh7cKDGb1j9 T5LBEzpqNLqv0weGZsIetXbt1U8G3jQLiBCwDwwmFPA3vmgrkejd1zlhjfNts/E5AoMU 7AWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KPgzWVR2TEjesZX0JPoK3y+RAnXwgUq7isHaUTz0AjE=; b=UJE2O0JvPC2gcvKoyTjFD6CpUB5NUBdj734twitKrG+nzCmdjVre2n+xv9j54oms7h 599GvJCIVJiPDu9z/CQhmCAvmZvkOPXvUVTjFRwRoMLlt4RcOkLxWgGqmjkweMB+MEKP H6pqdEbuGCDQlGBsPR/feYynvjGADAn5L2RUbzHDiSe8t/fL4zOe8vXxrz6hODk0AxGt C5yCmd+XmOgLyfF1qazE13rVAMZpiKrUhlUZOJuRuPpklPbz/k9n65hU2GgnIqHTjRwH ZAeEeyLMoRvZ964AcxKx+AarSZnR3sOJo1FaowVjKB1UbYA9bhPiICOXb6c/ITT9OH5I JLTQ== X-Gm-Message-State: ALoCoQmxglnAN+63BhFCwosZ1Dv0GQg1wPpYUHros+fmB+tNFk38ja1RDg8a3D+2oIk5hM8Mv2tOesSuMNdf/EYkzR+h/iusDg== X-Received: by 10.194.82.229 with SMTP id l5mr47117541wjy.140.1453375419736; Thu, 21 Jan 2016 03:23:39 -0800 (PST) Received: from alcyon.dev.6wind.com (guy78-3-82-239-227-177.fbx.proxad.net. [82.239.227.177]) by smtp.gmail.com with ESMTPSA id l7sm1023699wjx.14.2016.01.21.03.23.38 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 21 Jan 2016 03:23:39 -0800 (PST) From: David Marchand To: dev@dpdk.org Date: Thu, 21 Jan 2016 12:23:19 +0100 Message-Id: <1453375399-25576-1-git-send-email-david.marchand@6wind.com> X-Mailer: git-send-email 1.7.10.4 Subject: [dpdk-dev] [PATCH] no need to test for NULL when freeing X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jan 2016 11:23:40 -0000 free() already handles NULL pointer. Signed-off-by: David Marchand --- app/test/test_devargs.c | 3 +- app/test/test_link_bonding.c | 6 ++-- app/test/test_pci.c | 3 +- app/test/test_ring.c | 36 ++++++++-------------- drivers/net/xenvirt/rte_eth_xenvirt.c | 6 ++-- drivers/net/xenvirt/rte_mempool_gntalloc.c | 9 ++---- examples/ip_pipeline/cpu_core_map.c | 3 +- .../pipeline/pipeline_flow_classification_be.c | 6 ++-- examples/vhost_xen/vhost_monitor.c | 3 +- examples/vhost_xen/xenstore_parse.c | 33 +++++++------------- lib/librte_eal/common/eal_common_devargs.c | 3 +- lib/librte_eal/linuxapp/eal/eal_memory.c | 3 +- lib/librte_ether/rte_ethdev.c | 6 ++-- lib/librte_kvargs/rte_kvargs.c | 4 +-- 14 files changed, 41 insertions(+), 83 deletions(-) diff --git a/app/test/test_devargs.c b/app/test/test_devargs.c index 049f32d..e5a9aa0 100644 --- a/app/test/test_devargs.c +++ b/app/test/test_devargs.c @@ -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); } } diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c index 2d98958..7cbc289 100644 --- a/app/test/test_link_bonding.c +++ b/app/test/test_link_bonding.c @@ -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(); diff --git a/app/test/test_pci.c b/app/test/test_pci.c index 5530d99..0ed357e 100644 --- a/app/test/test_pci.c +++ b/app/test/test_pci.c @@ -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); } } diff --git a/app/test/test_ring.c b/app/test/test_ring.c index e5614de..943c350 100644 --- a/app/test/test_ring.c +++ b/app/test/test_ring.c @@ -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 } diff --git a/drivers/net/xenvirt/rte_eth_xenvirt.c b/drivers/net/xenvirt/rte_eth_xenvirt.c index 3353bcb..3f31806 100644 --- a/drivers/net/xenvirt/rte_eth_xenvirt.c +++ b/drivers/net/xenvirt/rte_eth_xenvirt.c @@ -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; } diff --git a/drivers/net/xenvirt/rte_mempool_gntalloc.c b/drivers/net/xenvirt/rte_mempool_gntalloc.c index 0585f08..7bfbfda 100644 --- a/drivers/net/xenvirt/rte_mempool_gntalloc.c +++ b/drivers/net/xenvirt/rte_mempool_gntalloc.c @@ -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 diff --git a/examples/ip_pipeline/cpu_core_map.c b/examples/ip_pipeline/cpu_core_map.c index 331b946..2a91f31 100644 --- a/examples/ip_pipeline/cpu_core_map.c +++ b/examples/ip_pipeline/cpu_core_map.c @@ -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); } diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c b/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c index e808e79..ac80fc6 100644 --- a/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c +++ b/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c @@ -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; } diff --git a/examples/vhost_xen/vhost_monitor.c b/examples/vhost_xen/vhost_monitor.c index a891c56..7cc5c2f 100644 --- a/examples/vhost_xen/vhost_monitor.c +++ b/examples/vhost_xen/vhost_monitor.c @@ -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); diff --git a/examples/vhost_xen/xenstore_parse.c b/examples/vhost_xen/xenstore_parse.c index eb629e2..26d2432 100644 --- a/examples/vhost_xen/xenstore_parse.c +++ b/examples/vhost_xen/xenstore_parse.c @@ -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; } diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 5d075d0..2bfe54a 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -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); diff --git a/lib/librte_eal/linuxapp/eal/eal_memory.c b/lib/librte_eal/linuxapp/eal/eal_memory.c index 846fd31..72568e5 100644 --- a/lib/librte_eal/linuxapp/eal/eal_memory.c +++ b/lib/librte_eal/linuxapp/eal/eal_memory.c @@ -1412,8 +1412,7 @@ rte_eal_hugepage_init(void) return 0; fail: - if (tmp_hp) - free(tmp_hp); + free(tmp_hp); return -1; } diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index ed971b4..af990e2 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -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"); diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index c2dd051..8d56abd 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -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); } -- 1.9.1