Remove redundant NULL pointer checks before free functions found by nullfree.cocci
Signed-off-by: Stephen Hemminger <step...@networkplumber.org> --- app/pdump/main.c | 9 ++-- app/test-crypto-perf/cperf_test_latency.c | 3 +- .../cperf_test_pmd_cyclecount.c | 9 ++-- app/test-crypto-perf/cperf_test_throughput.c | 3 +- .../cperf_test_vector_parsing.c | 6 +-- app/test-crypto-perf/cperf_test_verify.c | 3 +- app/test-pmd/cmd_flex_item.c | 3 +- app/test-pmd/cmdline.c | 3 +- app/test-pmd/testpmd.c | 3 +- app/test-regex/main.c | 12 ++--- app/test/test_cksum.c | 3 +- app/test/test_compressdev.c | 3 +- app/test/test_cryptodev.h | 3 +- app/test/test_cryptodev_asym.c | 3 +- app/test/test_cryptodev_blockcipher.c | 12 ++--- app/test/test_func_reentrancy.c | 15 +++---- app/test/test_hash.c | 15 +++---- app/test/test_hash_perf.c | 7 +-- app/test/test_link_bonding.c | 9 ++-- app/test/test_link_bonding_mode4.c | 3 +- app/test/test_malloc.c | 5 +-- app/test/test_mbuf.c | 45 +++++++------------ app/test/test_pcapng.c | 3 +- app/test/test_reorder.c | 15 +++---- app/test/virtual_pmd.c | 3 +- 25 files changed, 65 insertions(+), 133 deletions(-) diff --git a/app/pdump/main.c b/app/pdump/main.c index 46f9d25db004..04a38e891119 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -502,14 +502,11 @@ cleanup_rings(void) for (i = 0; i < num_tuples; i++) { pt = &pdump_t[i]; - if (pt->device_id) - free(pt->device_id); + free(pt->device_id); /* free the rings */ - if (pt->rx_ring) - rte_ring_free(pt->rx_ring); - if (pt->tx_ring) - rte_ring_free(pt->tx_ring); + rte_ring_free(pt->rx_ring); + rte_ring_free(pt->tx_ring); } } diff --git a/app/test-crypto-perf/cperf_test_latency.c b/app/test-crypto-perf/cperf_test_latency.c index ce49feaba9f3..4c7bc72eb5fd 100644 --- a/app/test-crypto-perf/cperf_test_latency.c +++ b/app/test-crypto-perf/cperf_test_latency.c @@ -49,8 +49,7 @@ cperf_latency_test_free(struct cperf_latency_ctx *ctx) rte_cryptodev_sym_session_free(ctx->sess); } - if (ctx->pool) - rte_mempool_free(ctx->pool); + rte_mempool_free(ctx->pool); rte_free(ctx->res); rte_free(ctx); diff --git a/app/test-crypto-perf/cperf_test_pmd_cyclecount.c b/app/test-crypto-perf/cperf_test_pmd_cyclecount.c index 5842f29d43e2..6b4d09e623eb 100644 --- a/app/test-crypto-perf/cperf_test_pmd_cyclecount.c +++ b/app/test-crypto-perf/cperf_test_pmd_cyclecount.c @@ -79,14 +79,11 @@ cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx) } } - if (ctx->pool) - rte_mempool_free(ctx->pool); + rte_mempool_free(ctx->pool); - if (ctx->ops) - rte_free(ctx->ops); + rte_free(ctx->ops); - if (ctx->ops_processed) - rte_free(ctx->ops_processed); + rte_free(ctx->ops_processed); rte_free(ctx); } diff --git a/app/test-crypto-perf/cperf_test_throughput.c b/app/test-crypto-perf/cperf_test_throughput.c index 51512af2ad81..51fad5a05505 100644 --- a/app/test-crypto-perf/cperf_test_throughput.c +++ b/app/test-crypto-perf/cperf_test_throughput.c @@ -57,8 +57,7 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx) rte_cryptodev_sym_session_free(ctx->sess); } } - if (ctx->pool) - rte_mempool_free(ctx->pool); + rte_mempool_free(ctx->pool); rte_free(ctx); } diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c index 1e9dfcfff087..87f3a90055aa 100644 --- a/app/test-crypto-perf/cperf_test_vector_parsing.c +++ b/app/test-crypto-perf/cperf_test_vector_parsing.c @@ -551,10 +551,8 @@ parse_file(struct cperf_test_vector *vector, struct cperf_options *opts) err: if (fp) fclose(fp); - if (line) - free(line); - if (entry) - rte_free(entry); + free(line); + rte_free(entry); return -1; } diff --git a/app/test-crypto-perf/cperf_test_verify.c b/app/test-crypto-perf/cperf_test_verify.c index 496eb0de00f0..c031330afcfe 100644 --- a/app/test-crypto-perf/cperf_test_verify.c +++ b/app/test-crypto-perf/cperf_test_verify.c @@ -42,8 +42,7 @@ cperf_verify_test_free(struct cperf_verify_ctx *ctx) rte_cryptodev_sym_session_free(ctx->sess); } - if (ctx->pool) - rte_mempool_free(ctx->pool); + rte_mempool_free(ctx->pool); rte_free(ctx); } diff --git a/app/test-pmd/cmd_flex_item.c b/app/test-pmd/cmd_flex_item.c index 908bcb3f47f8..9050825a81d7 100644 --- a/app/test-pmd/cmd_flex_item.c +++ b/app/test-pmd/cmd_flex_item.c @@ -364,8 +364,7 @@ flex_item_create(portid_t port_id, uint16_t flex_id, const char *filename) flow_error.message ? flow_error.message : ""); } out: - if (fp) - free(fp); + free(fp); } #else /* RTE_HAS_JANSSON */ diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index e626b1c7d9ee..298a594e709b 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -14696,8 +14696,7 @@ cmd_ddp_info_parsed( ret = 0; no_print_return: - if (proto) - free(proto); + free(proto); #endif if (ret == -ENOTSUP) fprintf(stderr, "Function not supported in PMD\n"); diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index e1da961311f8..6d2e52c7905f 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -908,8 +908,7 @@ create_extmem(uint32_t nb_mbufs, uint32_t mbuf_sz, struct extmem_param *param, return 0; fail: - if (iovas) - free(iovas); + free(iovas); if (addr) munmap(addr, mem_sz); diff --git a/app/test-regex/main.c b/app/test-regex/main.c index 8e665df73ce0..ab8a3e56e774 100644 --- a/app/test-regex/main.c +++ b/app/test-regex/main.c @@ -210,8 +210,7 @@ read_file(char *file, char **buf) printf("Error, can't open file %s\n, err = %d", file, res); if (fp) fclose(fp); - if (*buf) - rte_free(*buf); + rte_free(*buf); return -res; } @@ -299,8 +298,7 @@ init_port(uint16_t *nb_max_payload, char *rules_file, uint8_t *nb_max_matches, rte_free(rules); return 0; error: - if (rules) - rte_free(rules); + rte_free(rules); return res; } @@ -367,8 +365,7 @@ regex_create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len, return mbuf; fail: - if (mbuf) - rte_pktmbuf_free(mbuf); + rte_pktmbuf_free(mbuf); return NULL; } @@ -612,8 +609,7 @@ run_regex(void *args) rte_free(qp->buf); qp->buf = NULL; } - if (mbuf_mp) - rte_mempool_free(mbuf_mp); + rte_mempool_free(mbuf_mp); rte_free(qps); return res; } diff --git a/app/test/test_cksum.c b/app/test/test_cksum.c index cd983d7c01ce..6c15de9a9312 100644 --- a/app/test/test_cksum.c +++ b/app/test/test_cksum.c @@ -218,8 +218,7 @@ test_l4_cksum(struct rte_mempool *pktmbuf_pool, const char *pktdata, size_t len) return 0; fail: - if (m) - rte_pktmbuf_free(m); + rte_pktmbuf_free(m); return -1; } diff --git a/app/test/test_compressdev.c b/app/test/test_compressdev.c index 57c566aa9229..fbecaf9aaad4 100644 --- a/app/test/test_compressdev.c +++ b/app/test/test_compressdev.c @@ -2144,8 +2144,7 @@ test_deflate_comp_decomp(const struct interim_data_params *int_data, if (stream != NULL) rte_compressdev_stream_free(0, stream); - if (all_decomp_data != NULL) - rte_free(all_decomp_data); + rte_free(all_decomp_data); /* Free compress private xforms */ for (i = 0; i < test_priv_data.num_priv_xforms; i++) { diff --git a/app/test/test_cryptodev.h b/app/test/test_cryptodev.h index 70f23a3f67d0..29a7d4db2b10 100644 --- a/app/test/test_cryptodev.h +++ b/app/test/test_cryptodev.h @@ -230,8 +230,7 @@ create_segmented_mbuf(struct rte_mempool *mbuf_pool, int pkt_len, return mbuf; fail: - if (mbuf) - rte_pktmbuf_free(mbuf); + rte_pktmbuf_free(mbuf); return NULL; } diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c index 9d3a5589bb9c..3dadedf733e9 100644 --- a/app/test/test_cryptodev_asym.c +++ b/app/test/test_cryptodev_asym.c @@ -520,8 +520,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params, if (op != NULL) rte_crypto_op_free(op); - if (result != NULL) - rte_free(result); + rte_free(result); return status; } diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c index 0c6f3ff42d4b..494459195c49 100644 --- a/app/test/test_cryptodev_blockcipher.c +++ b/app/test/test_cryptodev_blockcipher.c @@ -807,20 +807,16 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t, rte_cryptodev_sym_session_clear(dev_id, sess); rte_cryptodev_sym_session_free(sess); } - if (cipher_xform) - rte_free(cipher_xform); - if (auth_xform) - rte_free(auth_xform); + rte_free(cipher_xform); + rte_free(auth_xform); } if (op) rte_crypto_op_free(op); - if (obuf) - rte_pktmbuf_free(obuf); + rte_pktmbuf_free(obuf); - if (ibuf) - rte_pktmbuf_free(ibuf); + rte_pktmbuf_free(ibuf); return status; } diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c index 4ab4167eb031..da00694daafd 100644 --- a/app/test/test_func_reentrancy.c +++ b/app/test/test_func_reentrancy.c @@ -89,15 +89,13 @@ ring_clean(unsigned int lcore_id) int i; rp = rte_ring_lookup("fr_test_once"); - if (rp != NULL) - rte_ring_free(rp); + rte_ring_free(rp); for (i = 0; i < MAX_ITER_MULTI; i++) { snprintf(ring_name, sizeof(ring_name), "fr_test_%d_%d", lcore_id, i); rp = rte_ring_lookup(ring_name); - if (rp != NULL) - rte_ring_free(rp); + rte_ring_free(rp); } } @@ -152,15 +150,13 @@ mempool_clean(unsigned int lcore_id) int i; mp = rte_mempool_lookup("fr_test_once"); - if (mp != NULL) - rte_mempool_free(mp); + rte_mempool_free(mp); for (i = 0; i < MAX_ITER_MULTI; i++) { snprintf(mempool_name, sizeof(mempool_name), "fr_test_%d_%d", lcore_id, i); mp = rte_mempool_lookup(mempool_name); - if (mp != NULL) - rte_mempool_free(mp); + rte_mempool_free(mp); } } @@ -215,8 +211,7 @@ hash_clean(unsigned lcore_id) int i; handle = rte_hash_find_existing("fr_test_once"); - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); for (i = 0; i < MAX_ITER_MULTI; i++) { snprintf(hash_name, sizeof(hash_name), "fr_test_%d_%d", lcore_id, i); diff --git a/app/test/test_hash.c b/app/test/test_hash.c index b99e8de1db71..d522cb7f8cbf 100644 --- a/app/test/test_hash.c +++ b/app/test/test_hash.c @@ -1654,8 +1654,7 @@ test_hash_add_delete_jhash2(void) ret = 0; fail_jhash2: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1689,8 +1688,7 @@ test_hash_add_delete_2_jhash2(void) ret = 0; fail_2_jhash2: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1754,8 +1752,7 @@ test_hash_add_delete_jhash_1word(void) ret = 0; fail_jhash_1word: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1789,8 +1786,7 @@ test_hash_add_delete_jhash_2word(void) ret = 0; fail_jhash_2word: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } @@ -1824,8 +1820,7 @@ test_hash_add_delete_jhash_3word(void) ret = 0; fail_jhash_3word: - if (handle != NULL) - rte_hash_free(handle); + rte_hash_free(handle); return ret; } diff --git a/app/test/test_hash_perf.c b/app/test/test_hash_perf.c index 104a70b3974e..5d36c0f4543d 100644 --- a/app/test/test_hash_perf.c +++ b/app/test/test_hash_perf.c @@ -106,12 +106,7 @@ create_table(unsigned int with_data, unsigned int table_index, ut_params.key_len = hashtest_key_lens[table_index]; ut_params.socket_id = rte_socket_id(); h[table_index] = rte_hash_find_existing(name); - if (h[table_index] != NULL) - /* - * If table was already created, free it to create it again, - * so we force it is empty - */ - rte_hash_free(h[table_index]); + rte_hash_free(h[table_index]); h[table_index] = rte_hash_create(&ut_params); if (h[table_index] == NULL) { printf("Error creating table\n"); diff --git a/app/test/test_link_bonding.c b/app/test/test_link_bonding.c index dc6fc46b9c93..82a9b8e01a82 100644 --- a/app/test/test_link_bonding.c +++ b/app/test/test_link_bonding.c @@ -1639,8 +1639,7 @@ test_roundrobin_rx_burst_on_single_slave(void) /* free mbufs */ for (i = 0; i < MAX_PKT_BURST; i++) { - if (rx_pkt_burst[i] != NULL) - rte_pktmbuf_free(rx_pkt_burst[i]); + rte_pktmbuf_free(rx_pkt_burst[i]); } @@ -1722,8 +1721,7 @@ test_roundrobin_rx_burst_on_multiple_slaves(void) /* free mbufs */ for (i = 0; i < MAX_PKT_BURST; i++) { - if (rx_pkt_burst[i] != NULL) - rte_pktmbuf_free(rx_pkt_burst[i]); + rte_pktmbuf_free(rx_pkt_burst[i]); } /* Clean up and remove slaves from bonded device */ @@ -2010,8 +2008,7 @@ test_roundrobin_verify_slave_link_status_change_behaviour(void) /* free mbufs */ for (i = 0; i < MAX_PKT_BURST; i++) { - if (rx_pkt_burst[i] != NULL) - rte_pktmbuf_free(rx_pkt_burst[i]); + rte_pktmbuf_free(rx_pkt_burst[i]); } /* Clean up and remove slaves from bonded device */ diff --git a/app/test/test_link_bonding_mode4.c b/app/test/test_link_bonding_mode4.c index 351129de2f9b..d9b9c323c7f8 100644 --- a/app/test/test_link_bonding_mode4.c +++ b/app/test/test_link_bonding_mode4.c @@ -194,8 +194,7 @@ free_pkts(struct rte_mbuf **pkts, uint16_t count) uint16_t i; for (i = 0; i < count; i++) { - if (pkts[i] != NULL) - rte_pktmbuf_free(pkts[i]); + rte_pktmbuf_free(pkts[i]); } } diff --git a/app/test/test_malloc.c b/app/test/test_malloc.c index 8db500c514e7..de40e506113a 100644 --- a/app/test/test_malloc.c +++ b/app/test/test_malloc.c @@ -823,7 +823,7 @@ test_zero_aligned_alloc(void) err_return: /*clean up */ - if (p1) rte_free(p1); + rte_free(p1); return -1; } @@ -876,8 +876,7 @@ test_malloc_bad_params(void) err_return: /* clean up pointer */ - if (bad_ptr) - rte_free(bad_ptr); + rte_free(bad_ptr); return -1; } diff --git a/app/test/test_mbuf.c b/app/test/test_mbuf.c index f762befb6954..cf0577308f4d 100644 --- a/app/test/test_mbuf.c +++ b/app/test/test_mbuf.c @@ -304,8 +304,7 @@ test_one_pktmbuf(struct rte_mempool *pktmbuf_pool) return 0; fail: - if (m) - rte_pktmbuf_free(m); + rte_pktmbuf_free(m); return -1; } @@ -416,12 +415,9 @@ testclone_testupdate_testdetach(struct rte_mempool *pktmbuf_pool, return 0; fail: - if (m) - rte_pktmbuf_free(m); - if (clone) - rte_pktmbuf_free(clone); - if (clone2) - rte_pktmbuf_free(clone2); + rte_pktmbuf_free(m); + rte_pktmbuf_free(clone); + rte_pktmbuf_free(clone2); return -1; } @@ -572,12 +568,9 @@ test_pktmbuf_copy(struct rte_mempool *pktmbuf_pool, return 0; fail: - if (m) - rte_pktmbuf_free(m); - if (copy) - rte_pktmbuf_free(copy); - if (copy2) - rte_pktmbuf_free(copy2); + rte_pktmbuf_free(m); + rte_pktmbuf_free(copy); + rte_pktmbuf_free(copy2); return -1; } @@ -679,12 +672,9 @@ test_attach_from_different_pool(struct rte_mempool *pktmbuf_pool, return 0; fail: - if (m) - rte_pktmbuf_free(m); - if (clone) - rte_pktmbuf_free(clone); - if (clone2) - rte_pktmbuf_free(clone2); + rte_pktmbuf_free(m); + rte_pktmbuf_free(clone); + rte_pktmbuf_free(clone2); return -1; } @@ -722,8 +712,7 @@ test_pktmbuf_pool(struct rte_mempool *pktmbuf_pool) } /* free them */ for (i=0; i<NB_MBUF; i++) { - if (m[i] != NULL) - rte_pktmbuf_free(m[i]); + rte_pktmbuf_free(m[i]); } return ret; @@ -924,8 +913,7 @@ test_pktmbuf_pool_ptr(struct rte_mempool *pktmbuf_pool) /* free them */ for (i=0; i<NB_MBUF; i++) { - if (m[i] != NULL) - rte_pktmbuf_free(m[i]); + rte_pktmbuf_free(m[i]); } for (i=0; i<NB_MBUF; i++) @@ -947,8 +935,7 @@ test_pktmbuf_pool_ptr(struct rte_mempool *pktmbuf_pool) /* free them */ for (i=0; i<NB_MBUF; i++) { - if (m[i] != NULL) - rte_pktmbuf_free(m[i]); + rte_pktmbuf_free(m[i]); } return ret; @@ -1366,8 +1353,7 @@ test_mbuf_linearize(struct rte_mempool *pktmbuf_pool, int pkt_len, return 0; fail: - if (mbuf) - rte_pktmbuf_free(mbuf); + rte_pktmbuf_free(mbuf); return -1; } @@ -2783,8 +2769,7 @@ test_nb_segs_and_next_reset(void) return 0; fail: - if (pool != NULL) - rte_mempool_free(pool); + rte_mempool_free(pool); return -1; } diff --git a/app/test/test_pcapng.c b/app/test/test_pcapng.c index 34c5e1234695..320dacea3498 100644 --- a/app/test/test_pcapng.c +++ b/app/test/test_pcapng.c @@ -240,8 +240,7 @@ test_validate(void) static void test_cleanup(void) { - if (mp) - rte_mempool_free(mp); + rte_mempool_free(mp); if (pcapng) rte_pcapng_close(pcapng); diff --git a/app/test/test_reorder.c b/app/test/test_reorder.c index 07dcce06d293..f0714a5c18a3 100644 --- a/app/test/test_reorder.c +++ b/app/test/test_reorder.c @@ -218,8 +218,7 @@ test_reorder_insert(void) exit: rte_reorder_free(b); for (i = 0; i < num_bufs; i++) { - if (bufs[i] != NULL) - rte_pktmbuf_free(bufs[i]); + rte_pktmbuf_free(bufs[i]); } return ret; } @@ -278,8 +277,7 @@ test_reorder_drain(void) ret = -1; goto exit; } - if (robufs[0] != NULL) - rte_pktmbuf_free(robufs[0]); + rte_pktmbuf_free(robufs[0]); /* Insert more packets * RB[] = {NULL, NULL, NULL, NULL} @@ -313,8 +311,7 @@ test_reorder_drain(void) goto exit; } for (i = 0; i < 3; i++) { - if (robufs[i] != NULL) - rte_pktmbuf_free(robufs[i]); + rte_pktmbuf_free(robufs[i]); } /* @@ -332,10 +329,8 @@ test_reorder_drain(void) exit: rte_reorder_free(b); for (i = 0; i < num_bufs; i++) { - if (bufs[i] != NULL) - rte_pktmbuf_free(bufs[i]); - if (robufs[i] != NULL) - rte_pktmbuf_free(robufs[i]); + rte_pktmbuf_free(bufs[i]); + rte_pktmbuf_free(robufs[i]); } return ret; } diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c index 3d2793852049..cd4611ab48df 100644 --- a/app/test/virtual_pmd.c +++ b/app/test/virtual_pmd.c @@ -397,8 +397,7 @@ virtual_ethdev_tx_burst_fail(void *queue, struct rte_mbuf **bufs, /* free packets in burst */ for (i = 0; i < successfully_txd; i++) { /* free packets in burst */ - if (bufs[i] != NULL) - rte_pktmbuf_free(bufs[i]); + rte_pktmbuf_free(bufs[i]); bufs[i] = NULL; } -- 2.34.1