From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0A65AA034E; Wed, 9 Feb 2022 20:18:45 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 913D64118A; Wed, 9 Feb 2022 20:18:02 +0100 (CET) Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by mails.dpdk.org (Postfix) with ESMTP id 6673D4117D for ; Wed, 9 Feb 2022 20:18:01 +0100 (CET) Received: by mail-pl1-f174.google.com with SMTP id y18so3051808plb.11 for ; Wed, 09 Feb 2022 11:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SNZRZWczlI4lQxEKBwU52craEXLkZaPQ7UDQ83L8dK0=; b=jUtEQ6O7cFO0B6wrnDGv4r4qftKQhgcJ/UuFiFmRZtyQxUHh9vQGsPAUsSVkTlCGnp UVz8/hldvTZmhP4dR40SOkr5i0muIxL5UR4mLAovTafRVINXYH2JdWB9azV9FhPy1d8k z6B3QiuwHgcFA+w3sz7/jCkOMD94p30EkR/wJThlP1CxQdE5kninTsxuEN1Tf6y9P7t5 e7VMPaSDC5gRD1HDPcEMugESPm5upEixWarUF9W+1wBmykTe21vHosTmjyd8yjHmaZL1 oZja9SsxUNkLMKI4FFphAMcnx70cSdKNOYBKr2jZh5gjSUq/q1WXKfKUkZ/rBSBB6a95 6/wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SNZRZWczlI4lQxEKBwU52craEXLkZaPQ7UDQ83L8dK0=; b=QN8psuljkjlj6gf7VBTrZL9BuWdXHqKRbvkswYjdztKuAG7k/wblNKhri+mEqxLXaB mCO6cclcRp2VWX6C2w9sYXtZCx8J0wBJugG4b/AVnICLTL0Wlpl98y2vlxubwfZZ2tpy Qd7t37T01QWTbeIgcbJGWVOXkEXJVNVr9uImwIyEmIb0XXS/4HdPs4zIZRpeSKqWydZs ZiQ5lc/Oy24KvGw/s72RpigYpuGOdD0zB0kwq0uNLVmU8BVEj7KjTTi/1jvD6mqPqLls 4D9BLDYGd1/rkJa0Tgolk9X30Ss7Srs93XQQZjR6PtvijkDJ2mKKUTKbTa1o0jQXKgMi ZoBA== X-Gm-Message-State: AOAM530GAoV+N0PTcII578jgIjSlQZpbMWODwjmyUQ2Nn5QLC++sRkop EvEFGleDZ3I9MiGD53w7Jjn12F/iXPRilpnJ X-Google-Smtp-Source: ABdhPJx/NwJd82oizyFDTUvAKt0hYci65yvVVJ6qXrsnQfkVw4EHIjx4IbOwbukPeHeYBHG6F9nG+A== X-Received: by 2002:a17:902:9346:: with SMTP id g6mr3604267plp.156.1644434280122; Wed, 09 Feb 2022 11:18:00 -0800 (PST) Received: from hermes.local (204-195-112-199.wavecable.com. [204.195.112.199]) by smtp.gmail.com with ESMTPSA id u16sm14378401pgh.54.2022.02.09.11.17.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 11:17:59 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Reshma Pattan , Declan Doherty , Ciara Power , Xiaoyun Li , Aman Singh , Yuying Zhang , Ori Kam , Olivier Matz , Fan Zhang , Ashish Gupta , Akhil Goyal , Bruce Richardson , Vladimir Medvedkin , Andrew Rybchenko , Honnappa Nagarahalli , Konstantin Ananyev , Anatoly Burakov , Yipeng Wang , Sameh Gobriel , Chas Williams , "Min Hu (Connor)" Subject: [PATCH v3 07/36] app: remove unnecessary NULL checks Date: Wed, 9 Feb 2022 11:17:19 -0800 Message-Id: <20220209191748.377729-8-stephen@networkplumber.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220209191748.377729-1-stephen@networkplumber.org> References: <20220124000518.319850-1-stephen@networkplumber.org> <20220209191748.377729-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Remove redundant NULL pointer checks before free functions found by nullfree.cocci Signed-off-by: Stephen Hemminger --- 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