* [PATCH v3 1/8] cocci/nullfree: add more functions
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
@ 2022-02-20 18:21 ` Stephen Hemminger
2022-02-20 18:21 ` [PATCH v3 2/8] acl: remove unnecessary null checks Stephen Hemminger
` (8 subsequent siblings)
9 siblings, 0 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-20 18:21 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
There are more functions in DPDK which have the semantics
as free() when passed NULL pointer. Also, put the checks
in alpha order.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
devtools/cocci/nullfree.cocci | 108 ++++++++++++++++++++++++++++++++--
1 file changed, 102 insertions(+), 6 deletions(-)
diff --git a/devtools/cocci/nullfree.cocci b/devtools/cocci/nullfree.cocci
index 363b6149ac28..9ca3fc286497 100644
--- a/devtools/cocci/nullfree.cocci
+++ b/devtools/cocci/nullfree.cocci
@@ -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);
)
--
2.34.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3 2/8] acl: remove unnecessary null checks
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
2022-02-20 18:21 ` [PATCH v3 1/8] cocci/nullfree: add more functions Stephen Hemminger
@ 2022-02-20 18:21 ` Stephen Hemminger
2022-02-20 18:21 ` [PATCH v3 3/8] lpm: remove unnecessary NULL checks Stephen Hemminger
` (7 subsequent siblings)
9 siblings, 0 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-20 18:21 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev, Cristian Dumitrescu
This function already handles NULL as valid input.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
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(-)
diff --git a/app/test/test_acl.c b/app/test/test_acl.c
index 4d51098925c4..623f34682e69 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/lib/acl/rte_acl.h b/lib/acl/rte_acl.h
index f7f5f0870122..c33a688433b1 100644
--- a/lib/acl/rte_acl.h
+++ b/lib/acl/rte_acl.h
@@ -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);
diff --git a/lib/table/rte_swx_table_wm.c b/lib/table/rte_swx_table_wm.c
index e260be106221..c9d42a855249 100644
--- a/lib/table/rte_swx_table_wm.c
+++ b/lib/table/rte_swx_table_wm.c
@@ -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);
}
diff --git a/lib/table/rte_table_acl.c b/lib/table/rte_table_acl.c
index 14d54019f0bb..d15f03448796 100644
--- a/lib/table/rte_table_acl.c
+++ b/lib/table/rte_table_acl.c
@@ -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++) {
--
2.34.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3 3/8] lpm: remove unnecessary NULL checks
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
2022-02-20 18:21 ` [PATCH v3 1/8] cocci/nullfree: add more functions Stephen Hemminger
2022-02-20 18:21 ` [PATCH v3 2/8] acl: remove unnecessary null checks Stephen Hemminger
@ 2022-02-20 18:21 ` Stephen Hemminger
2022-02-21 2:47 ` Ruifeng Wang
2022-02-21 15:51 ` Medvedkin, Vladimir
2022-02-20 18:21 ` [PATCH v3 4/8] lib: document existing free functions Stephen Hemminger
` (6 subsequent siblings)
9 siblings, 2 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-20 18:21 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, Bruce Richardson, Vladimir Medvedkin,
Yipeng Wang, Sameh Gobriel, Anatoly Burakov, Olivier Matz,
Andrew Rybchenko, Honnappa Nagarahalli, Konstantin Ananyev
The functions rte_lpm_free() and rte_lpm6_free() already
handle NULL pointer case.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
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(-)
diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c
index da00694daafd..67e69ad53588 100644
--- a/app/test/test_func_reentrancy.c
+++ b/app/test/test_func_reentrancy.c
@@ -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);
diff --git a/lib/lpm/rte_lpm.h b/lib/lpm/rte_lpm.h
index 5eb14c1748e5..a50bf3339fee 100644
--- a/lib/lpm/rte_lpm.h
+++ b/lib/lpm/rte_lpm.h
@@ -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
*/
diff --git a/lib/lpm/rte_lpm6.h b/lib/lpm/rte_lpm6.h
index f96f3372e593..145fd4495a94 100644
--- a/lib/lpm/rte_lpm6.h
+++ b/lib/lpm/rte_lpm6.h
@@ -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
*/
--
2.34.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* RE: [PATCH v3 3/8] lpm: remove unnecessary NULL checks
2022-02-20 18:21 ` [PATCH v3 3/8] lpm: remove unnecessary NULL checks Stephen Hemminger
@ 2022-02-21 2:47 ` Ruifeng Wang
2022-02-21 15:51 ` Medvedkin, Vladimir
1 sibling, 0 replies; 33+ messages in thread
From: Ruifeng Wang @ 2022-02-21 2:47 UTC (permalink / raw)
To: Stephen Hemminger, dev
Cc: Bruce Richardson, Vladimir Medvedkin, Yipeng Wang, Sameh Gobriel,
Anatoly Burakov, Olivier Matz, Andrew Rybchenko,
Honnappa Nagarahalli, Konstantin Ananyev, nd
> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Monday, February 21, 2022 2:22 AM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Bruce
> Richardson <bruce.richardson@intel.com>; Vladimir Medvedkin
> <vladimir.medvedkin@intel.com>; Yipeng Wang <yipeng1.wang@intel.com>;
> Sameh Gobriel <sameh.gobriel@intel.com>; Anatoly Burakov
> <anatoly.burakov@intel.com>; Olivier Matz <olivier.matz@6wind.com>;
> Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>; Honnappa
> Nagarahalli <Honnappa.Nagarahalli@arm.com>; Konstantin Ananyev
> <konstantin.ananyev@intel.com>
> Subject: [PATCH v3 3/8] lpm: remove unnecessary NULL checks
>
> The functions rte_lpm_free() and rte_lpm6_free() already handle NULL
> pointer case.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> 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(-)
>
Reviewed-by: Ruifeng Wang <ruifeng.wang@arm.com>
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v3 3/8] lpm: remove unnecessary NULL checks
2022-02-20 18:21 ` [PATCH v3 3/8] lpm: remove unnecessary NULL checks Stephen Hemminger
2022-02-21 2:47 ` Ruifeng Wang
@ 2022-02-21 15:51 ` Medvedkin, Vladimir
1 sibling, 0 replies; 33+ messages in thread
From: Medvedkin, Vladimir @ 2022-02-21 15:51 UTC (permalink / raw)
To: Stephen Hemminger, dev
Cc: Bruce Richardson, Yipeng Wang, Sameh Gobriel, Anatoly Burakov,
Olivier Matz, Andrew Rybchenko, Honnappa Nagarahalli,
Konstantin Ananyev
On 20/02/2022 18:21, Stephen Hemminger wrote:
> The functions rte_lpm_free() and rte_lpm6_free() already
> handle NULL pointer case.
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> 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(-)
>
Acked-by: Vladimir Medvedkin <vladimir.medvedkin@intel.com>
--
Regards,
Vladimir
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3 4/8] lib: document existing free functions
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
` (2 preceding siblings ...)
2022-02-20 18:21 ` [PATCH v3 3/8] lpm: remove unnecessary NULL checks Stephen Hemminger
@ 2022-02-20 18:21 ` Stephen Hemminger
2022-02-27 20:48 ` Thomas Monjalon
2022-02-20 18:21 ` [PATCH v3 5/8] test: remove unnecessary NULL checks before free Stephen Hemminger
` (5 subsequent siblings)
9 siblings, 1 reply; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-20 18:21 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, Fan Zhang, Ashish Gupta, Akhil Goyal,
Harman Kalra, Byron Marohn, Yipeng Wang, Jerin Jacob,
Vladimir Medvedkin, Sameh Gobriel, Reshma Pattan,
Cristian Dumitrescu, Jasvinder Singh, Olivier Matz, Ciara Power
These functions all accept NULL as parameter.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
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(-)
diff --git a/lib/bitratestats/rte_bitrate.h b/lib/bitratestats/rte_bitrate.h
index e494389b95a0..843baaf10900 100644
--- a/lib/bitratestats/rte_bitrate.h
+++ b/lib/bitratestats/rte_bitrate.h
@@ -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);
diff --git a/lib/compressdev/rte_comp.h b/lib/compressdev/rte_comp.h
index 95306c5d0364..b07434ad39b2 100644
--- a/lib/compressdev/rte_comp.h
+++ b/lib/compressdev/rte_comp.h
@@ -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
diff --git a/lib/cryptodev/rte_crypto.h b/lib/cryptodev/rte_crypto.h
index a864f5036f3a..326764b0f0c0 100644
--- a/lib/cryptodev/rte_crypto.h
+++ b/lib/cryptodev/rte_crypto.h
@@ -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)
diff --git a/lib/eal/include/rte_interrupts.h b/lib/eal/include/rte_interrupts.h
index edbf0faeeffd..3ef8ab4621fb 100644
--- a/lib/eal/include/rte_interrupts.h
+++ b/lib/eal/include/rte_interrupts.h
@@ -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
diff --git a/lib/efd/rte_efd.h b/lib/efd/rte_efd.h
index d3d7befd0c90..afba38a78c8a 100644
--- a/lib/efd/rte_efd.h
+++ b/lib/efd/rte_efd.h
@@ -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);
diff --git a/lib/eventdev/rte_event_ring.h b/lib/eventdev/rte_event_ring.h
index c0861b0ec2db..85c214a678cd 100644
--- a/lib/eventdev/rte_event_ring.h
+++ b/lib/eventdev/rte_event_ring.h
@@ -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);
diff --git a/lib/fib/rte_fib.h b/lib/fib/rte_fib.h
index e592d3251af1..5df6e34bde70 100644
--- a/lib/fib/rte_fib.h
+++ b/lib/fib/rte_fib.h
@@ -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
*/
diff --git a/lib/fib/rte_fib6.h b/lib/fib/rte_fib6.h
index cb133719e175..4029c8f3ee0d 100644
--- a/lib/fib/rte_fib6.h
+++ b/lib/fib/rte_fib6.h
@@ -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
*/
diff --git a/lib/member/rte_member.h b/lib/member/rte_member.h
index c0689e233e65..ada3b96e5ec1 100644
--- a/lib/member/rte_member.h
+++ b/lib/member/rte_member.h
@@ -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);
diff --git a/lib/reorder/rte_reorder.h b/lib/reorder/rte_reorder.h
index 9de02403746b..ecf83fb5c578 100644
--- a/lib/reorder/rte_reorder.h
+++ b/lib/reorder/rte_reorder.h
@@ -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
*/
diff --git a/lib/rib/rte_rib.h b/lib/rib/rte_rib.h
index bebb30f7d7cf..bafd2585ac69 100644
--- a/lib/rib/rte_rib.h
+++ b/lib/rib/rte_rib.h
@@ -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
*/
diff --git a/lib/rib/rte_rib6.h b/lib/rib/rte_rib6.h
index 6f532265c657..a2e179ccb4b9 100644
--- a/lib/rib/rte_rib6.h
+++ b/lib/rib/rte_rib6.h
@@ -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
*/
diff --git a/lib/sched/rte_sched.h b/lib/sched/rte_sched.h
index 3c625ba1698a..d212ad5774e6 100644
--- a/lib/sched/rte_sched.h
+++ b/lib/sched/rte_sched.h
@@ -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);
diff --git a/lib/stack/rte_stack.h b/lib/stack/rte_stack.h
index 321f4cec1a10..8c3bd4862711 100644
--- a/lib/stack/rte_stack.h
+++ b/lib/stack/rte_stack.h
@@ -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);
diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h
index 7bca8a9a49e2..af95fb4f150b 100644
--- a/lib/telemetry/rte_telemetry.h
+++ b/lib/telemetry/rte_telemetry.h
@@ -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);
--
2.34.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v3 4/8] lib: document existing free functions
2022-02-20 18:21 ` [PATCH v3 4/8] lib: document existing free functions Stephen Hemminger
@ 2022-02-27 20:48 ` Thomas Monjalon
2022-02-28 9:42 ` Bruce Richardson
0 siblings, 1 reply; 33+ messages in thread
From: Thomas Monjalon @ 2022-02-27 20:48 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev, bruce.richardson
20/02/2022 19:21, Stephen Hemminger:
> + * 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.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v3 4/8] lib: document existing free functions
2022-02-27 20:48 ` Thomas Monjalon
@ 2022-02-28 9:42 ` Bruce Richardson
2022-02-28 17:08 ` Stephen Hemminger
0 siblings, 1 reply; 33+ messages in thread
From: Bruce Richardson @ 2022-02-28 9:42 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: Stephen Hemminger, dev
On Sun, Feb 27, 2022 at 09:48:57PM +0100, Thomas Monjalon wrote:
> 20/02/2022 19:21, Stephen Hemminger:
> > + * 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
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v3 4/8] lib: document existing free functions
2022-02-28 9:42 ` Bruce Richardson
@ 2022-02-28 17:08 ` Stephen Hemminger
2022-06-22 9:23 ` Thomas Monjalon
0 siblings, 1 reply; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-28 17:08 UTC (permalink / raw)
To: Bruce Richardson; +Cc: Thomas Monjalon, dev
On Mon, 28 Feb 2022 09:42:47 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:
> On Sun, Feb 27, 2022 at 09:48:57PM +0100, Thomas Monjalon wrote:
> > 20/02/2022 19:21, Stephen Hemminger:
> > > + * 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.
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v3 4/8] lib: document existing free functions
2022-02-28 17:08 ` Stephen Hemminger
@ 2022-06-22 9:23 ` Thomas Monjalon
2022-06-22 14:55 ` Stephen Hemminger
0 siblings, 1 reply; 33+ messages in thread
From: Thomas Monjalon @ 2022-06-22 9:23 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Bruce Richardson, dev
28/02/2022 18:08, Stephen Hemminger:
> On Mon, 28 Feb 2022 09:42:47 +0000
> Bruce Richardson <bruce.richardson@intel.com> wrote:
>
> > On Sun, Feb 27, 2022 at 09:48:57PM +0100, Thomas Monjalon wrote:
> > > 20/02/2022 19:21, Stephen Hemminger:
> > > > + * 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.
Please do you want to respin?
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v3 4/8] lib: document existing free functions
2022-06-22 9:23 ` Thomas Monjalon
@ 2022-06-22 14:55 ` Stephen Hemminger
0 siblings, 0 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-06-22 14:55 UTC (permalink / raw)
To: Thomas Monjalon; +Cc: Bruce Richardson, dev
On Wed, 22 Jun 2022 11:23:04 +0200
Thomas Monjalon <thomas@monjalon.net> wrote:
> 28/02/2022 18:08, Stephen Hemminger:
> > On Mon, 28 Feb 2022 09:42:47 +0000
> > Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > > On Sun, Feb 27, 2022 at 09:48:57PM +0100, Thomas Monjalon wrote:
> > > > 20/02/2022 19:21, Stephen Hemminger:
> > > > > + * 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.
>
> Please do you want to respin?
>
>
Sure.
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3 5/8] test: remove unnecessary NULL checks before free
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
` (3 preceding siblings ...)
2022-02-20 18:21 ` [PATCH v3 4/8] lib: document existing free functions Stephen Hemminger
@ 2022-02-20 18:21 ` Stephen Hemminger
2022-02-20 18:21 ` [PATCH v3 6/8] fips_validation: remove unnecessary NULL check Stephen Hemminger
` (4 subsequent siblings)
9 siblings, 0 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-20 18:21 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, Olivier Matz, Akhil Goyal, Fan Zhang,
Yipeng Wang, Sameh Gobriel, Bruce Richardson, Vladimir Medvedkin,
Honnappa Nagarahalli, Konstantin Ananyev, Anatoly Burakov,
Andrew Rybchenko
These are all cases in test code where there is unnecessary
NULL check before free caught by coccinelle nullfree script.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
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(-)
diff --git a/app/test/test_cmdline_lib.c b/app/test/test_cmdline_lib.c
index fcd58cb76af1..87c105936650 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 a63c199964d4..1d9f615255c4 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -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,
diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 7cda8bb081f0..9b4d9db59297 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -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;
}
diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c
index 494459195c49..954587ea5b18 100644
--- a/app/test/test_cryptodev_blockcipher.c
+++ b/app/test/test_cryptodev_blockcipher.c
@@ -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);
diff --git a/app/test/test_func_reentrancy.c b/app/test/test_func_reentrancy.c
index 67e69ad53588..d1ed5d4abcfc 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);
diff --git a/app/test/test_hash.c b/app/test/test_hash.c
index d522cb7f8cbf..3e45afaa67fc 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
--
2.34.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3 6/8] fips_validation: remove unnecessary NULL check
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
` (4 preceding siblings ...)
2022-02-20 18:21 ` [PATCH v3 5/8] test: remove unnecessary NULL checks before free Stephen Hemminger
@ 2022-02-20 18:21 ` Stephen Hemminger
2022-02-20 18:21 ` [PATCH v3 7/8] event/sw: " Stephen Hemminger
` (3 subsequent siblings)
9 siblings, 0 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-20 18:21 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Marko Kovacevic
No need to check for null pointer here.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
examples/fips_validation/fips_dev_self_test.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/examples/fips_validation/fips_dev_self_test.c b/examples/fips_validation/fips_dev_self_test.c
index 076e9de099c0..19af134bbe83 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);
--
2.34.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3 7/8] event/sw: remove unnecessary NULL check
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
` (5 preceding siblings ...)
2022-02-20 18:21 ` [PATCH v3 6/8] fips_validation: remove unnecessary NULL check Stephen Hemminger
@ 2022-02-20 18:21 ` Stephen Hemminger
2022-02-20 18:21 ` [PATCH v3 8/8] pipeline: remove unnecessary checks for NULL pointer before free Stephen Hemminger
` (2 subsequent siblings)
9 siblings, 0 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-20 18:21 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Harry van Haaren
The XXX_free() functions already handle NULL pointer.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
drivers/event/sw/sw_evdev.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/event/sw/sw_evdev.c b/drivers/event/sw/sw_evdev.c
index ba82a80385b6..f93313b31b5c 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,
--
2.34.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v3 8/8] pipeline: remove unnecessary checks for NULL pointer before free
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
` (6 preceding siblings ...)
2022-02-20 18:21 ` [PATCH v3 7/8] event/sw: " Stephen Hemminger
@ 2022-02-20 18:21 ` Stephen Hemminger
2022-06-22 20:52 ` [PATCH v4] lib: document existing free functions Stephen Hemminger
2022-06-24 12:41 ` [PATCH v3 0/8] yet more unnecessary NULL checks David Marchand
9 siblings, 0 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-02-20 18:21 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Cristian Dumitrescu
This library (mostly) uses convention that allows caller
to pass NULL.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
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(-)
diff --git a/lib/pipeline/rte_port_in_action.h b/lib/pipeline/rte_port_in_action.h
index d6b063cf58a7..9debb9269297 100644
--- a/lib/pipeline/rte_port_in_action.h
+++ b/lib/pipeline/rte_port_in_action.h
@@ -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
diff --git a/lib/pipeline/rte_swx_ctl.c b/lib/pipeline/rte_swx_ctl.c
index f52ccffd75a4..710e89a46a26 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_ctl.h b/lib/pipeline/rte_swx_ctl.h
index 82e62e70a7c3..501731d54724 100644
--- a/lib/pipeline/rte_swx_ctl.h
+++ b/lib/pipeline/rte_swx_ctl.h
@@ -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
diff --git a/lib/pipeline/rte_swx_pipeline.c b/lib/pipeline/rte_swx_pipeline.c
index 868010303c73..0177a45c4486 100644
--- a/lib/pipeline/rte_swx_pipeline.c
+++ b/lib/pipeline/rte_swx_pipeline.c
@@ -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);
diff --git a/lib/pipeline/rte_swx_pipeline.h b/lib/pipeline/rte_swx_pipeline.h
index 77141bd3415b..51817159b154 100644
--- a/lib/pipeline/rte_swx_pipeline.h
+++ b/lib/pipeline/rte_swx_pipeline.h
@@ -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
--
2.34.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* [PATCH v4] lib: document existing free functions
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
` (7 preceding siblings ...)
2022-02-20 18:21 ` [PATCH v3 8/8] pipeline: remove unnecessary checks for NULL pointer before free Stephen Hemminger
@ 2022-06-22 20:52 ` Stephen Hemminger
2022-06-23 0:37 ` fengchengwen
2022-06-24 12:35 ` David Marchand
2022-06-24 12:41 ` [PATCH v3 0/8] yet more unnecessary NULL checks David Marchand
9 siblings, 2 replies; 33+ messages in thread
From: Stephen Hemminger @ 2022-06-22 20:52 UTC (permalink / raw)
To: dev
Cc: Stephen Hemminger, Fan Zhang, Ashish Gupta, Akhil Goyal,
Harman Kalra, Byron Marohn, Yipeng Wang, Jerin Jacob,
Vladimir Medvedkin, Sameh Gobriel, Reshma Pattan,
Cristian Dumitrescu, Jasvinder Singh, Olivier Matz, Ciara Power
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 <stephen@networkplumber.org>
---
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(-)
diff --git a/lib/bitratestats/rte_bitrate.h b/lib/bitratestats/rte_bitrate.h
index e494389b95a0..35cb44be1b7d 100644
--- a/lib/bitratestats/rte_bitrate.h
+++ b/lib/bitratestats/rte_bitrate.h
@@ -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);
diff --git a/lib/compressdev/rte_comp.h b/lib/compressdev/rte_comp.h
index cdb55e5887d3..8cc60bf9e898 100644
--- a/lib/compressdev/rte_comp.h
+++ b/lib/compressdev/rte_comp.h
@@ -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
diff --git a/lib/cryptodev/rte_crypto.h b/lib/cryptodev/rte_crypto.h
index aeb3bf6e383a..e03bbeceddef 100644
--- a/lib/cryptodev/rte_crypto.h
+++ b/lib/cryptodev/rte_crypto.h
@@ -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)
diff --git a/lib/eal/include/rte_interrupts.h b/lib/eal/include/rte_interrupts.h
index 68ad19c3e742..4361ecc565d3 100644
--- a/lib/eal/include/rte_interrupts.h
+++ b/lib/eal/include/rte_interrupts.h
@@ -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
diff --git a/lib/efd/rte_efd.h b/lib/efd/rte_efd.h
index d3d7befd0c90..b4ef783b8783 100644
--- a/lib/efd/rte_efd.h
+++ b/lib/efd/rte_efd.h
@@ -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);
diff --git a/lib/eventdev/rte_event_ring.h b/lib/eventdev/rte_event_ring.h
index 0101cc0aa232..34abe8d51831 100644
--- a/lib/eventdev/rte_event_ring.h
+++ b/lib/eventdev/rte_event_ring.h
@@ -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);
diff --git a/lib/fib/rte_fib.h b/lib/fib/rte_fib.h
index 90f28b7e11ad..29d99105dcc5 100644
--- a/lib/fib/rte_fib.h
+++ b/lib/fib/rte_fib.h
@@ -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
*/
diff --git a/lib/fib/rte_fib6.h b/lib/fib/rte_fib6.h
index 62a425d9afe2..a9a02257ee5c 100644
--- a/lib/fib/rte_fib6.h
+++ b/lib/fib/rte_fib6.h
@@ -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
*/
diff --git a/lib/member/rte_member.h b/lib/member/rte_member.h
index 567ee0c84bd9..41c730ba76a3 100644
--- a/lib/member/rte_member.h
+++ b/lib/member/rte_member.h
@@ -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);
diff --git a/lib/reorder/rte_reorder.h b/lib/reorder/rte_reorder.h
index 9de02403746b..4dedc36b8a80 100644
--- a/lib/reorder/rte_reorder.h
+++ b/lib/reorder/rte_reorder.h
@@ -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
*/
diff --git a/lib/rib/rte_rib.h b/lib/rib/rte_rib.h
index c18c4ca594c1..7c3d0997244f 100644
--- a/lib/rib/rte_rib.h
+++ b/lib/rib/rte_rib.h
@@ -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
*/
diff --git a/lib/rib/rte_rib6.h b/lib/rib/rte_rib6.h
index fa8e9bf7327b..64301776b51f 100644
--- a/lib/rib/rte_rib6.h
+++ b/lib/rib/rte_rib6.h
@@ -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
*/
diff --git a/lib/sched/rte_sched.h b/lib/sched/rte_sched.h
index 0bd5b72a4a7a..0ba4ef6dec01 100644
--- a/lib/sched/rte_sched.h
+++ b/lib/sched/rte_sched.h
@@ -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);
diff --git a/lib/stack/rte_stack.h b/lib/stack/rte_stack.h
index 91fc5707670f..33ea451223e5 100644
--- a/lib/stack/rte_stack.h
+++ b/lib/stack/rte_stack.h
@@ -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);
diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h
index 3372b32f38b5..a49a6d1e571b 100644
--- a/lib/telemetry/rte_telemetry.h
+++ b/lib/telemetry/rte_telemetry.h
@@ -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);
--
2.35.1
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v4] lib: document existing free functions
2022-06-22 20:52 ` [PATCH v4] lib: document existing free functions Stephen Hemminger
@ 2022-06-23 0:37 ` fengchengwen
2022-06-24 12:35 ` David Marchand
1 sibling, 0 replies; 33+ messages in thread
From: fengchengwen @ 2022-06-23 0:37 UTC (permalink / raw)
To: Stephen Hemminger, dev
Cc: Fan Zhang, Ashish Gupta, Akhil Goyal, Harman Kalra, Byron Marohn,
Yipeng Wang, Jerin Jacob, Vladimir Medvedkin, Sameh Gobriel,
Reshma Pattan, Cristian Dumitrescu, Jasvinder Singh,
Olivier Matz, Ciara Power
On 2022/6/23 4:52, Stephen Hemminger wrote:
> 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.
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
> 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(-)
>
...
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v4] lib: document existing free functions
2022-06-22 20:52 ` [PATCH v4] lib: document existing free functions Stephen Hemminger
2022-06-23 0:37 ` fengchengwen
@ 2022-06-24 12:35 ` David Marchand
1 sibling, 0 replies; 33+ messages in thread
From: David Marchand @ 2022-06-24 12:35 UTC (permalink / raw)
To: Stephen Hemminger
Cc: dev, Fan Zhang, Ashish Gupta, Akhil Goyal, Harman Kalra,
Byron Marohn, Yipeng Wang, Jerin Jacob, Vladimir Medvedkin,
Sameh Gobriel, Reshma Pattan, Cristian Dumitrescu,
Jasvinder Singh, Olivier Matz, Ciara Power, Chengwen Feng
On Wed, Jun 22, 2022 at 10:53 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> 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 <stephen@networkplumber.org>
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.
--
David Marchand
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [PATCH v3 0/8] yet more unnecessary NULL checks
2022-02-20 18:21 ` [PATCH v3 0/8] yet more unnecessary NULL checks Stephen Hemminger
` (8 preceding siblings ...)
2022-06-22 20:52 ` [PATCH v4] lib: document existing free functions Stephen Hemminger
@ 2022-06-24 12:41 ` David Marchand
9 siblings, 0 replies; 33+ messages in thread
From: David Marchand @ 2022-06-24 12:41 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: dev
On Sun, Feb 20, 2022 at 7:22 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> 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
>
> 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.
--
David Marchand
^ permalink raw reply [flat|nested] 33+ messages in thread