From 64e14b8b072ae694ef35a3392639223ecf862820 Mon Sep 17 00:00:00 2001 From: Stephen Hemminger Date: Sun, 20 Feb 2022 10:21:41 -0800 Subject: [PATCH] remove unnecessary null checks Found by nullfree.cocci. Signed-off-by: Stephen Hemminger [David: for lpm parts:] Reviewed-by: Ruifeng Wang Acked-by: Vladimir Medvedkin [David: for vdpa/mlx5 parts:] Acked-by: Matan Azrad [David: for dma/dpaa2, raw/ifpga, vdpa/mlx5:] Acked-by: Tyler Retzlaff Reviewed-by: Chengwen Feng [David: reran cocci.sh and updated common/mlx5 and cryptodev asym test] Signed-off-by: David Marchand --- app/test/test_acl.c | 12 +++---- app/test/test_cmdline_lib.c | 3 +- app/test/test_cryptodev.c | 9 ++--- app/test/test_cryptodev_asym.c | 33 +++++++------------ app/test/test_cryptodev_blockcipher.c | 3 +- app/test/test_func_reentrancy.c | 6 ++-- app/test/test_hash.c | 3 +- drivers/common/mlx5/linux/mlx5_common_os.c | 3 +- drivers/dma/dpaa2/dpaa2_qdma.c | 6 ++-- drivers/event/sw/sw_evdev.c | 6 ++-- drivers/raw/ifpga/ifpga_rawdev.c | 3 +- drivers/vdpa/mlx5/mlx5_vdpa_virtq.c | 3 +- examples/fips_validation/fips_dev_self_test.c | 3 +- lib/pipeline/rte_swx_ctl.c | 3 +- lib/pipeline/rte_swx_pipeline.c | 6 ++-- lib/table/rte_swx_table_wm.c | 3 +- lib/table/rte_table_acl.c | 15 +++------ 17 files changed, 40 insertions(+), 80 deletions(-) diff --git a/app/test/test_acl.c b/app/test/test_acl.c index 4d51098925..623f34682e 100644 --- a/app/test/test_acl.c +++ b/app/test/test_acl.c @@ -1171,8 +1171,7 @@ test_create_find_add(void) printf("Line %i: Creating context with existing name " "test failed!\n", __LINE__); - if (tmp) - rte_acl_free(tmp); + rte_acl_free(tmp); goto err; } @@ -1182,8 +1181,7 @@ test_create_find_add(void) printf("Line %i: Creating context with existing " "name test 2 failed!\n", __LINE__); - if (tmp) - rte_acl_free(tmp); + rte_acl_free(tmp); goto err; } @@ -1191,16 +1189,14 @@ test_create_find_add(void) tmp = rte_acl_find_existing(acx_name); if (tmp != acx) { printf("Line %i: Finding %s failed!\n", __LINE__, acx_name); - if (tmp) - rte_acl_free(tmp); + rte_acl_free(tmp); goto err; } tmp = rte_acl_find_existing(acx2_name); if (tmp != acx2) { printf("Line %i: Finding %s failed!\n", __LINE__, acx2_name); - if (tmp) - rte_acl_free(tmp); + rte_acl_free(tmp); goto err; } diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c index fcd58cb76a..87c1059366 100644 --- a/app/test/test_cmdline_lib.c +++ b/app/test/test_cmdline_lib.c @@ -229,8 +229,7 @@ test_cmdline_fns(void) error: printf("Error: function accepted null parameter!\n"); - if (cl != NULL) - cmdline_free(cl); + cmdline_free(cl); return -1; } diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 1cac76a64a..e6d8bcfb02 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -1450,8 +1450,7 @@ ut_teardown(void) } /* free crypto operation structure */ - if (ut_params->op) - rte_crypto_op_free(ut_params->op); + rte_crypto_op_free(ut_params->op); /* * free mbuf - both obuf and ibuf are usually the same, @@ -12097,8 +12096,7 @@ test_multi_session(void) aes_cbc_iv), "Failed to perform decrypt on request number %u.", i); /* free crypto operation structure */ - if (ut_params->op) - rte_crypto_op_free(ut_params->op); + rte_crypto_op_free(ut_params->op); /* * free mbuf - both obuf and ibuf are usually the same, @@ -12241,8 +12239,7 @@ test_multi_session_random_usage(void) ut_paramz[j].iv), "Failed to perform decrypt on request number %u.", i); - if (ut_paramz[j].ut_params.op) - rte_crypto_op_free(ut_paramz[j].ut_params.op); + rte_crypto_op_free(ut_paramz[j].ut_params.op); /* * free mbuf - both obuf and ibuf are usually the same, diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c index e4b3c211df..fc1a727472 100644 --- a/app/test/test_cryptodev_asym.c +++ b/app/test/test_cryptodev_asym.c @@ -505,8 +505,7 @@ error_exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); rte_free(result); @@ -1115,8 +1114,7 @@ test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm) error_exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); return status; } @@ -1194,8 +1192,7 @@ test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm) error_exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); return status; } @@ -1284,8 +1281,7 @@ test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm) error_exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); return status; } @@ -1371,8 +1367,7 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm) error_exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); return status; } @@ -1482,8 +1477,7 @@ error_exit: if (sess) rte_cryptodev_asym_session_free(dev_id, sess); - if (op) - rte_crypto_op_free(op); + rte_crypto_op_free(op); TEST_ASSERT_EQUAL(status, 0, "Test failed"); @@ -1594,8 +1588,7 @@ error_exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); TEST_ASSERT_EQUAL(status, 0, "Test failed"); @@ -1718,8 +1711,7 @@ test_dsa_sign(struct rte_crypto_dsa_op_param *dsa_op) error_exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); return status; } @@ -1809,8 +1801,7 @@ test_dsa_verify(struct rte_crypto_dsa_op_param *dsa_op) error_exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); return status; } @@ -2012,8 +2003,7 @@ test_ecdsa_sign_verify(enum curve curve_id) exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); return status; }; @@ -2174,8 +2164,7 @@ test_ecpm(enum curve curve_id) exit: if (sess != NULL) rte_cryptodev_asym_session_free(dev_id, sess); - if (op != NULL) - rte_crypto_op_free(op); + rte_crypto_op_free(op); return status; } diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c index 127e2a53d3..b5813b956f 100644 --- a/app/test/test_cryptodev_blockcipher.c +++ b/app/test/test_cryptodev_blockcipher.c @@ -809,8 +809,7 @@ error_exit: rte_free(auth_xform); } - if (op) - rte_crypto_op_free(op); + rte_crypto_op_free(op); rte_pktmbuf_free(obuf); diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c index da00694daa..d1ed5d4abc 100644 --- a/app/test/test_func_reentrancy.c +++ b/app/test/test_func_reentrancy.c @@ -278,8 +278,7 @@ fbk_clean(unsigned lcore_id) int i; handle = rte_fbk_hash_find_existing("fr_test_once"); - if (handle != NULL) - rte_fbk_hash_free(handle); + rte_fbk_hash_free(handle); for (i = 0; i < MAX_ITER_MULTI; i++) { snprintf(fbk_name, sizeof(fbk_name), "fr_test_%d_%d", lcore_id, i); @@ -348,8 +347,7 @@ lpm_clean(unsigned int lcore_id) int i; lpm = rte_lpm_find_existing("fr_test_once"); - if (lpm != NULL) - rte_lpm_free(lpm); + rte_lpm_free(lpm); for (i = 0; i < MAX_LPM_ITER_TIMES; i++) { snprintf(lpm_name, sizeof(lpm_name), "fr_test_%d_%d", lcore_id, i); diff --git a/app/test/test_hash.c b/app/test/test_hash.c index d522cb7f8c..3e45afaa67 100644 --- a/app/test/test_hash.c +++ b/app/test/test_hash.c @@ -1159,8 +1159,7 @@ fbk_hash_unit_test(void) RETURN_IF_ERROR_FBK(handle == NULL, "fbk hash creation should have succeeded"); tmp = rte_fbk_hash_create(&invalid_params_same_name_2); - if (tmp != NULL) - rte_fbk_hash_free(tmp); + rte_fbk_hash_free(tmp); RETURN_IF_ERROR_FBK(tmp != NULL, "fbk hash creation should have failed"); /* we are not freeing handle here because we need a hash list diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c index f10a981a37..c57e1918d2 100644 --- a/drivers/common/mlx5/linux/mlx5_common_os.c +++ b/drivers/common/mlx5/linux/mlx5_common_os.c @@ -1018,8 +1018,7 @@ mlx5_os_interrupt_handler_create(int mode, bool set_fd_nonblock, int fd, } return tmp_intr_handle; err: - if (tmp_intr_handle) - rte_intr_instance_free(tmp_intr_handle); + rte_intr_instance_free(tmp_intr_handle); return NULL; } diff --git a/drivers/dma/dpaa2/dpaa2_qdma.c b/drivers/dma/dpaa2/dpaa2_qdma.c index a93a60565d..0500e8c225 100644 --- a/drivers/dma/dpaa2/dpaa2_qdma.c +++ b/drivers/dma/dpaa2/dpaa2_qdma.c @@ -1404,11 +1404,9 @@ dpaa2_qdma_reset(struct rte_dma_dev *dev) /* Reset and free virtual queues */ for (i = 0; i < qdma_dev->num_vqs; i++) { - if (qdma_dev->vqs[i].status_ring) - rte_ring_free(qdma_dev->vqs[i].status_ring); + rte_ring_free(qdma_dev->vqs[i].status_ring); } - if (qdma_dev->vqs) - rte_free(qdma_dev->vqs); + rte_free(qdma_dev->vqs); qdma_dev->vqs = NULL; /* Reset QDMA device structure */ diff --git a/drivers/event/sw/sw_evdev.c b/drivers/event/sw/sw_evdev.c index ba82a80385..f93313b31b 100644 --- a/drivers/event/sw/sw_evdev.c +++ b/drivers/event/sw/sw_evdev.c @@ -166,8 +166,7 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id, snprintf(buf, sizeof(buf), "sw%d_p%u_%s", dev->data->dev_id, port_id, "rx_worker_ring"); struct rte_event_ring *existing_ring = rte_event_ring_lookup(buf); - if (existing_ring) - rte_event_ring_free(existing_ring); + rte_event_ring_free(existing_ring); p->rx_worker_ring = rte_event_ring_create(buf, MAX_SW_PROD_Q_DEPTH, dev->data->socket_id, @@ -186,8 +185,7 @@ sw_port_setup(struct rte_eventdev *dev, uint8_t port_id, snprintf(buf, sizeof(buf), "sw%d_p%u, %s", dev->data->dev_id, port_id, "cq_worker_ring"); existing_ring = rte_event_ring_lookup(buf); - if (existing_ring) - rte_event_ring_free(existing_ring); + rte_event_ring_free(existing_ring); p->cq_worker_ring = rte_event_ring_create(buf, conf->dequeue_depth, dev->data->socket_id, diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c index ceb18aed8d..8c05302a65 100644 --- a/drivers/raw/ifpga/ifpga_rawdev.c +++ b/drivers/raw/ifpga/ifpga_rawdev.c @@ -1768,8 +1768,7 @@ ifpga_vdev_parse_devargs(struct rte_devargs *devargs, ret = 0; end: - if (kvlist) - rte_kvargs_free(kvlist); + rte_kvargs_free(kvlist); return ret; } diff --git a/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c b/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c index 06a5c26947..ed17fb5add 100644 --- a/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c +++ b/drivers/vdpa/mlx5/mlx5_vdpa_virtq.c @@ -364,8 +364,7 @@ mlx5_vdpa_virtq_sub_objs_prepare(struct mlx5_vdpa_priv *priv, if (virtq->umems[i].obj) claim_zero(mlx5_glue->devx_umem_dereg (virtq->umems[i].obj)); - if (virtq->umems[i].buf) - rte_free(virtq->umems[i].buf); + rte_free(virtq->umems[i].buf); virtq->umems[i].size = 0; virtq->umems[i].obj = NULL; virtq->umems[i].buf = NULL; diff --git a/examples/fips_validation/fips_dev_self_test.c b/examples/fips_validation/fips_dev_self_test.c index 076e9de099..19af134bbe 100644 --- a/examples/fips_validation/fips_dev_self_test.c +++ b/examples/fips_validation/fips_dev_self_test.c @@ -1523,8 +1523,7 @@ fips_dev_auto_test_uninit(uint8_t dev_id, struct fips_dev_auto_test_env *env) { rte_pktmbuf_free(env->mbuf); - if (env->op) - rte_crypto_op_free(env->op); + rte_crypto_op_free(env->op); rte_mempool_free(env->mpool); rte_mempool_free(env->op_pool); rte_mempool_free(env->sess_pool); diff --git a/lib/pipeline/rte_swx_ctl.c b/lib/pipeline/rte_swx_ctl.c index f52ccffd75..710e89a46a 100644 --- a/lib/pipeline/rte_swx_ctl.c +++ b/lib/pipeline/rte_swx_ctl.c @@ -1046,8 +1046,7 @@ table_state_free(struct rte_swx_ctl_pipeline *ctl) struct rte_swx_table_state *ts = &ctl->ts_next[selector_base_index + i]; /* Table object. */ - if (ts->obj) - rte_swx_table_selector_free(ts->obj); + rte_swx_table_selector_free(ts->obj); } /* For each learner table, free its table state. */ diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c index 50805ba821..732a064a60 100644 --- a/lib/pipeline/rte_swx_pipeline.c +++ b/lib/pipeline/rte_swx_pipeline.c @@ -9250,16 +9250,14 @@ table_state_build_free(struct rte_swx_pipeline *p) struct rte_swx_table_state *ts = &p->table_state[p->n_tables + i]; /* ts->obj. */ - if (ts->obj) - rte_swx_table_selector_free(ts->obj); + rte_swx_table_selector_free(ts->obj); } for (i = 0; i < p->n_learners; i++) { struct rte_swx_table_state *ts = &p->table_state[p->n_tables + p->n_selectors + i]; /* ts->obj. */ - if (ts->obj) - rte_swx_table_learner_free(ts->obj); + rte_swx_table_learner_free(ts->obj); /* ts->default_action_data. */ free(ts->default_action_data); diff --git a/lib/table/rte_swx_table_wm.c b/lib/table/rte_swx_table_wm.c index 27a67b47bd..ce2a78f94c 100644 --- a/lib/table/rte_swx_table_wm.c +++ b/lib/table/rte_swx_table_wm.c @@ -373,8 +373,7 @@ table_free(void *table) if (!t) return; - if (t->acl_ctx) - rte_acl_free(t->acl_ctx); + rte_acl_free(t->acl_ctx); env_free(t, t->total_size); } diff --git a/lib/table/rte_table_acl.c b/lib/table/rte_table_acl.c index 179a1da835..53fd5c66ad 100644 --- a/lib/table/rte_table_acl.c +++ b/lib/table/rte_table_acl.c @@ -145,8 +145,7 @@ rte_table_acl_free(void *table) } /* Free previously allocated resources */ - if (acl->ctx != NULL) - rte_acl_free(acl->ctx); + rte_acl_free(acl->ctx); rte_free(acl); @@ -317,8 +316,7 @@ rte_table_acl_entry_add( } /* Commit changes */ - if (acl->ctx != NULL) - rte_acl_free(acl->ctx); + rte_acl_free(acl->ctx); acl->ctx = ctx; *key_found = 0; *entry_ptr = &acl->memory[free_pos * acl->entry_size]; @@ -397,8 +395,7 @@ rte_table_acl_entry_delete( } /* Commit changes */ - if (acl->ctx != NULL) - rte_acl_free(acl->ctx); + rte_acl_free(acl->ctx); acl->ctx = ctx; *key_found = 1; @@ -574,8 +571,7 @@ rte_table_acl_entry_add_bulk( } /* Commit changes */ - if (acl->ctx != NULL) - rte_acl_free(acl->ctx); + rte_acl_free(acl->ctx); acl->ctx = ctx; for (i = 0; i < n_keys; i++) { @@ -693,8 +689,7 @@ rte_table_acl_entry_delete_bulk( } /* Commit changes */ - if (acl->ctx != NULL) - rte_acl_free(acl->ctx); + rte_acl_free(acl->ctx); acl->ctx = ctx; for (i = 0; i < n_keys; i++) { -- 2.39.5