more unnecessary null checks
cover more unnecessary null checks
Thomas suggested there are some other functions that could use the nullfree cleanup. And ACL and LPM are both candidates.
Stephen Hemminger (3):
cocci/nullfree: add more functions
acl: remove unncessary null checks in calls to rte_acl_free()
lpm: remove unnecessary NULL checks
app/test/test_acl.c | 12 ++++-------- app/test/test_func_reentrancy.c | 3 +-- devtools/cocci/nullfree.cocci | 9 +++++++++ lib/acl/rte_acl.h | 1 + lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + lib/table/rte_swx_table_wm.c | 3 +-- lib/table/rte_table_acl.c | 15 +++++---------- 8 files changed, 23 insertions(+), 22 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 cocci/nullfree: add more functions
There are more functions in DPDK which have the semantics as free() when passed NULL pointer.
--- devtools/cocci/nullfree.cocci | 9 +++++++++ 1 file changed, 9 insertions(+)
devtools/cocci/nullfree.cocci +9 -0
@@ -10,6 +10,9 @@ expression E; - if (E != NULL) free(E); + free(E); | +- if (E != NULL) rte_acl_free(E); ++ rte_acl_free(E); +| - if (E != NULL) rte_bitmap_free(E); + rte_bitmap_free(E); |
@@ -19,6 +22,12 @@ expression E; - if (E != NULL) rte_hash_free(E); + rte_hash_free(E); | +- if (E != NULL) rte_lpm_free(E); ++ rte_lpm_free(E); +| +- if (E != NULL) rte_lpm6_free(E); ++ rte_lpm6_free(E); +| - if (E != NULL) rte_ring_free(E); + rte_ring_free(E); |
Signature · 1 line
2.34.1
PATCH 2/3 acl: remove unncessary null checks in calls to rte_acl_free()
In reply to Stephen HemmingerThis function already handles NULL as valid input.
--- app/test/test_acl.c | 12 ++++-------- lib/acl/rte_acl.h | 1 + lib/table/rte_swx_table_wm.c | 3 +-- lib/table/rte_table_acl.c | 15 +++++---------- 4 files changed, 11 insertions(+), 20 deletions(-)
app/test/test_acl.c +4 -8
@@ -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; }
lib/acl/rte_acl.h +1 -0
@@ -165,6 +165,7 @@ rte_acl_find_existing(const char *name);* * @param ctx * ACL context to free +* If NULL then, the function does nothing. */ void rte_acl_free (struct rte_acl_ctx *ctx);
lib/table/rte_swx_table_wm.c +1 -2
@@ -375,8 +375,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); }
lib/table/rte_table_acl.c +5 -10
@@ -148,8 +148,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);
@@ -320,8 +319,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];
@@ -400,8 +398,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 ;
@@ -577,8 +574,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++) {
@@ -696,8 +692,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++) {
Signature · 1 line
2.34.1
PATCH 3/3 lpm: remove unnecessary NULL checks
In reply to Stephen HemmingerThe functions rte_lpm_free() and rte_lpm6_free() alread handle NULL pointer case.
--- app/test/test_func_reentrancy.c | 3 +-- lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
app/test/test_func_reentrancy.c +1 -2
@@ -348,8 +348,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);
lib/lpm/rte_lpm.h +1 -0
@@ -183,6 +183,7 @@ rte_lpm_find_existing(const char *name);* * @param lpm * LPM object handle +* If NULL then, the function does nothing. * @return * None */
lib/lpm/rte_lpm6.h +1 -0
@@ -73,6 +73,7 @@ rte_lpm6_find_existing(const char *name);* * @param lpm * LPM object handle +* If NULL then, the function does nothing. * @return * None */
Signature · 1 line
2.34.1
v2 cover fix more unnecessary null checks
In reply to Stephen HemmingerThomas suggested there are some other functions that could use the nullfree cleanup; this covers the rest of the story.
v2 - fix spelling typo and add more functions
Stephen Hemminger (7):
cocci/nullfree: add more functions
acl: remove unnecessary null checks
lpm: remove unnecessary NULL checks
lib: document existing free functions
test: remove unecessary NULL checks before free
fips_validation: remove unnecessary NULL check
event/sw: remove unnecessary NULL check
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 | 30 +++------ app/test/test_cryptodev_blockcipher.c | 3 +- app/test/test_func_reentrancy.c | 6 +- app/test/test_hash.c | 3 +- devtools/cocci/nullfree.cocci | 63 +++++++++++++++++-- drivers/event/sw/sw_evdev.c | 6 +- examples/fips_validation/fips_dev_self_test.c | 3 +- lib/acl/rte_acl.h | 1 + lib/compressdev/rte_comp.h | 1 + lib/cryptodev/rte_crypto.h | 1 + lib/eal/include/rte_interrupts.h | 4 +- lib/efd/rte_efd.h | 1 + lib/eventdev/rte_event_ring.h | 1 + lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + lib/member/rte_member.h | 1 + lib/rib/rte_rib.h | 1 + lib/rib/rte_rib6.h | 1 + lib/stack/rte_stack.h | 1 + lib/table/rte_swx_table_wm.c | 3 +- lib/table/rte_table_acl.c | 15 ++--- lib/telemetry/rte_telemetry.h | 2 +- 25 files changed, 103 insertions(+), 70 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/7 cocci/nullfree: add more functions
There are more functions in DPDK which have the semantics as free() when passed NULL pointer. Also, put the checks in alpha order.
--- devtools/cocci/nullfree.cocci | 63 +++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 6 deletions(-)
devtools/cocci/nullfree.cocci +57 -6
@@ -7,27 +7,78 @@ expression E; @@ ( +- if (E != NULL) cmdline_free(E); ++ cmdline_free(E); +| - if (E != NULL) free(E); + free(E); | +- if (E != NULL) rte_acl_free(E); ++ rte_acl_free(E); +| - if (E != NULL) rte_bitmap_free(E); + rte_bitmap_free(E); | +- if (E != NULL) rte_comp_op_free(E); ++ rte_comp_op_free(E); +| +- if (E != NULL) rte_crypto_op_free(E); ++ rte_crypto_op_free(E); +| +- if (E != NULL) rte_efd_free(E); ++ rte_efd_free(E); +| +- if (E != NULL) rte_event_ring_free(E); ++ rte_event_ring_free(E); +| - if (E != NULL) rte_free(E); + rte_free(E); | +- if (E != NULL) rte_fbk_hash_free(E); ++ rte_fbk_hash_free(E); +| +- if (E != NULL) rte_gpu_mem_free(E); ++ rte_gpu_mem_free(E); +| - if (E != NULL) rte_hash_free(E); + rte_hash_free(E); | -- if (E != NULL) rte_ring_free(E); -+ rte_ring_free(E); +- if (E != NULL) rte_intr_instance_free(E); ++ rte_intr_instance_free(E); | -- if (E != NULL) rte_pktmbuf_free(E); -+ rte_pktmbuf_free(E); +- if (E != NULL) rte_intr_vec_list_free(E); ++ rte_intr_vec_list_free(E); +| +- if (E != NULL) rte_kvargs_free(E); ++ rte_kvargs_free(E); +| +- if (E != NULL) rte_lpm_free(E); ++ rte_lpm_free(E); +| +- if (E != NULL) rte_lpm6_free(E); ++ rte_lpm6_free(E); +| +- if (E != NULL) rte_member_free(E); ++ rte_member_free(E); | - if (E != NULL) rte_mempool_free(E); + rte_mempool_free(E); | -- if (E != NULL) rte_kvargs_free(E); -+ rte_kvargs_free(E); +- if (E != NULL) rte_pktmbuf_free(E); ++ rte_pktmbuf_free(E); +| +- if (E != NULL) rte_rib_free(E); ++ rte_rib_free(E); +| +- if (E != NULL) rte_rib6_free(E); ++ rte_rib6_free(E); +| +- if (E != NULL) rte_ring_free(E); ++ rte_ring_free(E); +| +- if (E != NULL) rte_stack_free(E); ++ rte_stack_free(E); +| +- if (E != NULL) rte_tel_data_free(E); ++ rte_tel_data_free(E); )
Signature · 1 line
2.34.1
PATCH v2 2/7 acl: remove unnecessary null checks
In reply to Stephen HemmingerThis function already handles NULL as valid input.
--- app/test/test_acl.c | 12 ++++-------- lib/acl/rte_acl.h | 1 + lib/table/rte_swx_table_wm.c | 3 +-- lib/table/rte_table_acl.c | 15 +++++---------- 4 files changed, 11 insertions(+), 20 deletions(-)
app/test/test_acl.c +4 -8
@@ -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; }
lib/acl/rte_acl.h +1 -0
@@ -165,6 +165,7 @@ rte_acl_find_existing(const char *name);* * @param ctx * ACL context to free +* If NULL then, the function does nothing. */ void rte_acl_free (struct rte_acl_ctx *ctx);
lib/table/rte_swx_table_wm.c +1 -2
@@ -375,8 +375,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); }
lib/table/rte_table_acl.c +5 -10
@@ -148,8 +148,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);
@@ -320,8 +319,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];
@@ -400,8 +398,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 ;
@@ -577,8 +574,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++) {
@@ -696,8 +692,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++) {
Signature · 1 line
2.34.1
PATCH v2 3/7 lpm: remove unnecessary NULL checks
In reply to Stephen HemmingerThe functions rte_lpm_free() and rte_lpm6_free() already handle NULL pointer case.
--- app/test/test_func_reentrancy.c | 3 +-- lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
app/test/test_func_reentrancy.c +1 -2
@@ -348,8 +348,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);
lib/lpm/rte_lpm.h +1 -0
@@ -183,6 +183,7 @@ rte_lpm_find_existing(const char *name);* * @param lpm * LPM object handle +* If NULL then, the function does nothing. * @return * None */
lib/lpm/rte_lpm6.h +1 -0
@@ -73,6 +73,7 @@ rte_lpm6_find_existing(const char *name);* * @param lpm * LPM object handle +* If NULL then, the function does nothing. * @return * None */
Signature · 1 line
2.34.1
PATCH v2 4/7 lib: document existing free functions
In reply to Stephen HemmingerThese functions all accept NULL as parameter.
--- lib/compressdev/rte_comp.h | 1 + lib/cryptodev/rte_crypto.h | 1 + lib/eal/include/rte_interrupts.h | 4 +++- lib/efd/rte_efd.h | 1 + lib/eventdev/rte_event_ring.h | 1 + lib/member/rte_member.h | 1 + lib/rib/rte_rib.h | 1 + lib/rib/rte_rib6.h | 1 + lib/stack/rte_stack.h | 1 + lib/telemetry/rte_telemetry.h | 2 +- 10 files changed, 12 insertions(+), 2 deletions(-)
lib/compressdev/rte_comp.h +1 -0
@@ -471,6 +471,7 @@ rte_comp_op_bulk_alloc(struct rte_mempool *mempool,* * @param op * Compress operation +* If NULL then, the function does nothing. */ __rte_experimental void
lib/cryptodev/rte_crypto.h +1 -0
@@ -339,6 +339,7 @@ __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size)* be returned to the mempool. * * @param op symmetric crypto operation +* If NULL then, the function does nothing. */ static inline void rte_crypto_op_free (struct rte_crypto_op *op)
lib/eal/include/rte_interrupts.h +3 -1
@@ -243,7 +243,8 @@ rte_intr_instance_alloc(uint32_t flags);* resources. * * @param intr_handle -* Interrupt handle address. +* Interrupt handle address. +* If NULL then, the function does nothing. * */ __rte_experimental
@@ -746,6 +747,7 @@ rte_intr_vec_list_index_get(const struct rte_intr_handle *intr_handle,* * @param intr_handle * pointer to the interrupt handle. +* If NULL then, the function does nothing. * * @return * - On success, zero
lib/efd/rte_efd.h +1 -0
@@ -146,6 +146,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,* * @param table * Table to free +* If NULL then, the function does nothing. */ void rte_efd_free (struct rte_efd_table *table);
lib/eventdev/rte_event_ring.h +1 -0
@@ -233,6 +233,7 @@ rte_event_ring_lookup(const char *name);* * @param r * Ring to free +* If NULL then, the function does nothing. */ void rte_event_ring_free (struct rte_event_ring *r);
lib/member/rte_member.h +1 -0
@@ -444,6 +444,7 @@ rte_member_add(const struct rte_member_setsum *setsum, const void *key,* * @param setsum * Pointer to the set summary. +* If NULL then, the function does nothing. */ void rte_member_free (struct rte_member_setsum *setsum);
lib/rib/rte_rib.h +1 -0
@@ -265,6 +265,7 @@ rte_rib_find_existing(const char *name);* * @param rib * RIB object handle +* If NULL then, the function does nothing. * @return * None */
lib/rib/rte_rib6.h +1 -0
@@ -320,6 +320,7 @@ rte_rib6_find_existing(const char *name);* * @param rib * RIB object handle +* If NULL then, the function does nothing. * @return * None */
lib/stack/rte_stack.h +1 -0
@@ -215,6 +215,7 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,* * @param s * Stack to free +* If NULL then, the function does nothing. */ void rte_stack_free (struct rte_stack *s);
lib/telemetry/rte_telemetry.h +1 -1
@@ -289,7 +289,7 @@ rte_tel_data_alloc(void);* * @param data * Pointer to container. -*. +* If NULL then, the function does nothing. */ void rte_tel_data_free (struct rte_tel_data *data);
Signature · 1 line
2.34.1
PATCH v2 5/7 test: remove unecessary NULL checks before free
In reply to Stephen HemmingerThese are all cases in test code where there is unnecessary NULL check before free caught by coccinelle nullfree script.
--- app/test/test_cmdline_lib.c | 3 +-- app/test/test_cryptodev.c | 9 +++----- app/test/test_cryptodev_asym.c | 30 +++++++++------------------ app/test/test_cryptodev_blockcipher.c | 3 +-- app/test/test_func_reentrancy.c | 3 +-- app/test/test_hash.c | 3 +-- 6 files changed, 17 insertions(+), 34 deletions(-)
app/test/test_cmdline_lib.c +1 -2
@@ -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 ; }
app/test/test_cryptodev.c +3 -6
@@ -1451,8 +1451,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,
@@ -11653,8 +11652,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,
@@ -11797,8 +11795,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,
app/test/test_cryptodev_asym.c +10 -20
@@ -507,8 +507,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,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);
@@ -1114,8 +1113,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; }
@@ -1193,8 +1191,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; }
@@ -1283,8 +1280,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; }
@@ -1370,8 +1366,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; }
@@ -1481,8 +1476,7 @@ test_mod_inv(void)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" );
@@ -1593,8 +1587,7 @@ test_mod_exp(void)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" );
@@ -1758,8 +1751,7 @@ test_dsa_sign(void) 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; }
@@ -1947,8 +1939,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; };
@@ -2109,8 +2100,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; }
app/test/test_cryptodev_blockcipher.c +1 -2
@@ -811,8 +811,7 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,rte_free (auth_xform); } -if (op) -rte_crypto_op_free (op); +rte_crypto_op_free (op);rte_pktmbuf_free (obuf);
app/test/test_func_reentrancy.c +1 -2
@@ -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);
app/test/test_hash.c +1 -2
@@ -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
Signature · 1 line
2.34.1
PATCH v2 6/7 fips_validation: remove unnecessary NULL check
In reply to Stephen HemmingerNo need to check for null pointer here.
--- examples/fips_validation/fips_dev_self_test.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
examples/fips_validation/fips_dev_self_test.c +1 -2
@@ -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);
Signature · 1 line
2.34.1
PATCH v2 7/7 event/sw: remove unnecessary NULL check
In reply to Stephen HemmingerThe rte_event_ring_free() function already handles NULL pointer.
--- drivers/event/sw/sw_evdev.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/event/sw/sw_evdev.c +2 -4
@@ -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,
Signature · 1 line
2.34.1
Quoted 6 lines · Stephen Hemminger
Thomas suggested there are some other functions that could use the nullfree cleanup. And ACL and LPM are both candidates.
Stephen Hemminger (3):
cocci/nullfree: add more functions
Can ./devtools/cocci.sh to integrated to devtools/checkpatches.sh to detect the issues before
the code gets into DPDK?
Quoted 16 lines
acl: remove unncessary null checks in calls to
rte_acl_free()
lpm: remove unnecessary NULL checksapp/test/test_acl.c | 12 ++++-------- app/test/test_func_reentrancy.c | 3 +-- devtools/cocci/nullfree.cocci | 9 +++++++++ lib/acl/rte_acl.h | 1 + lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + lib/table/rte_swx_table_wm.c | 3 +-- lib/table/rte_table_acl.c | 15 +++++---------- 8 files changed, 23 insertions(+), 22 deletions(-)--
2.34.1
v3 cover yet more unnecessary NULL checks
In reply to Stephen HemmingerThomas suggested there are some other functions that could use the nullfree cleanup; this covers the rest of the story.
Note: this does not change existing API/ABI, there are still some outliers that don't use the convention but fixing these will have to wait until next LTS.
v3 - fix another typo and add more functions
v2 - fix spelling typo and add functions
Stephen Hemminger (8):
cocci/nullfree: add more functions
acl: remove unnecessary null checks
lpm: remove unnecessary NULL checks
lib: document existing free functions
test: remove unnecessary NULL checks before free
fips_validation: remove unnecessary NULL check event/sw: remove unnecessary NULL check
pipeline: remove unnecessary checks for NULL pointer before free
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 | 30 ++--- app/test/test_cryptodev_blockcipher.c | 3 +- app/test/test_func_reentrancy.c | 6 +- app/test/test_hash.c | 3 +- devtools/cocci/nullfree.cocci | 108 +++++++++++++++++- drivers/event/sw/sw_evdev.c | 6 +- examples/fips_validation/fips_dev_self_test.c | 3 +- lib/acl/rte_acl.h | 1 + lib/bitratestats/rte_bitrate.h | 1 + lib/compressdev/rte_comp.h | 1 + lib/cryptodev/rte_crypto.h | 1 + lib/eal/include/rte_interrupts.h | 4 +- lib/efd/rte_efd.h | 1 + lib/eventdev/rte_event_ring.h | 1 + lib/fib/rte_fib.h | 1 + lib/fib/rte_fib6.h | 1 + lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + lib/member/rte_member.h | 1 + lib/pipeline/rte_port_in_action.h | 6 +- lib/pipeline/rte_swx_ctl.c | 3 +- lib/pipeline/rte_swx_ctl.h | 1 + lib/pipeline/rte_swx_pipeline.c | 6 +- lib/pipeline/rte_swx_pipeline.h | 1 + lib/reorder/rte_reorder.h | 1 + lib/rib/rte_rib.h | 1 + lib/rib/rte_rib6.h | 1 + lib/sched/rte_sched.h | 1 + lib/stack/rte_stack.h | 1 + lib/table/rte_swx_table_wm.c | 3 +- lib/table/rte_table_acl.c | 15 +-- lib/telemetry/rte_telemetry.h | 2 +- 35 files changed, 162 insertions(+), 78 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/8 cocci/nullfree: add more functions
There are more functions in DPDK which have the semantics as free() when passed NULL pointer. Also, put the checks in alpha order.
--- devtools/cocci/nullfree.cocci | 108 ++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 6 deletions(-)
devtools/cocci/nullfree.cocci +102 -6
@@ -7,27 +7,123 @@ expression E; @@ ( +- if (E != NULL) cmdline_free(E); ++ cmdline_free(E); +| - if (E != NULL) free(E); + free(E); | +- if (E != NULL) rte_acl_free(E); ++ rte_acl_free(E); +| - if (E != NULL) rte_bitmap_free(E); + rte_bitmap_free(E); | +- if (E != NULL) rte_comp_op_free(E); ++ rte_comp_op_free(E); +| +- if (E != NULL) rte_crypto_op_free(E); ++ rte_crypto_op_free(E); +| +- if (E != NULL) rte_efd_free(E); ++ rte_efd_free(E); +| +- if (E != NULL) rte_event_ring_free(E); ++ rte_event_ring_free(E); +| +- if (E != NULL) rte_fib_free(E); ++ rte_fib_free(E); +| +- if (E != NULL) rte_fib6_free(E); ++ rte_fib6_free(E); +| +- if (E != NULL) rte_flow_classifier_free(E); ++ rte_flow_classifier_free(E); +| - if (E != NULL) rte_free(E); + rte_free(E); | +- if (E != NULL) rte_fbk_hash_free(E); ++ rte_fbk_hash_free(E); +| +- if (E != NULL) rte_gpu_mem_free(E); ++ rte_gpu_mem_free(E); +| - if (E != NULL) rte_hash_free(E); + rte_hash_free(E); | -- if (E != NULL) rte_ring_free(E); -+ rte_ring_free(E); +- if (E != NULL) rte_intr_instance_free(E); ++ rte_intr_instance_free(E); | -- if (E != NULL) rte_pktmbuf_free(E); -+ rte_pktmbuf_free(E); +- if (E != NULL) rte_intr_vec_list_free(E); ++ rte_intr_vec_list_free(E); +| +- if (E != NULL) rte_kvargs_free(E); ++ rte_kvargs_free(E); +| +- if (E != NULL) rte_lpm_free(E); ++ rte_lpm_free(E); +| +- if (E != NULL) rte_lpm6_free(E); ++ rte_lpm6_free(E); +| +- if (E != NULL) rte_member_free(E); ++ rte_member_free(E); | - if (E != NULL) rte_mempool_free(E); + rte_mempool_free(E); | -- if (E != NULL) rte_kvargs_free(E); -+ rte_kvargs_free(E); +- if (E != NULL) rte_pktmbuf_free(E); ++ rte_pktmbuf_free(E); +| +- if (E != NULL) rte_rib_free(E); ++ rte_rib_free(E); +| +- if (E != NULL) rte_rib6_free(E); ++ rte_rib6_free(E); +| +- if (E != NULL) rte_reorder_free(E); ++ rte_reorder_free(E); +| +- if (E != NULL) rte_ring_free(E); ++ rte_ring_free(E); +| +- if (E != NULL) rte_port_in_action_free(E); ++ rte_port_in_action_free(E); +| +- if (E != NULL) rte_port_in_action_profile_free(E); ++ rte_port_in_action_profile_free(E); +| +- if (E != NULL) rte_sched_port_free(E); ++ rte_sched_port_free(E); +| +- if (E != NULL) rte_stack_free(E); ++ rte_stack_free(E); +| +- if (E != NULL) rte_stats_bitrate_free(E); ++ rte_stats_bitrate_free(E); +| +- if (E != NULL) rte_swx_ctl_pipeline_free(E); ++ rte_swx_ctl_pipeline_free(E); +| +- if (E != NULL) rte_swx_pipeline_free(E); ++ rte_swx_pipeline_free(E); +| +- if (E != NULL) rte_swx_table_learner_free(E); ++ rte_swx_table_learner_free(E); +| +- if (E != NULL) rte_swx_table_selector_free(E); ++ rte_swx_table_selector_free(E); +| +- if (E != NULL) rte_table_action_free(E); ++ rte_table_action_free(E); +| +- if (E != NULL) rte_table_action_profile_free(E); ++ rte_table_action_profile_free(E); +| +- if (E != NULL) rte_tel_data_free(E); ++ rte_tel_data_free(E); +| +- if (E != NULL) trie_free(E); ++ trie_free(E); )
Signature · 1 line
2.34.1
PATCH v3 2/8 acl: remove unnecessary null checks
In reply to Stephen HemmingerThis function already handles NULL as valid input.
--- app/test/test_acl.c | 12 ++++-------- lib/acl/rte_acl.h | 1 + lib/table/rte_swx_table_wm.c | 3 +-- lib/table/rte_table_acl.c | 15 +++++---------- 4 files changed, 11 insertions(+), 20 deletions(-)
app/test/test_acl.c +4 -8
@@ -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; }
lib/acl/rte_acl.h +1 -0
@@ -165,6 +165,7 @@ rte_acl_find_existing(const char *name);* * @param ctx * ACL context to free +* If NULL then, the function does nothing. */ void rte_acl_free (struct rte_acl_ctx *ctx);
lib/table/rte_swx_table_wm.c +1 -2
@@ -375,8 +375,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); }
lib/table/rte_table_acl.c +5 -10
@@ -148,8 +148,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);
@@ -320,8 +319,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];
@@ -400,8 +398,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 ;
@@ -577,8 +574,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++) {
@@ -696,8 +692,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++) {
Signature · 1 line
2.34.1
PATCH v3 3/8 lpm: remove unnecessary NULL checks
In reply to Stephen HemmingerThe functions rte_lpm_free() and rte_lpm6_free() already handle NULL pointer case.
--- app/test/test_func_reentrancy.c | 3 +-- lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
app/test/test_func_reentrancy.c +1 -2
@@ -348,8 +348,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);
lib/lpm/rte_lpm.h +1 -0
@@ -183,6 +183,7 @@ rte_lpm_find_existing(const char *name);* * @param lpm * LPM object handle +* If NULL then, the function does nothing. * @return * None */
lib/lpm/rte_lpm6.h +1 -0
@@ -73,6 +73,7 @@ rte_lpm6_find_existing(const char *name);* * @param lpm * LPM object handle +* If NULL then, the function does nothing. * @return * None */
Signature · 1 line
2.34.1
RE: [PATCH v3 3/8] lpm: remove unnecessary NULL checks
Quoted 17 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Monday, February 21, 2022 2:22 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Bruce Richardson <[email protected]>; Vladimir Medvedkin <[email protected]>; Yipeng Wang <[email protected]>; Sameh Gobriel <[email protected]>; Anatoly Burakov <[email protected]>; Olivier Matz <[email protected]>; Andrew Rybchenko <[email protected]>; Honnappa Nagarahalli <[email protected]>; Konstantin Ananyev <[email protected]>
Subject: [PATCH v3 3/8] lpm: remove unnecessary NULL checksThe functions
rte_lpm_free()andrte_lpm6_free()already handle NULL pointer case.
Quoted 7 lines
Signed-off-by Stephen Hemminger <[email protected]>--- app/test/test_func_reentrancy.c | 3 +-- lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
Re: [PATCH v3 3/8] lpm: remove unnecessary NULL checks
In reply to Stephen HemmingerQuoted 10 lines · Stephen Hemminger
The functions
rte_lpm_free()andrte_lpm6_free()already handle NULL pointer case.Signed-off-by Stephen Hemminger <[email protected]>--- app/test/test_func_reentrancy.c | 3 +-- lib/lpm/rte_lpm.h | 1 + lib/lpm/rte_lpm6.h | 1 + 3 files changed, 3 insertions(+), 2 deletions(-)
Signature · 2 lines
Regards, Vladimir
PATCH v3 4/8 lib: document existing free functions
In reply to Stephen HemmingerThese functions all accept NULL as parameter.
--- lib/bitratestats/rte_bitrate.h | 1 + lib/compressdev/rte_comp.h | 1 + lib/cryptodev/rte_crypto.h | 1 + lib/eal/include/rte_interrupts.h | 4 +++- lib/efd/rte_efd.h | 1 + lib/eventdev/rte_event_ring.h | 1 + lib/fib/rte_fib.h | 1 + lib/fib/rte_fib6.h | 1 + lib/member/rte_member.h | 1 + lib/reorder/rte_reorder.h | 1 + lib/rib/rte_rib.h | 1 + lib/rib/rte_rib6.h | 1 + lib/sched/rte_sched.h | 1 + lib/stack/rte_stack.h | 1 + lib/telemetry/rte_telemetry.h | 2 +- 15 files changed, 17 insertions(+), 2 deletions(-)
lib/bitratestats/rte_bitrate.h +1 -0
@@ -32,6 +32,7 @@ struct rte_stats_bitrates *rte_stats_bitrate_create(void);* * @param bitrate_data * Pointer allocated by rte_stats_bitrate_create() +* If NULL then, the function does nothing. */ void rte_stats_bitrate_free (struct rte_stats_bitrates *bitrate_data);
lib/compressdev/rte_comp.h +1 -0
@@ -471,6 +471,7 @@ rte_comp_op_bulk_alloc(struct rte_mempool *mempool,* * @param op * Compress operation +* If NULL then, the function does nothing. */ __rte_experimental void
lib/cryptodev/rte_crypto.h +1 -0
@@ -339,6 +339,7 @@ __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size)* be returned to the mempool. * * @param op symmetric crypto operation +* If NULL then, the function does nothing. */ static inline void rte_crypto_op_free (struct rte_crypto_op *op)
lib/eal/include/rte_interrupts.h +3 -1
@@ -243,7 +243,8 @@ rte_intr_instance_alloc(uint32_t flags);* resources. * * @param intr_handle -* Interrupt handle address. +* Interrupt handle address. +* If NULL then, the function does nothing. * */ __rte_experimental
@@ -746,6 +747,7 @@ rte_intr_vec_list_index_get(const struct rte_intr_handle *intr_handle,* * @param intr_handle * pointer to the interrupt handle. +* If NULL then, the function does nothing. * * @return * - On success, zero
lib/efd/rte_efd.h +1 -0
@@ -146,6 +146,7 @@ rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,* * @param table * Table to free +* If NULL then, the function does nothing. */ void rte_efd_free (struct rte_efd_table *table);
lib/eventdev/rte_event_ring.h +1 -0
@@ -233,6 +233,7 @@ rte_event_ring_lookup(const char *name);* * @param r * Ring to free +* If NULL then, the function does nothing. */ void rte_event_ring_free (struct rte_event_ring *r);
lib/fib/rte_fib.h +1 -0
@@ -124,6 +124,7 @@ rte_fib_find_existing(const char *name);* * @param fib * FIB object handle +* If NULL then, the function does nothing. * @return * None */
lib/fib/rte_fib6.h +1 -0
@@ -115,6 +115,7 @@ rte_fib6_find_existing(const char *name);* * @param fib * FIB object handle +* If NULL then, the function does nothing. * @return * None */
lib/member/rte_member.h +1 -0
@@ -444,6 +444,7 @@ rte_member_add(const struct rte_member_setsum *setsum, const void *key,* * @param setsum * Pointer to the set summary. +* If NULL then, the function does nothing. */ void rte_member_free (struct rte_member_setsum *setsum);
lib/reorder/rte_reorder.h +1 -0
@@ -115,6 +115,7 @@ rte_reorder_reset(struct rte_reorder_buffer *b);* * @param b * reorder buffer instance +* If NULL then, the function does nothing. * @return * None */
lib/rib/rte_rib.h +1 -0
@@ -265,6 +265,7 @@ rte_rib_find_existing(const char *name);* * @param rib * RIB object handle +* If NULL then, the function does nothing. * @return * None */
lib/rib/rte_rib6.h +1 -0
@@ -320,6 +320,7 @@ rte_rib6_find_existing(const char *name);* * @param rib * RIB object handle +* If NULL then, the function does nothing. * @return * None */
lib/sched/rte_sched.h +1 -0
@@ -330,6 +330,7 @@ rte_sched_port_config(struct rte_sched_port_params *params);* * @param port * Handle to port scheduler instance +* If NULL then, the function does nothing. */ void rte_sched_port_free (struct rte_sched_port *port);
lib/stack/rte_stack.h +1 -0
@@ -215,6 +215,7 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,* * @param s * Stack to free +* If NULL then, the function does nothing. */ void rte_stack_free (struct rte_stack *s);
lib/telemetry/rte_telemetry.h +1 -1
@@ -289,7 +289,7 @@ rte_tel_data_alloc(void);* * @param data * Pointer to container. -*. +* If NULL then, the function does nothing. */ void rte_tel_data_free (struct rte_tel_data *data);
Signature · 1 line
2.34.1
Re: [PATCH v3 4/8] lib: document existing free functions
20/02/2022 19:21, Stephen Hemminger:
Quoted 1 line
+ * If NULL then, the function does nothing.
I'm not English native, but I thought it should be one of these 2 forms:
- If NULL, the function does nothing.
- If NULL then the function does nothing.
Re: [PATCH v3 4/8] lib: document existing free functions
Quoted 7 lines · Thomas Monjalon
20/02/2022 19:21, Stephen Hemminger:
Quoted 1 line
+ * If NULL then, the function does nothing.
I'm not English native, but I thought it should be one of these 2 forms:
- If NULL, the function does nothing.
- If NULL then the function does nothing.
I would agree, and also would tend toward the first version.
/Bruce
Re: [PATCH v3 4/8] lib: document existing free functions
Quoted 11 lines · On Mon, 28 Feb 2022 09:42:47 +0000 Bruce Richardson…
Quoted 7 lines · Thomas Monjalon
20/02/2022 19:21, Stephen Hemminger:
Quoted 1 line
+ * If NULL then, the function does nothing.
I'm not English native, but I thought it should be one of these 2 forms:
- If NULL, the function does nothing.
- If NULL then the function does nothing.I would agree, and also would tend toward the first version.
/Bruce
Either one. I was just copy/pasting pre-existing grammar problem.
Re: [PATCH v3 4/8] lib: document existing free functions
28/02/2022 18:08, Stephen Hemminger:
Quoted 11 lines
Quoted 8 lines · On Mon, 28 Feb 2022 09:42:47 +0000 Bruce Richardson…
Quoted 7 lines · Thomas Monjalon
20/02/2022 19:21, Stephen Hemminger:
Quoted 1 line
+ * If NULL then, the function does nothing.
I'm not English native, but I thought it should be one of these 2 forms:
- If NULL, the function does nothing.
- If NULL then the function does nothing.
Quoted 5 lines
Quoted 3 lines
I would agree, and also would tend toward the first version.
/Bruce
Either one. I was just copy/pasting pre-existing grammar problem.
Please do you want to respin?
Re: [PATCH v3 4/8] lib: document existing free functions
Quoted 12 lines · On Wed, 22 Jun 2022 11:23:04 +0200 Thomas Monjalon <[email protected]> wrote:
28/02/2022 18:08, Stephen Hemminger:
Quoted 11 lines
Quoted 8 lines · On Mon, 28 Feb 2022 09:42:47 +0000 Bruce Richardson…
Quoted 7 lines · Thomas Monjalon
20/02/2022 19:21, Stephen Hemminger:
Quoted 1 line
+ * If NULL then, the function does nothing.
I'm not English native, but I thought it should be one of these 2 forms:
- If NULL, the function does nothing.
- If NULL then the function does nothing.
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
I would agree, and also would tend toward the first version.
/Bruce
Either one. I was just copy/pasting pre-existing grammar problem.
Please do you want to respin?
Sure.
PATCH v3 5/8 test: remove unnecessary NULL checks before free
In reply to Stephen HemmingerThese are all cases in test code where there is unnecessary NULL check before free caught by coccinelle nullfree script.
--- app/test/test_cmdline_lib.c | 3 +-- app/test/test_cryptodev.c | 9 +++----- app/test/test_cryptodev_asym.c | 30 +++++++++------------------ app/test/test_cryptodev_blockcipher.c | 3 +-- app/test/test_func_reentrancy.c | 3 +-- app/test/test_hash.c | 3 +-- 6 files changed, 17 insertions(+), 34 deletions(-)
app/test/test_cmdline_lib.c +1 -2
@@ -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 ; }
app/test/test_cryptodev.c +3 -6
@@ -1451,8 +1451,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,
@@ -11653,8 +11652,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,
@@ -11797,8 +11795,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,
app/test/test_cryptodev_asym.c +10 -20
@@ -507,8 +507,7 @@ test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,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);
@@ -1114,8 +1113,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; }
@@ -1193,8 +1191,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; }
@@ -1283,8 +1280,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; }
@@ -1370,8 +1366,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; }
@@ -1481,8 +1476,7 @@ test_mod_inv(void)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" );
@@ -1593,8 +1587,7 @@ test_mod_exp(void)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" );
@@ -1758,8 +1751,7 @@ test_dsa_sign(void) 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; }
@@ -1947,8 +1939,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; };
@@ -2109,8 +2100,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; }
app/test/test_cryptodev_blockcipher.c +1 -2
@@ -811,8 +811,7 @@ test_blockcipher_one_case(const struct blockcipher_test_case *t,rte_free (auth_xform); } -if (op) -rte_crypto_op_free (op); +rte_crypto_op_free (op);rte_pktmbuf_free (obuf);
app/test/test_func_reentrancy.c +1 -2
@@ -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);
app/test/test_hash.c +1 -2
@@ -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
Signature · 1 line
2.34.1
PATCH v3 6/8 fips_validation: remove unnecessary NULL check
In reply to Stephen HemmingerNo need to check for null pointer here.
--- examples/fips_validation/fips_dev_self_test.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
examples/fips_validation/fips_dev_self_test.c +1 -2
@@ -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);
Signature · 1 line
2.34.1
PATCH v3 7/8 event/sw: remove unnecessary NULL check
In reply to Stephen HemmingerThe XXX_free() functions already handle NULL pointer.
--- drivers/event/sw/sw_evdev.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/event/sw/sw_evdev.c +2 -4
@@ -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,
Signature · 1 line
2.34.1
PATCH v3 8/8 pipeline: remove unnecessary checks for NULL pointer before free
In reply to Stephen HemmingerThis library (mostly) uses convention that allows caller to pass NULL.
--- lib/pipeline/rte_port_in_action.h | 6 ++++-- lib/pipeline/rte_swx_ctl.c | 3 +-- lib/pipeline/rte_swx_ctl.h | 1 + lib/pipeline/rte_swx_pipeline.c | 6 ++---- lib/pipeline/rte_swx_pipeline.h | 1 + 5 files changed, 9 insertions(+), 8 deletions(-)
lib/pipeline/rte_port_in_action.h +4 -2
@@ -181,8 +181,9 @@ rte_port_in_action_profile_create(uint32_t socket_id);* * @param[in] profile * Input port action profile handle (needs to be valid). +* If NULL then, the function does nothing. * @return -* Zero on success, non-zero error code otherwise. +* always zero. */ __rte_experimental int
@@ -259,8 +260,9 @@ rte_port_in_action_create(struct rte_port_in_action_profile *profile,* * @param[in] action * Handle to input port action object (needs to be valid). +* If NULL then, the function does nothing. * @return -* Zero on success, non-zero error code otherwise. +* Always zero. */ __rte_experimental int
lib/pipeline/rte_swx_ctl.c +1 -2
@@ -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. */
lib/pipeline/rte_swx_ctl.h +1 -0
@@ -1285,6 +1285,7 @@ rte_swx_ctl_meter_stats_read(struct rte_swx_pipeline *p,* * @param[in] ctl * Pipeline control handle. +* If NULL then, the function does nothing. */ __rte_experimental void
lib/pipeline/rte_swx_pipeline.c +2 -4
@@ -8672,16 +8672,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);
lib/pipeline/rte_swx_pipeline.h +1 -0
@@ -912,6 +912,7 @@ rte_swx_pipeline_flush(struct rte_swx_pipeline *p);* * @param[in] p * Pipeline handle. +* If NULL then, the function does nothing. */ __rte_experimental void
Signature · 1 line
2.34.1
PATCH v4 1/1 lib: document existing free functions
In reply to Stephen HemmingerMake sure all functions which use the convention that XXX_free(NULL) is a nop are all documented.
The wording is chosen to match the documentation of free(3). "If ptr is NULL, no operation is performed."
--- lib/bitratestats/rte_bitrate.h | 1 + lib/compressdev/rte_comp.h | 3 ++- lib/cryptodev/rte_crypto.h | 4 +++- lib/eal/include/rte_interrupts.h | 3 ++- lib/efd/rte_efd.h | 3 ++- lib/eventdev/rte_event_ring.h | 3 ++- lib/fib/rte_fib.h | 3 ++- lib/fib/rte_fib6.h | 3 ++- lib/member/rte_member.h | 1 + lib/reorder/rte_reorder.h | 3 ++- lib/rib/rte_rib.h | 3 ++- lib/rib/rte_rib6.h | 3 ++- lib/sched/rte_sched.h | 3 ++- lib/stack/rte_stack.h | 3 ++- lib/telemetry/rte_telemetry.h | 2 +- 15 files changed, 28 insertions(+), 13 deletions(-)
lib/bitratestats/rte_bitrate.h +1 -0
@@ -32,6 +32,7 @@ struct rte_stats_bitrates *rte_stats_bitrate_create(void);* * @param bitrate_data * Pointer allocated by rte_stats_bitrate_create() +* If pointer is NULL, no operation is performed. */ void rte_stats_bitrate_free (struct rte_stats_bitrates *bitrate_data);
lib/compressdev/rte_comp.h +2 -1
@@ -469,7 +469,8 @@ rte_comp_op_bulk_alloc(struct rte_mempool *mempool,* be returned to the mempool. * * @param op -* Compress operation +* Compress operation pointer allocated from rte_comp_op_alloc() +* If pointer is NULL, no operation is performed. */ __rte_experimental void
lib/cryptodev/rte_crypto.h +3 -1
@@ -347,7 +347,9 @@ __rte_crypto_op_get_priv_data(struct rte_crypto_op *op, uint32_t size)* If operation has been allocate from a rte_mempool, then the operation will * be returned to the mempool. * -* @param op symmetric crypto operation +* @param op +* Pointer to symmetric crypto operation allocated with rte_crypto_op_alloc() +* If pointer is NULL, no operation is performed. */ static inline void rte_crypto_op_free (struct rte_crypto_op *op)
lib/eal/include/rte_interrupts.h +2 -1
@@ -242,7 +242,8 @@ rte_intr_instance_alloc(uint32_t flags);* Free the memory allocated for interrupt handle resources. * * @param intr_handle -* Interrupt handle address. +* Interrupt handle allocated with rte_intr_instance_alloc(). +* If handle is NULL, no operation is performed. * */ __rte_experimental
lib/efd/rte_efd.h +2 -1
@@ -145,7 +145,8 @@ rte_efd_create(const char *name, uint32_t max_num_rules, uint32_t key_len,* Releases the resources from an EFD table * * @param table -* Table to free +* Pointer to table allocated with rte_efd_create(). +* If pointer is NULL, no operation is performed. */ void rte_efd_free (struct rte_efd_table *table);
lib/eventdev/rte_event_ring.h +2 -1
@@ -234,7 +234,8 @@ rte_event_ring_lookup(const char *name);* De-allocate all memory used by the ring. * * @param r -* Ring to free +* Pointer to ring to created with rte_event_ring_create(). +* If pointer is NULL, no operation is performed. */ void rte_event_ring_free (struct rte_event_ring *r);
lib/fib/rte_fib.h +2 -1
@@ -122,7 +122,8 @@ rte_fib_find_existing(const char *name);* Free an FIB object. * * @param fib -* FIB object handle +* FIB object handle created by rte_fib_create(). +* If handle is NULL, no operation is performed. * @return * None */
lib/fib/rte_fib6.h +2 -1
@@ -113,7 +113,8 @@ rte_fib6_find_existing(const char *name);* Free an FIB object. * * @param fib -* FIB object handle +* FIB object handle created by rte_fib6_create(). +* If handle is NULL, no operation is performed. * @return * None */
lib/member/rte_member.h +1 -0
@@ -443,6 +443,7 @@ rte_member_add(const struct rte_member_setsum *setsum, const void *key,* * @param setsum * Pointer to the set summary. +* If pointer is NULL, no operation is performed. */ void rte_member_free (struct rte_member_setsum *setsum);
lib/reorder/rte_reorder.h +2 -1
@@ -114,7 +114,8 @@ rte_reorder_reset(struct rte_reorder_buffer *b);* Free reorder buffer instance. * * @param b -* reorder buffer instance +* Pointer to reorder buffer instance. +* If pointer is NULL, no operation is performed. * @return * None */
lib/rib/rte_rib.h +2 -1
@@ -263,7 +263,8 @@ rte_rib_find_existing(const char *name);* Free an RIB object. * * @param rib -* RIB object handle +* RIB object handle created with rte_rib_create(). +* If handle is NULL, no operation is performed. * @return * None */
lib/rib/rte_rib6.h +2 -1
@@ -318,7 +318,8 @@ rte_rib6_find_existing(const char *name);* Free an RIB object. * * @param rib -* RIB object handle +* RIB object handle created with rte_rib6_create(). +* If handle is NULL, no operation is performed. * @return * None */
lib/sched/rte_sched.h +2 -1
@@ -328,7 +328,8 @@ rte_sched_port_config(struct rte_sched_port_params *params);* Hierarchical scheduler port free * * @param port -* Handle to port scheduler instance +* Handle to port scheduler instance. +* If handle is NULL, no operation is performed. */ void rte_sched_port_free (struct rte_sched_port *port);
lib/stack/rte_stack.h +2 -1
@@ -213,7 +213,8 @@ rte_stack_create(const char *name, unsigned int count, int socket_id,* Free all memory used by the stack. * * @param s -* Stack to free +* Pointer to stack created with rte_stack_create(). +* If pointer is NULL, no operation is performed. */ void rte_stack_free (struct rte_stack *s);
lib/telemetry/rte_telemetry.h +1 -1
@@ -293,7 +293,7 @@ rte_tel_data_alloc(void);* * @param data * Pointer to container. -*. +* If pointer is NULL, no operation is performed. */ void rte_tel_data_free (struct rte_tel_data *data);
Signature · 1 line
2.35.1
Re: [PATCH v4] lib: document existing free functions
Quoted 5 lines · Stephen Hemminger
Make sure all functions which use the convention that
XXX_free(NULL)is a nop are all documented.The wording is chosen to match the documentation of free(3). "If ptr is NULL, no operation is performed."
It's a good idea to add such explicit description.
Quoted 20 lines
Signed-off-by Stephen Hemminger <[email protected]>--- lib/bitratestats/rte_bitrate.h | 1 + lib/compressdev/rte_comp.h | 3 ++- lib/cryptodev/rte_crypto.h | 4 +++- lib/eal/include/rte_interrupts.h | 3 ++- lib/efd/rte_efd.h | 3 ++- lib/eventdev/rte_event_ring.h | 3 ++- lib/fib/rte_fib.h | 3 ++- lib/fib/rte_fib6.h | 3 ++- lib/member/rte_member.h | 1 + lib/reorder/rte_reorder.h | 3 ++- lib/rib/rte_rib.h | 3 ++- lib/rib/rte_rib6.h | 3 ++- lib/sched/rte_sched.h | 3 ++- lib/stack/rte_stack.h | 3 ++- lib/telemetry/rte_telemetry.h | 2 +- 15 files changed, 28 insertions(+), 13 deletions(-)
...
Re: [PATCH v4] lib: document existing free functions
In reply to Stephen HemmingerQuoted 8 lines · Stephen Hemminger
Make sure all functions which use the convention that
XXX_free(NULL)is a nop are all documented.The wording is chosen to match the documentation of free(3). "If ptr is NULL, no operation is performed."
Signed-off-by Stephen Hemminger <[email protected]>
Squashed similar updates for acl, lpm and pipeline API that were in
https://patchwork.dpdk.org/project/dpdk/list/?series=21752&state=*
series, and applied.
Thanks.
Signature · 1 line
David Marchand
Re: [PATCH v3 0/8] yet more unnecessary NULL checks
In reply to Stephen HemmingerQuoted 12 lines · Stephen Hemminger
Thomas suggested there are some other functions that could use the nullfree cleanup; this covers the rest of the story.
Note: this does not change existing API/ABI, there are still some outliers that don't use the convention but fixing these will have to wait until next LTS.
v3 - fix another typo and add more functions
v2 - fix spelling typo and add functions
Quoted 9 lines
Stephen Hemminger (8):
cocci/nullfree: add more functions
acl: remove unnecessary null checks
lpm: remove unnecessary NULL checks
lib: document existing free functions
test: remove unnecessary NULL checks before free
fips_validation: remove unnecessary NULL check event/sw: remove unnecessary NULL check
pipeline: remove unnecessary checks for NULL pointer before free
Series applied.
I reran the script and fixed two more instances.
Thanks for the cleanup Stephen.
Signature · 1 line
David Marchand