DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 00/15] Add attributes to allocation functions
@ 2025-01-20 18:03 Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 01/15] fib: add allocation function attributes Stephen Hemminger
                   ` (16 more replies)
  0 siblings, 17 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

This patch series builds on the allocation function attributes
added in 24.11 release. These annotations will allow for compiler
to flag cases where a pointer is allocated with one function
but incorrectly passed to a different free function.

Checkpatch perl script falsely complains in a couple patches
because it doesn't really understand C syntax for attributes.

Stephen Hemminger (15):
  fib: add allocation function attributes
  rib: annotate rib allocation functions
  hash: add allocation function attributes
  lpm: add allocation function attributes
  pipeline: add allocation function attributes
  acl: add allocation function attributes
  bitratestats: add allocation function attributes
  member: add allocation function attributes
  mempool: add allocation function attributes
  eventdev: add allocation function attributes
  ring: add allocation function attributes
  reorder: add allocation function attributes
  compressdev: add allocation function attributes
  telemetry: add allocation function attributes
  sched: add allocation function attributes

 lib/acl/rte_acl.h                 | 26 ++++++++-------
 lib/bitratestats/rte_bitrate.h    | 20 +++++------
 lib/compressdev/rte_comp.h        | 28 ++++++++--------
 lib/eventdev/rte_event_ring.h     | 27 +++++++--------
 lib/fib/rte_fib.h                 | 26 ++++++++-------
 lib/fib/rte_fib6.h                | 24 +++++++-------
 lib/fib/trie.h                    |  7 ++--
 lib/hash/rte_fbk_hash.h           | 24 +++++++-------
 lib/hash/rte_hash.h               | 21 ++++++------
 lib/lpm/rte_lpm.h                 | 23 ++++++-------
 lib/lpm/rte_lpm6.h                | 23 ++++++-------
 lib/member/rte_member.h           | 24 +++++++-------
 lib/mempool/rte_mempool.h         | 37 +++++++++++----------
 lib/pipeline/rte_port_in_action.h | 55 ++++++++++++++++---------------
 lib/pipeline/rte_table_action.h   | 53 +++++++++++++++--------------
 lib/reorder/rte_reorder.h         | 23 ++++++-------
 lib/rib/rte_rib.h                 | 24 +++++++-------
 lib/rib/rte_rib6.h                | 24 +++++++-------
 lib/ring/rte_ring.h               | 22 +++++++------
 lib/sched/rte_sched.h             | 23 +++++++------
 lib/telemetry/rte_telemetry.h     | 21 ++++++------
 21 files changed, 296 insertions(+), 259 deletions(-)

-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 01/15] fib: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 02/15] rib: annotate rib allocation functions Stephen Hemminger
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Vladimir Medvedkin

Use function attributes to catch cases where fib table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/fib/rte_fib.h  | 26 +++++++++++++++-----------
 lib/fib/rte_fib6.h | 24 +++++++++++++-----------
 lib/fib/trie.h     |  7 ++++---
 3 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/lib/fib/rte_fib.h b/lib/fib/rte_fib.h
index 496d137d48..65c24d5459 100644
--- a/lib/fib/rte_fib.h
+++ b/lib/fib/rte_fib.h
@@ -17,8 +17,10 @@
 
 #include <stdint.h>
 
+#include <rte_common.h>
 #include <rte_rcu_qsbr.h>
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -128,6 +130,17 @@ struct rte_fib_rcu_config {
 	uint32_t reclaim_max;
 };
 
+
+/**
+ * Free an FIB object.
+ *
+ * @param fib
+ *   FIB object handle created by rte_fib_create().
+ *   If fib is NULL, no operation is performed.
+ */
+void
+rte_fib_free(struct rte_fib *fib);
+
 /**
  * Create FIB
  *
@@ -142,7 +155,8 @@ struct rte_fib_rcu_config {
  *  NULL otherwise with rte_errno set to an appropriate values.
  */
 struct rte_fib *
-rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf);
+rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf)
+	__rte_malloc __rte_dealloc(rte_fib_free, 1);
 
 /**
  * Find an existing FIB object and return a pointer to it.
@@ -157,16 +171,6 @@ rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf);
 struct rte_fib *
 rte_fib_find_existing(const char *name);
 
-/**
- * Free an FIB object.
- *
- * @param fib
- *   FIB object handle created by rte_fib_create().
- *   If fib is NULL, no operation is performed.
- */
-void
-rte_fib_free(struct rte_fib *fib);
-
 /**
  * Add a route to the FIB.
  *
diff --git a/lib/fib/rte_fib6.h b/lib/fib/rte_fib6.h
index 21f0492374..b03b24421c 100644
--- a/lib/fib/rte_fib6.h
+++ b/lib/fib/rte_fib6.h
@@ -82,6 +82,17 @@ struct rte_fib6_conf {
 	};
 };
 
+
+/**
+ * Free an FIB object.
+ *
+ * @param fib
+ *   FIB object handle created by rte_fib6_create().
+ *   If fib is NULL, no operation is performed.
+ */
+void
+rte_fib6_free(struct rte_fib6 *fib);
+
 /**
  * Create FIB
  *
@@ -96,7 +107,8 @@ struct rte_fib6_conf {
  *  NULL otherwise with rte_errno set to an appropriate values.
  */
 struct rte_fib6 *
-rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
+rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf)
+	__rte_malloc __rte_dealloc(rte_fib6_free, 1);
 
 /**
  * Find an existing FIB object and return a pointer to it.
@@ -111,16 +123,6 @@ rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
 struct rte_fib6 *
 rte_fib6_find_existing(const char *name);
 
-/**
- * Free an FIB object.
- *
- * @param fib
- *   FIB object handle created by rte_fib6_create().
- *   If fib is NULL, no operation is performed.
- */
-void
-rte_fib6_free(struct rte_fib6 *fib);
-
 /**
  * Add a route to the FIB.
  *
diff --git a/lib/fib/trie.h b/lib/fib/trie.h
index f87fc0f6d2..bcb161702b 100644
--- a/lib/fib/trie.h
+++ b/lib/fib/trie.h
@@ -129,12 +129,13 @@ LOOKUP_FUNC(2b, uint16_t, 1)
 LOOKUP_FUNC(4b, uint32_t, 2)
 LOOKUP_FUNC(8b, uint64_t, 3)
 
-void *
-trie_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
-
 void
 trie_free(void *p);
 
+void *
+trie_create(const char *name, int socket_id, struct rte_fib6_conf *conf)
+	__rte_malloc __rte_dealloc(trie_free, 1);
+
 rte_fib6_lookup_fn_t
 trie_get_lookup_fn(void *p, enum rte_fib6_lookup_type type);
 
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 02/15] rib: annotate rib allocation functions
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 01/15] fib: add allocation function attributes Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 03/15] hash: add allocation function attributes Stephen Hemminger
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Vladimir Medvedkin

Add function attributes to catch cases where rib is allocated
and not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/rib/rte_rib.h  | 24 +++++++++++++-----------
 lib/rib/rte_rib6.h | 24 +++++++++++++-----------
 2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/lib/rib/rte_rib.h b/lib/rib/rte_rib.h
index 2054d3cebd..f30b85d79a 100644
--- a/lib/rib/rte_rib.h
+++ b/lib/rib/rte_rib.h
@@ -230,6 +230,17 @@ rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh);
 int
 rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
 
+
+/**
+ * Free an RIB object.
+ *
+ * @param rib
+ *   RIB object handle created with rte_rib_create().
+ *   If rib is NULL, no operation is performed.
+ */
+void
+rte_rib_free(struct rte_rib *rib);
+
 /**
  * Create RIB
  *
@@ -245,7 +256,8 @@ rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
  */
 struct rte_rib *
 rte_rib_create(const char *name, int socket_id,
-	       const struct rte_rib_conf *conf);
+	       const struct rte_rib_conf *conf)
+	__rte_malloc __rte_dealloc(rte_rib_free, 1);
 
 /**
  * Find an existing RIB object and return a pointer to it.
@@ -259,16 +271,6 @@ rte_rib_create(const char *name, int socket_id,
 struct rte_rib *
 rte_rib_find_existing(const char *name);
 
-/**
- * Free an RIB object.
- *
- * @param rib
- *   RIB object handle created with rte_rib_create().
- *   If rib is NULL, no operation is performed.
- */
-void
-rte_rib_free(struct rte_rib *rib);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/rib/rte_rib6.h b/lib/rib/rte_rib6.h
index a60756f798..d9514acf82 100644
--- a/lib/rib/rte_rib6.h
+++ b/lib/rib/rte_rib6.h
@@ -294,6 +294,17 @@ rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh);
 int
 rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh);
 
+
+/**
+ * Free an RIB object.
+ *
+ * @param rib
+ *   RIB object handle created with rte_rib6_create().
+ *   If rib is NULL, no operation is performed.
+ */
+void
+rte_rib6_free(struct rte_rib6 *rib);
+
 /**
  * Create RIB
  *
@@ -309,7 +320,8 @@ rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh);
  */
 struct rte_rib6 *
 rte_rib6_create(const char *name, int socket_id,
-		const struct rte_rib6_conf *conf);
+		const struct rte_rib6_conf *conf)
+	__rte_malloc __rte_dealloc(rte_rib6_free, 1);
 
 /**
  * Find an existing RIB object and return a pointer to it.
@@ -323,16 +335,6 @@ rte_rib6_create(const char *name, int socket_id,
 struct rte_rib6 *
 rte_rib6_find_existing(const char *name);
 
-/**
- * Free an RIB object.
- *
- * @param rib
- *   RIB object handle created with rte_rib6_create().
- *   If rib is NULL, no operation is performed.
- */
-void
-rte_rib6_free(struct rte_rib6 *rib);
-
 #ifdef __cplusplus
 }
 #endif
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 03/15] hash: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 01/15] fib: add allocation function attributes Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 02/15] rib: annotate rib allocation functions Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 04/15] lpm: " Stephen Hemminger
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Yipeng Wang, Sameh Gobriel, Bruce Richardson,
	Vladimir Medvedkin

Use function attributes to catch cases where hash table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/hash/rte_fbk_hash.h | 24 +++++++++++++-----------
 lib/hash/rte_hash.h     | 21 +++++++++++----------
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/lib/hash/rte_fbk_hash.h b/lib/hash/rte_fbk_hash.h
index 1f0c1d1b6c..b1a43f37b4 100644
--- a/lib/hash/rte_fbk_hash.h
+++ b/lib/hash/rte_fbk_hash.h
@@ -322,6 +322,16 @@ rte_fbk_hash_get_load_factor(struct rte_fbk_hash_table *ht)
  */
 struct rte_fbk_hash_table *rte_fbk_hash_find_existing(const char *name);
 
+
+/**
+ * Free all memory used by a hash table.
+ * Has no effect on hash tables allocated in memory zones
+ *
+ * @param ht
+ *   Hash table to deallocate.
+ */
+void rte_fbk_hash_free(struct rte_fbk_hash_table *ht);
+
 /**
  * Create a new hash table for use with four byte keys.
  *
@@ -339,17 +349,9 @@ struct rte_fbk_hash_table *rte_fbk_hash_find_existing(const char *name);
  *    - EEXIST - a memzone with the same name already exists
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
-struct rte_fbk_hash_table * \
-rte_fbk_hash_create(const struct rte_fbk_hash_params *params);
-
-/**
- * Free all memory used by a hash table.
- * Has no effect on hash tables allocated in memory zones
- *
- * @param ht
- *   Hash table to deallocate.
- */
-void rte_fbk_hash_free(struct rte_fbk_hash_table *ht);
+struct rte_fbk_hash_table *
+rte_fbk_hash_create(const struct rte_fbk_hash_params *params)
+	__rte_malloc __rte_dealloc(rte_fbk_hash_free, 1);
 
 #ifdef __cplusplus
 }
diff --git a/lib/hash/rte_hash.h b/lib/hash/rte_hash.h
index 05ab447e4a..736fb15885 100644
--- a/lib/hash/rte_hash.h
+++ b/lib/hash/rte_hash.h
@@ -125,6 +125,15 @@ struct rte_hash_rcu_config {
 /** @internal A hash table structure. */
 struct rte_hash;
 
+/**
+ * De-allocate all memory used by hash table.
+ *
+ * @param h
+ *   Hash table to free, if NULL, the function does nothing.
+ */
+void
+rte_hash_free(struct rte_hash *h);
+
 /**
  * Create a new hash table.
  *
@@ -143,7 +152,8 @@ struct rte_hash;
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
 struct rte_hash *
-rte_hash_create(const struct rte_hash_parameters *params);
+rte_hash_create(const struct rte_hash_parameters *params)
+	__rte_malloc __rte_dealloc(rte_hash_free, 1);
 
 /**
  * Set a new hash compare function other than the default one.
@@ -171,15 +181,6 @@ void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);
 struct rte_hash *
 rte_hash_find_existing(const char *name);
 
-/**
- * De-allocate all memory used by hash table.
- *
- * @param h
- *   Hash table to free, if NULL, the function does nothing.
- */
-void
-rte_hash_free(struct rte_hash *h);
-
 /**
  * Reset all hash structure, by zeroing all entries.
  * When RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF is enabled,
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 04/15] lpm: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (2 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 03/15] hash: add allocation function attributes Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 05/15] pipeline: " Stephen Hemminger
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Bruce Richardson, Vladimir Medvedkin

Use function attributes to catch cases where lpm table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/lpm/rte_lpm.h  | 23 ++++++++++++-----------
 lib/lpm/rte_lpm6.h | 23 ++++++++++++-----------
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/lib/lpm/rte_lpm.h b/lib/lpm/rte_lpm.h
index 329dc1aad4..7df64f06b1 100644
--- a/lib/lpm/rte_lpm.h
+++ b/lib/lpm/rte_lpm.h
@@ -140,6 +140,16 @@ struct rte_lpm_rcu_config {
 				 */
 };
 
+/**
+ * Free an LPM object.
+ *
+ * @param lpm
+ *   LPM object handle
+ *   If lpm is NULL, no operation is performed.
+ */
+void
+rte_lpm_free(struct rte_lpm *lpm);
+
 /**
  * Create an LPM object.
  *
@@ -161,7 +171,8 @@ struct rte_lpm_rcu_config {
  */
 struct rte_lpm *
 rte_lpm_create(const char *name, int socket_id,
-		const struct rte_lpm_config *config);
+	       const struct rte_lpm_config *config)
+	__rte_malloc __rte_dealloc(rte_lpm_free, 1);
 
 /**
  * Find an existing LPM object and return a pointer to it.
@@ -176,16 +187,6 @@ rte_lpm_create(const char *name, int socket_id,
 struct rte_lpm *
 rte_lpm_find_existing(const char *name);
 
-/**
- * Free an LPM object.
- *
- * @param lpm
- *   LPM object handle
- *   If lpm is NULL, no operation is performed.
- */
-void
-rte_lpm_free(struct rte_lpm *lpm);
-
 /**
  * Associate RCU QSBR variable with an LPM object.
  *
diff --git a/lib/lpm/rte_lpm6.h b/lib/lpm/rte_lpm6.h
index 079187ca56..08b5618613 100644
--- a/lib/lpm/rte_lpm6.h
+++ b/lib/lpm/rte_lpm6.h
@@ -34,6 +34,16 @@ struct rte_lpm6_config {
 	int flags;               /**< This field is currently unused. */
 };
 
+/**
+ * Free an LPM object.
+ *
+ * @param lpm
+ *   LPM object handle
+ *   If lpm is NULL, no operation is performed.
+ */
+void
+rte_lpm6_free(struct rte_lpm6 *lpm);
+
 /**
  * Create an LPM object.
  *
@@ -55,7 +65,8 @@ struct rte_lpm6_config {
  */
 struct rte_lpm6 *
 rte_lpm6_create(const char *name, int socket_id,
-		const struct rte_lpm6_config *config);
+		const struct rte_lpm6_config *config)
+	__rte_malloc __rte_dealloc(rte_lpm6_free, 1);
 
 /**
  * Find an existing LPM object and return a pointer to it.
@@ -70,16 +81,6 @@ rte_lpm6_create(const char *name, int socket_id,
 struct rte_lpm6 *
 rte_lpm6_find_existing(const char *name);
 
-/**
- * Free an LPM object.
- *
- * @param lpm
- *   LPM object handle
- *   If lpm is NULL, no operation is performed.
- */
-void
-rte_lpm6_free(struct rte_lpm6 *lpm);
-
 /**
  * Add a rule to the LPM table.
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 05/15] pipeline: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (3 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 04/15] lpm: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 06/15] acl: " Stephen Hemminger
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Cristian Dumitrescu

Use function attributes to catch cases where pipeline is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/pipeline/rte_port_in_action.h | 55 ++++++++++++++++---------------
 lib/pipeline/rte_table_action.h   | 53 +++++++++++++++--------------
 2 files changed, 56 insertions(+), 52 deletions(-)

diff --git a/lib/pipeline/rte_port_in_action.h b/lib/pipeline/rte_port_in_action.h
index 9d17bae988..ee6cc59fae 100644
--- a/lib/pipeline/rte_port_in_action.h
+++ b/lib/pipeline/rte_port_in_action.h
@@ -164,18 +164,6 @@ struct rte_port_in_action_lb_params {
  */
 struct rte_port_in_action_profile;
 
-/**
- * Input port action profile create.
- *
- * @param[in] socket_id
- *   CPU socket ID for the internal data structures memory allocation.
- * @return
- *   Input port action profile handle on success, NULL otherwise.
- */
-__rte_experimental
-struct rte_port_in_action_profile *
-rte_port_in_action_profile_create(uint32_t socket_id);
-
 /**
  * Input port action profile free.
  *
@@ -189,6 +177,19 @@ __rte_experimental
 int
 rte_port_in_action_profile_free(struct rte_port_in_action_profile *profile);
 
+/**
+ * Input port action profile create.
+ *
+ * @param[in] socket_id
+ *   CPU socket ID for the internal data structures memory allocation.
+ * @return
+ *   Input port action profile handle on success, NULL otherwise.
+ */
+__rte_experimental
+struct rte_port_in_action_profile *
+rte_port_in_action_profile_create(uint32_t socket_id)
+	__rte_malloc __rte_dealloc(rte_port_in_action_profile_free, 1);
+
 /**
  * Input port action profile action register.
  *
@@ -236,6 +237,19 @@ rte_port_in_action_profile_freeze(struct rte_port_in_action_profile *profile);
  */
 struct rte_port_in_action;
 
+/**
+ * Input port action free.
+ *
+ * @param[in] action
+ *   Handle to input port action object (needs to be valid).
+ *   If action is NULL, no operation is performed.
+ * @return
+ *   Always zero.
+ */
+__rte_experimental
+int
+rte_port_in_action_free(struct rte_port_in_action *action);
+
 /**
  * Input port action create.
  *
@@ -252,21 +266,8 @@ struct rte_port_in_action;
  */
 __rte_experimental
 struct rte_port_in_action *
-rte_port_in_action_create(struct rte_port_in_action_profile *profile,
-	uint32_t socket_id);
-
-/**
- * Input port action free.
- *
- * @param[in] action
- *   Handle to input port action object (needs to be valid).
- *   If action is NULL, no operation is performed.
- * @return
- *   Always zero.
- */
-__rte_experimental
-int
-rte_port_in_action_free(struct rte_port_in_action *action);
+rte_port_in_action_create(struct rte_port_in_action_profile *profile, uint32_t socket_id)
+	__rte_malloc __rte_dealloc(rte_port_in_action_free, 1);
 
 /**
  * Input port params get.
diff --git a/lib/pipeline/rte_table_action.h b/lib/pipeline/rte_table_action.h
index 47a7bdfc01..e8b4d8b33d 100644
--- a/lib/pipeline/rte_table_action.h
+++ b/lib/pipeline/rte_table_action.h
@@ -54,6 +54,7 @@
 
 #include <stdint.h>
 
+#include <rte_common.h>
 #include <rte_compat.h>
 #include <rte_ether.h>
 #include <rte_ip6.h>
@@ -812,17 +813,6 @@ struct rte_table_action_decap_params {
  */
 struct rte_table_action_profile;
 
-/**
- * Table action profile create.
- *
- * @param[in] common
- *   Common action configuration.
- * @return
- *   Table action profile handle on success, NULL otherwise.
- */
-__rte_experimental
-struct rte_table_action_profile *
-rte_table_action_profile_create(struct rte_table_action_common_config *common);
 
 /**
  * Table action profile free.
@@ -836,6 +826,19 @@ __rte_experimental
 int
 rte_table_action_profile_free(struct rte_table_action_profile *profile);
 
+/**
+ * Table action profile create.
+ *
+ * @param[in] common
+ *   Common action configuration.
+ * @return
+ *   Table action profile handle on success, NULL otherwise.
+ */
+__rte_experimental
+struct rte_table_action_profile *
+rte_table_action_profile_create(struct rte_table_action_common_config *common)
+	__rte_malloc __rte_dealloc(rte_table_action_profile_free, 1);
+
 /**
  * Table action profile action register.
  *
@@ -881,6 +884,18 @@ rte_table_action_profile_freeze(struct rte_table_action_profile *profile);
  */
 struct rte_table_action;
 
+/**
+ * Table action free.
+ *
+ * @param[in] action
+ *   Handle to table action object (needs to be valid).
+ * @return
+ *   Zero on success, non-zero error code otherwise.
+ */
+__rte_experimental
+int
+rte_table_action_free(struct rte_table_action *action);
+
 /**
  * Table action create.
  *
@@ -898,20 +913,8 @@ struct rte_table_action;
  */
 __rte_experimental
 struct rte_table_action *
-rte_table_action_create(struct rte_table_action_profile *profile,
-	uint32_t socket_id);
-
-/**
- * Table action free.
- *
- * @param[in] action
- *   Handle to table action object (needs to be valid).
- * @return
- *   Zero on success, non-zero error code otherwise.
- */
-__rte_experimental
-int
-rte_table_action_free(struct rte_table_action *action);
+rte_table_action_create(struct rte_table_action_profile *profile, uint32_t socket_id)
+	__rte_malloc __rte_dealloc(rte_table_action_free, 1);
 
 /**
  * Table action table params get.
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 06/15] acl: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (4 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 05/15] pipeline: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 07/15] bitratestats: " Stephen Hemminger
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev

Use function attributes to catch cases where acl table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/acl/rte_acl.h | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/acl/rte_acl.h b/lib/acl/rte_acl.h
index ca75a6f220..b95f8778c3 100644
--- a/lib/acl/rte_acl.h
+++ b/lib/acl/rte_acl.h
@@ -133,6 +133,19 @@ struct rte_acl_param {
 };
 
 
+/** @internal opaque ACL handle */
+struct rte_acl_ctx;
+
+/**
+ * De-allocate all memory used by ACL context.
+ *
+ * @param ctx
+ *   ACL context to free
+ *   If ctx is NULL, no operation is performed.
+ */
+void
+rte_acl_free(struct rte_acl_ctx *ctx);
+
 /**
  * Create a new ACL context.
  *
@@ -145,7 +158,8 @@ struct rte_acl_param {
  *   - EINVAL - invalid parameter passed to function
  */
 struct rte_acl_ctx *
-rte_acl_create(const struct rte_acl_param *param);
+rte_acl_create(const struct rte_acl_param *param)
+	__rte_malloc __rte_dealloc(rte_acl_free, 1);
 
 /**
  * Find an existing ACL context object and return a pointer to it.
@@ -160,16 +174,6 @@ rte_acl_create(const struct rte_acl_param *param);
 struct rte_acl_ctx *
 rte_acl_find_existing(const char *name);
 
-/**
- * De-allocate all memory used by ACL context.
- *
- * @param ctx
- *   ACL context to free
- *   If ctx is NULL, no operation is performed.
- */
-void
-rte_acl_free(struct rte_acl_ctx *ctx);
-
 /**
  * Add rules to an existing ACL context.
  * This function is not multi-thread safe.
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 07/15] bitratestats: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (5 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 06/15] acl: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 08/15] member: " Stephen Hemminger
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

Use function attributes to catch cases where bitratestats is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/bitratestats/rte_bitrate.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/bitratestats/rte_bitrate.h b/lib/bitratestats/rte_bitrate.h
index 979a712837..27951f3e28 100644
--- a/lib/bitratestats/rte_bitrate.h
+++ b/lib/bitratestats/rte_bitrate.h
@@ -17,16 +17,6 @@ extern "C" {
  */
 struct rte_stats_bitrates;
 
-
-/**
- * Allocate a bitrate statistics structure
- *
- * @return
- *   - Pointer to structure on success
- *   - NULL on error (zmalloc failure)
- */
-struct rte_stats_bitrates *rte_stats_bitrate_create(void);
-
 /**
  * Free bitrate statistics structure
  *
@@ -36,6 +26,16 @@ struct rte_stats_bitrates *rte_stats_bitrate_create(void);
  */
 void rte_stats_bitrate_free(struct rte_stats_bitrates *bitrate_data);
 
+/**
+ * Allocate a bitrate statistics structure
+ *
+ * @return
+ *   - Pointer to structure on success
+ *   - NULL on error (zmalloc failure)
+ */
+struct rte_stats_bitrates *rte_stats_bitrate_create(void)
+	__rte_malloc __rte_dealloc(rte_stats_bitrate_free, 1);
+
 /**
  * Register bitrate statistics with the metric library.
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 08/15] member: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (6 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 07/15] bitratestats: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 09/15] mempool: " Stephen Hemminger
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Yipeng Wang, Sameh Gobriel

Use function attributes to catch cases where member table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/member/rte_member.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/member/rte_member.h b/lib/member/rte_member.h
index 109bdd000b..0235bb0a81 100644
--- a/lib/member/rte_member.h
+++ b/lib/member/rte_member.h
@@ -341,6 +341,16 @@ struct __rte_cache_aligned rte_member_parameters {
 struct rte_member_setsum *
 rte_member_find_existing(const char *name);
 
+/**
+ * De-allocate memory used by set-summary.
+ *
+ * @param setsum
+ *   Pointer to the set summary.
+ *   If setsum is NULL, no operation is performed.
+ */
+void
+rte_member_free(struct rte_member_setsum *setsum);
+
 /**
  * Create set-summary (SS).
  *
@@ -351,7 +361,8 @@ rte_member_find_existing(const char *name);
  *   Return value is NULL if the creation failed.
  */
 struct rte_member_setsum *
-rte_member_create(const struct rte_member_parameters *params);
+rte_member_create(const struct rte_member_parameters *params)
+	__rte_malloc __rte_dealloc(rte_member_free, 1);
 
 /**
  * Lookup key in set-summary (SS).
@@ -528,17 +539,6 @@ int
 rte_member_report_heavyhitter(const struct rte_member_setsum *setsum,
 			      void **keys, uint64_t *counts);
 
-
-/**
- * De-allocate memory used by set-summary.
- *
- * @param setsum
- *   Pointer to the set summary.
- *   If setsum is NULL, no operation is performed.
- */
-void
-rte_member_free(struct rte_member_setsum *setsum);
-
 /**
  * Reset the set-summary tables. E.g. reset bits to be 0 in BF,
  * reset set_id in each entry to be RTE_MEMBER_NO_MATCH in HT based SS.
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 09/15] mempool: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (7 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 08/15] member: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 10/15] eventdev: " Stephen Hemminger
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Andrew Rybchenko, Morten Brørup

Use function attributes to catch cases where mempool is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/mempool/rte_mempool.h | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h
index 7bdc92b812..c495cc012f 100644
--- a/lib/mempool/rte_mempool.h
+++ b/lib/mempool/rte_mempool.h
@@ -1012,6 +1012,20 @@ typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
  */
 typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
 
+/**
+ * Free a mempool
+ *
+ * Unlink the mempool from global list, free the memory chunks, and all
+ * memory referenced by the mempool. The objects must not be used by
+ * other cores as they will be freed.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ *   If NULL then, the function does nothing.
+ */
+void
+rte_mempool_free(struct rte_mempool *mp);
+
 /**
  * Create a new mempool named *name* in memory.
  *
@@ -1095,7 +1109,8 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
 		   unsigned cache_size, unsigned private_data_size,
 		   rte_mempool_ctor_t *mp_init, void *mp_init_arg,
 		   rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
-		   int socket_id, unsigned flags);
+		   int socket_id, unsigned int flags)
+	__rte_malloc __rte_dealloc(rte_mempool_free, 1);
 
 /**
  * Create an empty mempool
@@ -1132,22 +1147,10 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
  *   with rte_errno set appropriately. See rte_mempool_create() for details.
  */
 struct rte_mempool *
-rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
-	unsigned cache_size, unsigned private_data_size,
-	int socket_id, unsigned flags);
-/**
- * Free a mempool
- *
- * Unlink the mempool from global list, free the memory chunks, and all
- * memory referenced by the mempool. The objects must not be used by
- * other cores as they will be freed.
- *
- * @param mp
- *   A pointer to the mempool structure.
- *   If NULL then, the function does nothing.
- */
-void
-rte_mempool_free(struct rte_mempool *mp);
+rte_mempool_create_empty(const char *name, unsigned int n, unsigned int elt_size,
+			 unsigned int cache_size, unsigned int private_data_size,
+			 int socket_id, unsigned int flags)
+		__rte_malloc __rte_dealloc(rte_mempool_free, 1);
 
 /**
  * Add physically contiguous memory for objects in the pool at init
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 10/15] eventdev: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (8 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 09/15] mempool: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 11/15] ring: " Stephen Hemminger
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Jerin Jacob

Use function attributes to catch cases where eventdev is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eventdev/rte_event_ring.h | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/lib/eventdev/rte_event_ring.h b/lib/eventdev/rte_event_ring.h
index 5769da269e..a8f308e4d6 100644
--- a/lib/eventdev/rte_event_ring.h
+++ b/lib/eventdev/rte_event_ring.h
@@ -247,7 +247,18 @@ int
 rte_event_ring_init(struct rte_event_ring *r, const char *name,
 	unsigned int count, unsigned int flags);
 
-/*
+
+/**
+ * De-allocate all memory used by the ring.
+ *
+ * @param r
+ *   Pointer to ring to created with rte_event_ring_create().
+ *   If r is NULL, no operation is performed.
+ */
+void
+rte_event_ring_free(struct rte_event_ring *r);
+
+/**
  * Create an event ring structure
  *
  * This function allocates memory and initializes an event ring inside that
@@ -288,8 +299,8 @@ rte_event_ring_init(struct rte_event_ring *r, const char *name,
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
 struct rte_event_ring *
-rte_event_ring_create(const char *name, unsigned int count, int socket_id,
-		unsigned int flags);
+rte_event_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags)
+	__rte_malloc __rte_dealloc(rte_event_ring_free, 1);
 
 /**
  * Search for an event ring based on its name
@@ -304,16 +315,6 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
 struct rte_event_ring *
 rte_event_ring_lookup(const char *name);
 
-/**
- * De-allocate all memory used by the ring.
- *
- * @param r
- *   Pointer to ring to created with rte_event_ring_create().
- *   If r is NULL, no operation is performed.
- */
-void
-rte_event_ring_free(struct rte_event_ring *r);
-
 /**
  * Return the size of the event ring.
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 11/15] ring: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (9 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 10/15] eventdev: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 12/15] reorder: " Stephen Hemminger
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Honnappa Nagarahalli, Konstantin Ananyev

Use function attributes to catch cases where ring is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/ring/rte_ring.h | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/lib/ring/rte_ring.h b/lib/ring/rte_ring.h
index 63a71d5871..15340a1981 100644
--- a/lib/ring/rte_ring.h
+++ b/lib/ring/rte_ring.h
@@ -119,6 +119,16 @@ ssize_t rte_ring_get_memsize(unsigned int count);
 int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
 	unsigned int flags);
 
+
+/**
+ * De-allocate all memory used by the ring.
+ *
+ * @param r
+ *   Ring to free.
+ *   If NULL then, the function does nothing.
+ */
+void rte_ring_free(struct rte_ring *r);
+
 /**
  * Create a new ring named *name* in memory.
  *
@@ -183,16 +193,8 @@ int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
-				 int socket_id, unsigned int flags);
-
-/**
- * De-allocate all memory used by the ring.
- *
- * @param r
- *   Ring to free.
- *   If NULL then, the function does nothing.
- */
-void rte_ring_free(struct rte_ring *r);
+				 int socket_id, unsigned int flags)
+	__rte_malloc __rte_dealloc(rte_ring_free, 1);
 
 /**
  * Dump the status of the ring to a file.
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 12/15] reorder: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (10 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 11/15] ring: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-21 12:22   ` [EXTERNAL] " Volodymyr Fialko
  2025-01-20 18:03 ` [PATCH 13/15] compressdev: " Stephen Hemminger
                   ` (4 subsequent siblings)
  16 siblings, 1 reply; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Volodymyr Fialko

Use function attributes to catch cases where reorder table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/reorder/rte_reorder.h | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/reorder/rte_reorder.h b/lib/reorder/rte_reorder.h
index 56a6507f9f..2f26ed7df3 100644
--- a/lib/reorder/rte_reorder.h
+++ b/lib/reorder/rte_reorder.h
@@ -44,6 +44,16 @@ rte_reorder_seqn(struct rte_mbuf *mbuf)
 		rte_reorder_seqn_t *);
 }
 
+/**
+ * Free reorder buffer instance.
+ *
+ * @param b
+ *   Pointer to reorder buffer instance.
+ *   If b is NULL, no operation is performed.
+ */
+void
+rte_reorder_free(struct rte_reorder_buffer *b);
+
 /**
  * Create a new reorder buffer instance
  *
@@ -64,7 +74,8 @@ rte_reorder_seqn(struct rte_mbuf *mbuf)
  *    - EINVAL - invalid parameters
  */
 struct rte_reorder_buffer *
-rte_reorder_create(const char *name, unsigned socket_id, unsigned int size);
+rte_reorder_create(const char *name, unsigned int socket_id, unsigned int size)
+	__rte_malloc __rte_dealloc(rte_reorder_free, 1);
 
 /**
  * Initializes given reorder buffer instance
@@ -111,16 +122,6 @@ rte_reorder_find_existing(const char *name);
 void
 rte_reorder_reset(struct rte_reorder_buffer *b);
 
-/**
- * Free reorder buffer instance.
- *
- * @param b
- *   Pointer to reorder buffer instance.
- *   If b is NULL, no operation is performed.
- */
-void
-rte_reorder_free(struct rte_reorder_buffer *b);
-
 /**
  * Insert given mbuf in reorder buffer in its correct position
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 13/15] compressdev: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (11 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 12/15] reorder: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:03 ` [PATCH 14/15] telemetry: " Stephen Hemminger
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Fan Zhang, Ashish Gupta

Use function attributes to catch cases where compressdev is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/compressdev/rte_comp.h | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/lib/compressdev/rte_comp.h b/lib/compressdev/rte_comp.h
index d66a4b1cb9..f86e773b28 100644
--- a/lib/compressdev/rte_comp.h
+++ b/lib/compressdev/rte_comp.h
@@ -480,6 +480,19 @@ struct __rte_cache_aligned rte_comp_op {
 	 */
 };
 
+
+/**
+ * Free operation structure
+ * If operation has been allocate from a rte_mempool, then the operation will
+ * be returned to the mempool.
+ *
+ * @param op
+ *   Compress operation pointer allocated from rte_comp_op_alloc()
+ *   If op is NULL, no operation is performed.
+ */
+void
+rte_comp_op_free(struct rte_comp_op *op);
+
 /**
  * Creates an operation pool
  *
@@ -501,7 +514,8 @@ struct __rte_cache_aligned rte_comp_op {
 struct rte_mempool *
 rte_comp_op_pool_create(const char *name,
 		unsigned int nb_elts, unsigned int cache_size,
-		uint16_t user_size, int socket_id);
+		uint16_t user_size, int socket_id)
+	__rte_malloc __rte_dealloc(rte_comp_op_free, 1);
 
 /**
  * Allocate an operation from a mempool with default parameters set
@@ -533,18 +547,6 @@ int
 rte_comp_op_bulk_alloc(struct rte_mempool *mempool,
 		struct rte_comp_op **ops, uint16_t nb_ops);
 
-/**
- * Free operation structure
- * If operation has been allocate from a rte_mempool, then the operation will
- * be returned to the mempool.
- *
- * @param op
- *   Compress operation pointer allocated from rte_comp_op_alloc()
- *   If op is NULL, no operation is performed.
- */
-void
-rte_comp_op_free(struct rte_comp_op *op);
-
 /**
  * Bulk free operation structures
  * If operations have been allocated from an rte_mempool, then the operations
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 14/15] telemetry: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (12 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 13/15] compressdev: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:43   ` Bruce Richardson
  2025-01-20 18:03 ` [PATCH 15/15] sched: " Stephen Hemminger
                   ` (2 subsequent siblings)
  16 siblings, 1 reply; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Bruce Richardson

Use function attributes to catch cases where telemetry data
is allocated but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/telemetry/rte_telemetry.h | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h
index 2ccfc73a5f..c4554e4028 100644
--- a/lib/telemetry/rte_telemetry.h
+++ b/lib/telemetry/rte_telemetry.h
@@ -414,16 +414,6 @@ __rte_experimental
 int
 rte_telemetry_register_cmd_arg(const char *cmd, telemetry_arg_cb fn, void *arg, const char *help);
 
-/**
- * Get a pointer to a container with memory allocated. The container is to be
- * used embedded within an existing telemetry dict/array.
- *
- * @return
- *  Pointer to a container.
- */
-struct rte_tel_data *
-rte_tel_data_alloc(void);
-
 /**
  * @internal
  * Free a container that has memory allocated.
@@ -435,6 +425,17 @@ rte_tel_data_alloc(void);
 void
 rte_tel_data_free(struct rte_tel_data *data);
 
+/**
+ * Get a pointer to a container with memory allocated. The container is to be
+ * used embedded within an existing telemetry dict/array.
+ *
+ * @return
+ *  Pointer to a container.
+ */
+struct rte_tel_data *
+rte_tel_data_alloc(void)
+	__rte_malloc __rte_dealloc(rte_tel_data_free, 1);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH 15/15] sched: add allocation function attributes
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (13 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 14/15] telemetry: " Stephen Hemminger
@ 2025-01-20 18:03 ` Stephen Hemminger
  2025-01-20 18:40 ` [PATCH 00/15] Add attributes to allocation functions Bruce Richardson
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
  16 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:03 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Cristian Dumitrescu

Use function attributes to catch cases where sched port config
is allocated but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/sched/rte_sched.h | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lib/sched/rte_sched.h b/lib/sched/rte_sched.h
index 222e6b3583..7ae570aa1b 100644
--- a/lib/sched/rte_sched.h
+++ b/lib/sched/rte_sched.h
@@ -310,16 +310,7 @@ struct rte_sched_port_params {
  * Configuration
  */
 
-/**
- * Hierarchical scheduler port configuration
- *
- * @param params
- *   Port scheduler configuration parameter structure
- * @return
- *   Handle to port scheduler instance upon success or NULL otherwise.
- */
-struct rte_sched_port *
-rte_sched_port_config(struct rte_sched_port_params *params);
+struct rte_sched_port;
 
 /**
  * Hierarchical scheduler port free
@@ -331,6 +322,18 @@ rte_sched_port_config(struct rte_sched_port_params *params);
 void
 rte_sched_port_free(struct rte_sched_port *port);
 
+/**
+ * Hierarchical scheduler port configuration
+ *
+ * @param params
+ *   Port scheduler configuration parameter structure
+ * @return
+ *   Handle to port scheduler instance upon success or NULL otherwise.
+ */
+struct rte_sched_port *
+rte_sched_port_config(struct rte_sched_port_params *params)
+	__rte_malloc __rte_dealloc(rte_sched_port_free, 1);
+
 /**
  * Hierarchical scheduler pipe profile add
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/15] Add attributes to allocation functions
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (14 preceding siblings ...)
  2025-01-20 18:03 ` [PATCH 15/15] sched: " Stephen Hemminger
@ 2025-01-20 18:40 ` Bruce Richardson
  2025-01-20 18:42   ` Stephen Hemminger
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
  16 siblings, 1 reply; 37+ messages in thread
From: Bruce Richardson @ 2025-01-20 18:40 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

On Mon, Jan 20, 2025 at 10:03:18AM -0800, Stephen Hemminger wrote:
> This patch series builds on the allocation function attributes
> added in 24.11 release. These annotations will allow for compiler
> to flag cases where a pointer is allocated with one function
> but incorrectly passed to a different free function.
> 
> Checkpatch perl script falsely complains in a couple patches
> because it doesn't really understand C syntax for attributes.
> 

Looking at the patchset, I see a number of functions moved in files. Is
there a restriction on the placement of the alloc and free functions where
free has to be defined first?

/Bruce

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 00/15] Add attributes to allocation functions
  2025-01-20 18:40 ` [PATCH 00/15] Add attributes to allocation functions Bruce Richardson
@ 2025-01-20 18:42   ` Stephen Hemminger
  0 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-20 18:42 UTC (permalink / raw)
  To: Bruce Richardson; +Cc: dev

On Mon, 20 Jan 2025 18:40:53 +0000
Bruce Richardson <bruce.richardson@intel.com> wrote:

> On Mon, Jan 20, 2025 at 10:03:18AM -0800, Stephen Hemminger wrote:
> > This patch series builds on the allocation function attributes
> > added in 24.11 release. These annotations will allow for compiler
> > to flag cases where a pointer is allocated with one function
> > but incorrectly passed to a different free function.
> > 
> > Checkpatch perl script falsely complains in a couple patches
> > because it doesn't really understand C syntax for attributes.
> >   
> 
> Looking at the patchset, I see a number of functions moved in files. Is
> there a restriction on the placement of the alloc and free functions where
> free has to be defined first?
> 
> /Bruce

Yes the function prototype must be defined before it can be used.

^ permalink raw reply	[flat|nested] 37+ messages in thread

* Re: [PATCH 14/15] telemetry: add allocation function attributes
  2025-01-20 18:03 ` [PATCH 14/15] telemetry: " Stephen Hemminger
@ 2025-01-20 18:43   ` Bruce Richardson
  0 siblings, 0 replies; 37+ messages in thread
From: Bruce Richardson @ 2025-01-20 18:43 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

On Mon, Jan 20, 2025 at 10:03:32AM -0800, Stephen Hemminger wrote:
> Use function attributes to catch cases where telemetry data
> is allocated but not freed correctly.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/telemetry/rte_telemetry.h | 21 +++++++++++----------
>  1 file changed, 11 insertions(+), 10 deletions(-)
> 
Acked-by: Bruce Richardson <bruce.richardson@intel.com>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* RE: [EXTERNAL] [PATCH 12/15] reorder: add allocation function attributes
  2025-01-20 18:03 ` [PATCH 12/15] reorder: " Stephen Hemminger
@ 2025-01-21 12:22   ` Volodymyr Fialko
  0 siblings, 0 replies; 37+ messages in thread
From: Volodymyr Fialko @ 2025-01-21 12:22 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

> Use function attributes to catch cases where reorder table is allocated
> but not freed correctly.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/reorder/rte_reorder.h | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)

Acked-by: Volodymyr Fialko <vfialko@marvell.com>

^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 00/15] Add attributes to allocation functions
  2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
                   ` (15 preceding siblings ...)
  2025-01-20 18:40 ` [PATCH 00/15] Add attributes to allocation functions Bruce Richardson
@ 2025-01-22 17:32 ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 01/15] fib: add allocation function attributes Stephen Hemminger
                     ` (14 more replies)
  16 siblings, 15 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

This patch series builds on the allocation function attributes
added in 24.11 release. These annotations will allow for compiler
to flag cases where a pointer is allocated with one function
but incorrectly passed to a different free function.

The current code base does this correctly now, but adding
attributes will catch future bugs, or errors in user programs.

For each of these patches, the free function prototype
needs to be reordered to be before the function attribute
of the allocator.

Checkpatch perl script falsely complains in a couple patches
because it doesn't really understand C syntax for attributes.

v2 - fix issue with bitratestats prototypes

Stephen Hemminger (15):
  fib: add allocation function attributes
  rib: annotate rib allocation functions
  hash: add allocation function attributes
  lpm: add allocation function attributes
  pipeline: add allocation function attributes
  acl: add allocation function attributes
  bitratestats: add allocation function attributes
  member: add allocation function attributes
  mempool: add allocation function attributes
  eventdev: add allocation function attributes
  ring: add allocation function attributes
  reorder: add allocation function attributes
  compressdev: add allocation function attributes
  telemetry: add allocation function attributes
  sched: add allocation function attributes

 lib/acl/rte_acl.h                 | 26 ++++++++-------
 lib/bitratestats/rte_bitrate.h    |  4 +--
 lib/compressdev/rte_comp.h        | 28 ++++++++--------
 lib/eventdev/rte_event_ring.h     | 27 +++++++--------
 lib/fib/rte_fib.h                 | 26 ++++++++-------
 lib/fib/rte_fib6.h                | 24 +++++++-------
 lib/fib/trie.h                    |  7 ++--
 lib/hash/rte_fbk_hash.h           | 24 +++++++-------
 lib/hash/rte_hash.h               | 21 ++++++------
 lib/lpm/rte_lpm.h                 | 23 ++++++-------
 lib/lpm/rte_lpm6.h                | 23 ++++++-------
 lib/member/rte_member.h           | 24 +++++++-------
 lib/mempool/rte_mempool.h         | 37 +++++++++++----------
 lib/pipeline/rte_port_in_action.h | 55 ++++++++++++++++---------------
 lib/pipeline/rte_table_action.h   | 53 +++++++++++++++--------------
 lib/reorder/rte_reorder.h         | 23 ++++++-------
 lib/rib/rte_rib.h                 | 24 +++++++-------
 lib/rib/rte_rib6.h                | 24 +++++++-------
 lib/ring/rte_ring.h               | 22 +++++++------
 lib/sched/rte_sched.h             | 23 +++++++------
 lib/telemetry/rte_telemetry.h     | 21 ++++++------
 21 files changed, 288 insertions(+), 251 deletions(-)

-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 01/15] fib: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 02/15] rib: annotate rib allocation functions Stephen Hemminger
                     ` (13 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Vladimir Medvedkin

Use function attributes to catch cases where fib table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/fib/rte_fib.h  | 26 +++++++++++++++-----------
 lib/fib/rte_fib6.h | 24 +++++++++++++-----------
 lib/fib/trie.h     |  7 ++++---
 3 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/lib/fib/rte_fib.h b/lib/fib/rte_fib.h
index 496d137d48..65c24d5459 100644
--- a/lib/fib/rte_fib.h
+++ b/lib/fib/rte_fib.h
@@ -17,8 +17,10 @@
 
 #include <stdint.h>
 
+#include <rte_common.h>
 #include <rte_rcu_qsbr.h>
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -128,6 +130,17 @@ struct rte_fib_rcu_config {
 	uint32_t reclaim_max;
 };
 
+
+/**
+ * Free an FIB object.
+ *
+ * @param fib
+ *   FIB object handle created by rte_fib_create().
+ *   If fib is NULL, no operation is performed.
+ */
+void
+rte_fib_free(struct rte_fib *fib);
+
 /**
  * Create FIB
  *
@@ -142,7 +155,8 @@ struct rte_fib_rcu_config {
  *  NULL otherwise with rte_errno set to an appropriate values.
  */
 struct rte_fib *
-rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf);
+rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf)
+	__rte_malloc __rte_dealloc(rte_fib_free, 1);
 
 /**
  * Find an existing FIB object and return a pointer to it.
@@ -157,16 +171,6 @@ rte_fib_create(const char *name, int socket_id, struct rte_fib_conf *conf);
 struct rte_fib *
 rte_fib_find_existing(const char *name);
 
-/**
- * Free an FIB object.
- *
- * @param fib
- *   FIB object handle created by rte_fib_create().
- *   If fib is NULL, no operation is performed.
- */
-void
-rte_fib_free(struct rte_fib *fib);
-
 /**
  * Add a route to the FIB.
  *
diff --git a/lib/fib/rte_fib6.h b/lib/fib/rte_fib6.h
index 21f0492374..b03b24421c 100644
--- a/lib/fib/rte_fib6.h
+++ b/lib/fib/rte_fib6.h
@@ -82,6 +82,17 @@ struct rte_fib6_conf {
 	};
 };
 
+
+/**
+ * Free an FIB object.
+ *
+ * @param fib
+ *   FIB object handle created by rte_fib6_create().
+ *   If fib is NULL, no operation is performed.
+ */
+void
+rte_fib6_free(struct rte_fib6 *fib);
+
 /**
  * Create FIB
  *
@@ -96,7 +107,8 @@ struct rte_fib6_conf {
  *  NULL otherwise with rte_errno set to an appropriate values.
  */
 struct rte_fib6 *
-rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
+rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf)
+	__rte_malloc __rte_dealloc(rte_fib6_free, 1);
 
 /**
  * Find an existing FIB object and return a pointer to it.
@@ -111,16 +123,6 @@ rte_fib6_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
 struct rte_fib6 *
 rte_fib6_find_existing(const char *name);
 
-/**
- * Free an FIB object.
- *
- * @param fib
- *   FIB object handle created by rte_fib6_create().
- *   If fib is NULL, no operation is performed.
- */
-void
-rte_fib6_free(struct rte_fib6 *fib);
-
 /**
  * Add a route to the FIB.
  *
diff --git a/lib/fib/trie.h b/lib/fib/trie.h
index f87fc0f6d2..bcb161702b 100644
--- a/lib/fib/trie.h
+++ b/lib/fib/trie.h
@@ -129,12 +129,13 @@ LOOKUP_FUNC(2b, uint16_t, 1)
 LOOKUP_FUNC(4b, uint32_t, 2)
 LOOKUP_FUNC(8b, uint64_t, 3)
 
-void *
-trie_create(const char *name, int socket_id, struct rte_fib6_conf *conf);
-
 void
 trie_free(void *p);
 
+void *
+trie_create(const char *name, int socket_id, struct rte_fib6_conf *conf)
+	__rte_malloc __rte_dealloc(trie_free, 1);
+
 rte_fib6_lookup_fn_t
 trie_get_lookup_fn(void *p, enum rte_fib6_lookup_type type);
 
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 02/15] rib: annotate rib allocation functions
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 01/15] fib: add allocation function attributes Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 03/15] hash: add allocation function attributes Stephen Hemminger
                     ` (12 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Vladimir Medvedkin

Add function attributes to catch cases where rib is allocated
and not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/rib/rte_rib.h  | 24 +++++++++++++-----------
 lib/rib/rte_rib6.h | 24 +++++++++++++-----------
 2 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/lib/rib/rte_rib.h b/lib/rib/rte_rib.h
index 2054d3cebd..f30b85d79a 100644
--- a/lib/rib/rte_rib.h
+++ b/lib/rib/rte_rib.h
@@ -230,6 +230,17 @@ rte_rib_get_nh(const struct rte_rib_node *node, uint64_t *nh);
 int
 rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
 
+
+/**
+ * Free an RIB object.
+ *
+ * @param rib
+ *   RIB object handle created with rte_rib_create().
+ *   If rib is NULL, no operation is performed.
+ */
+void
+rte_rib_free(struct rte_rib *rib);
+
 /**
  * Create RIB
  *
@@ -245,7 +256,8 @@ rte_rib_set_nh(struct rte_rib_node *node, uint64_t nh);
  */
 struct rte_rib *
 rte_rib_create(const char *name, int socket_id,
-	       const struct rte_rib_conf *conf);
+	       const struct rte_rib_conf *conf)
+	__rte_malloc __rte_dealloc(rte_rib_free, 1);
 
 /**
  * Find an existing RIB object and return a pointer to it.
@@ -259,16 +271,6 @@ rte_rib_create(const char *name, int socket_id,
 struct rte_rib *
 rte_rib_find_existing(const char *name);
 
-/**
- * Free an RIB object.
- *
- * @param rib
- *   RIB object handle created with rte_rib_create().
- *   If rib is NULL, no operation is performed.
- */
-void
-rte_rib_free(struct rte_rib *rib);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/rib/rte_rib6.h b/lib/rib/rte_rib6.h
index a60756f798..d9514acf82 100644
--- a/lib/rib/rte_rib6.h
+++ b/lib/rib/rte_rib6.h
@@ -294,6 +294,17 @@ rte_rib6_get_nh(const struct rte_rib6_node *node, uint64_t *nh);
 int
 rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh);
 
+
+/**
+ * Free an RIB object.
+ *
+ * @param rib
+ *   RIB object handle created with rte_rib6_create().
+ *   If rib is NULL, no operation is performed.
+ */
+void
+rte_rib6_free(struct rte_rib6 *rib);
+
 /**
  * Create RIB
  *
@@ -309,7 +320,8 @@ rte_rib6_set_nh(struct rte_rib6_node *node, uint64_t nh);
  */
 struct rte_rib6 *
 rte_rib6_create(const char *name, int socket_id,
-		const struct rte_rib6_conf *conf);
+		const struct rte_rib6_conf *conf)
+	__rte_malloc __rte_dealloc(rte_rib6_free, 1);
 
 /**
  * Find an existing RIB object and return a pointer to it.
@@ -323,16 +335,6 @@ rte_rib6_create(const char *name, int socket_id,
 struct rte_rib6 *
 rte_rib6_find_existing(const char *name);
 
-/**
- * Free an RIB object.
- *
- * @param rib
- *   RIB object handle created with rte_rib6_create().
- *   If rib is NULL, no operation is performed.
- */
-void
-rte_rib6_free(struct rte_rib6 *rib);
-
 #ifdef __cplusplus
 }
 #endif
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 03/15] hash: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 01/15] fib: add allocation function attributes Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 02/15] rib: annotate rib allocation functions Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 04/15] lpm: " Stephen Hemminger
                     ` (11 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Yipeng Wang, Sameh Gobriel, Bruce Richardson,
	Vladimir Medvedkin

Use function attributes to catch cases where hash table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/hash/rte_fbk_hash.h | 24 +++++++++++++-----------
 lib/hash/rte_hash.h     | 21 +++++++++++----------
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/lib/hash/rte_fbk_hash.h b/lib/hash/rte_fbk_hash.h
index 1f0c1d1b6c..b1a43f37b4 100644
--- a/lib/hash/rte_fbk_hash.h
+++ b/lib/hash/rte_fbk_hash.h
@@ -322,6 +322,16 @@ rte_fbk_hash_get_load_factor(struct rte_fbk_hash_table *ht)
  */
 struct rte_fbk_hash_table *rte_fbk_hash_find_existing(const char *name);
 
+
+/**
+ * Free all memory used by a hash table.
+ * Has no effect on hash tables allocated in memory zones
+ *
+ * @param ht
+ *   Hash table to deallocate.
+ */
+void rte_fbk_hash_free(struct rte_fbk_hash_table *ht);
+
 /**
  * Create a new hash table for use with four byte keys.
  *
@@ -339,17 +349,9 @@ struct rte_fbk_hash_table *rte_fbk_hash_find_existing(const char *name);
  *    - EEXIST - a memzone with the same name already exists
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
-struct rte_fbk_hash_table * \
-rte_fbk_hash_create(const struct rte_fbk_hash_params *params);
-
-/**
- * Free all memory used by a hash table.
- * Has no effect on hash tables allocated in memory zones
- *
- * @param ht
- *   Hash table to deallocate.
- */
-void rte_fbk_hash_free(struct rte_fbk_hash_table *ht);
+struct rte_fbk_hash_table *
+rte_fbk_hash_create(const struct rte_fbk_hash_params *params)
+	__rte_malloc __rte_dealloc(rte_fbk_hash_free, 1);
 
 #ifdef __cplusplus
 }
diff --git a/lib/hash/rte_hash.h b/lib/hash/rte_hash.h
index 05ab447e4a..736fb15885 100644
--- a/lib/hash/rte_hash.h
+++ b/lib/hash/rte_hash.h
@@ -125,6 +125,15 @@ struct rte_hash_rcu_config {
 /** @internal A hash table structure. */
 struct rte_hash;
 
+/**
+ * De-allocate all memory used by hash table.
+ *
+ * @param h
+ *   Hash table to free, if NULL, the function does nothing.
+ */
+void
+rte_hash_free(struct rte_hash *h);
+
 /**
  * Create a new hash table.
  *
@@ -143,7 +152,8 @@ struct rte_hash;
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
 struct rte_hash *
-rte_hash_create(const struct rte_hash_parameters *params);
+rte_hash_create(const struct rte_hash_parameters *params)
+	__rte_malloc __rte_dealloc(rte_hash_free, 1);
 
 /**
  * Set a new hash compare function other than the default one.
@@ -171,15 +181,6 @@ void rte_hash_set_cmp_func(struct rte_hash *h, rte_hash_cmp_eq_t func);
 struct rte_hash *
 rte_hash_find_existing(const char *name);
 
-/**
- * De-allocate all memory used by hash table.
- *
- * @param h
- *   Hash table to free, if NULL, the function does nothing.
- */
-void
-rte_hash_free(struct rte_hash *h);
-
 /**
  * Reset all hash structure, by zeroing all entries.
  * When RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF is enabled,
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 04/15] lpm: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (2 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 03/15] hash: add allocation function attributes Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 05/15] pipeline: " Stephen Hemminger
                     ` (10 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Bruce Richardson, Vladimir Medvedkin

Use function attributes to catch cases where lpm table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/lpm/rte_lpm.h  | 23 ++++++++++++-----------
 lib/lpm/rte_lpm6.h | 23 ++++++++++++-----------
 2 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/lib/lpm/rte_lpm.h b/lib/lpm/rte_lpm.h
index 329dc1aad4..7df64f06b1 100644
--- a/lib/lpm/rte_lpm.h
+++ b/lib/lpm/rte_lpm.h
@@ -140,6 +140,16 @@ struct rte_lpm_rcu_config {
 				 */
 };
 
+/**
+ * Free an LPM object.
+ *
+ * @param lpm
+ *   LPM object handle
+ *   If lpm is NULL, no operation is performed.
+ */
+void
+rte_lpm_free(struct rte_lpm *lpm);
+
 /**
  * Create an LPM object.
  *
@@ -161,7 +171,8 @@ struct rte_lpm_rcu_config {
  */
 struct rte_lpm *
 rte_lpm_create(const char *name, int socket_id,
-		const struct rte_lpm_config *config);
+	       const struct rte_lpm_config *config)
+	__rte_malloc __rte_dealloc(rte_lpm_free, 1);
 
 /**
  * Find an existing LPM object and return a pointer to it.
@@ -176,16 +187,6 @@ rte_lpm_create(const char *name, int socket_id,
 struct rte_lpm *
 rte_lpm_find_existing(const char *name);
 
-/**
- * Free an LPM object.
- *
- * @param lpm
- *   LPM object handle
- *   If lpm is NULL, no operation is performed.
- */
-void
-rte_lpm_free(struct rte_lpm *lpm);
-
 /**
  * Associate RCU QSBR variable with an LPM object.
  *
diff --git a/lib/lpm/rte_lpm6.h b/lib/lpm/rte_lpm6.h
index 079187ca56..08b5618613 100644
--- a/lib/lpm/rte_lpm6.h
+++ b/lib/lpm/rte_lpm6.h
@@ -34,6 +34,16 @@ struct rte_lpm6_config {
 	int flags;               /**< This field is currently unused. */
 };
 
+/**
+ * Free an LPM object.
+ *
+ * @param lpm
+ *   LPM object handle
+ *   If lpm is NULL, no operation is performed.
+ */
+void
+rte_lpm6_free(struct rte_lpm6 *lpm);
+
 /**
  * Create an LPM object.
  *
@@ -55,7 +65,8 @@ struct rte_lpm6_config {
  */
 struct rte_lpm6 *
 rte_lpm6_create(const char *name, int socket_id,
-		const struct rte_lpm6_config *config);
+		const struct rte_lpm6_config *config)
+	__rte_malloc __rte_dealloc(rte_lpm6_free, 1);
 
 /**
  * Find an existing LPM object and return a pointer to it.
@@ -70,16 +81,6 @@ rte_lpm6_create(const char *name, int socket_id,
 struct rte_lpm6 *
 rte_lpm6_find_existing(const char *name);
 
-/**
- * Free an LPM object.
- *
- * @param lpm
- *   LPM object handle
- *   If lpm is NULL, no operation is performed.
- */
-void
-rte_lpm6_free(struct rte_lpm6 *lpm);
-
 /**
  * Add a rule to the LPM table.
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 05/15] pipeline: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (3 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 04/15] lpm: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 06/15] acl: " Stephen Hemminger
                     ` (9 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Cristian Dumitrescu

Use function attributes to catch cases where pipeline is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/pipeline/rte_port_in_action.h | 55 ++++++++++++++++---------------
 lib/pipeline/rte_table_action.h   | 53 +++++++++++++++--------------
 2 files changed, 56 insertions(+), 52 deletions(-)

diff --git a/lib/pipeline/rte_port_in_action.h b/lib/pipeline/rte_port_in_action.h
index 9d17bae988..ee6cc59fae 100644
--- a/lib/pipeline/rte_port_in_action.h
+++ b/lib/pipeline/rte_port_in_action.h
@@ -164,18 +164,6 @@ struct rte_port_in_action_lb_params {
  */
 struct rte_port_in_action_profile;
 
-/**
- * Input port action profile create.
- *
- * @param[in] socket_id
- *   CPU socket ID for the internal data structures memory allocation.
- * @return
- *   Input port action profile handle on success, NULL otherwise.
- */
-__rte_experimental
-struct rte_port_in_action_profile *
-rte_port_in_action_profile_create(uint32_t socket_id);
-
 /**
  * Input port action profile free.
  *
@@ -189,6 +177,19 @@ __rte_experimental
 int
 rte_port_in_action_profile_free(struct rte_port_in_action_profile *profile);
 
+/**
+ * Input port action profile create.
+ *
+ * @param[in] socket_id
+ *   CPU socket ID for the internal data structures memory allocation.
+ * @return
+ *   Input port action profile handle on success, NULL otherwise.
+ */
+__rte_experimental
+struct rte_port_in_action_profile *
+rte_port_in_action_profile_create(uint32_t socket_id)
+	__rte_malloc __rte_dealloc(rte_port_in_action_profile_free, 1);
+
 /**
  * Input port action profile action register.
  *
@@ -236,6 +237,19 @@ rte_port_in_action_profile_freeze(struct rte_port_in_action_profile *profile);
  */
 struct rte_port_in_action;
 
+/**
+ * Input port action free.
+ *
+ * @param[in] action
+ *   Handle to input port action object (needs to be valid).
+ *   If action is NULL, no operation is performed.
+ * @return
+ *   Always zero.
+ */
+__rte_experimental
+int
+rte_port_in_action_free(struct rte_port_in_action *action);
+
 /**
  * Input port action create.
  *
@@ -252,21 +266,8 @@ struct rte_port_in_action;
  */
 __rte_experimental
 struct rte_port_in_action *
-rte_port_in_action_create(struct rte_port_in_action_profile *profile,
-	uint32_t socket_id);
-
-/**
- * Input port action free.
- *
- * @param[in] action
- *   Handle to input port action object (needs to be valid).
- *   If action is NULL, no operation is performed.
- * @return
- *   Always zero.
- */
-__rte_experimental
-int
-rte_port_in_action_free(struct rte_port_in_action *action);
+rte_port_in_action_create(struct rte_port_in_action_profile *profile, uint32_t socket_id)
+	__rte_malloc __rte_dealloc(rte_port_in_action_free, 1);
 
 /**
  * Input port params get.
diff --git a/lib/pipeline/rte_table_action.h b/lib/pipeline/rte_table_action.h
index 47a7bdfc01..e8b4d8b33d 100644
--- a/lib/pipeline/rte_table_action.h
+++ b/lib/pipeline/rte_table_action.h
@@ -54,6 +54,7 @@
 
 #include <stdint.h>
 
+#include <rte_common.h>
 #include <rte_compat.h>
 #include <rte_ether.h>
 #include <rte_ip6.h>
@@ -812,17 +813,6 @@ struct rte_table_action_decap_params {
  */
 struct rte_table_action_profile;
 
-/**
- * Table action profile create.
- *
- * @param[in] common
- *   Common action configuration.
- * @return
- *   Table action profile handle on success, NULL otherwise.
- */
-__rte_experimental
-struct rte_table_action_profile *
-rte_table_action_profile_create(struct rte_table_action_common_config *common);
 
 /**
  * Table action profile free.
@@ -836,6 +826,19 @@ __rte_experimental
 int
 rte_table_action_profile_free(struct rte_table_action_profile *profile);
 
+/**
+ * Table action profile create.
+ *
+ * @param[in] common
+ *   Common action configuration.
+ * @return
+ *   Table action profile handle on success, NULL otherwise.
+ */
+__rte_experimental
+struct rte_table_action_profile *
+rte_table_action_profile_create(struct rte_table_action_common_config *common)
+	__rte_malloc __rte_dealloc(rte_table_action_profile_free, 1);
+
 /**
  * Table action profile action register.
  *
@@ -881,6 +884,18 @@ rte_table_action_profile_freeze(struct rte_table_action_profile *profile);
  */
 struct rte_table_action;
 
+/**
+ * Table action free.
+ *
+ * @param[in] action
+ *   Handle to table action object (needs to be valid).
+ * @return
+ *   Zero on success, non-zero error code otherwise.
+ */
+__rte_experimental
+int
+rte_table_action_free(struct rte_table_action *action);
+
 /**
  * Table action create.
  *
@@ -898,20 +913,8 @@ struct rte_table_action;
  */
 __rte_experimental
 struct rte_table_action *
-rte_table_action_create(struct rte_table_action_profile *profile,
-	uint32_t socket_id);
-
-/**
- * Table action free.
- *
- * @param[in] action
- *   Handle to table action object (needs to be valid).
- * @return
- *   Zero on success, non-zero error code otherwise.
- */
-__rte_experimental
-int
-rte_table_action_free(struct rte_table_action *action);
+rte_table_action_create(struct rte_table_action_profile *profile, uint32_t socket_id)
+	__rte_malloc __rte_dealloc(rte_table_action_free, 1);
 
 /**
  * Table action table params get.
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 06/15] acl: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (4 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 05/15] pipeline: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 07/15] bitratestats: " Stephen Hemminger
                     ` (8 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev

Use function attributes to catch cases where acl table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/acl/rte_acl.h | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/acl/rte_acl.h b/lib/acl/rte_acl.h
index ca75a6f220..b95f8778c3 100644
--- a/lib/acl/rte_acl.h
+++ b/lib/acl/rte_acl.h
@@ -133,6 +133,19 @@ struct rte_acl_param {
 };
 
 
+/** @internal opaque ACL handle */
+struct rte_acl_ctx;
+
+/**
+ * De-allocate all memory used by ACL context.
+ *
+ * @param ctx
+ *   ACL context to free
+ *   If ctx is NULL, no operation is performed.
+ */
+void
+rte_acl_free(struct rte_acl_ctx *ctx);
+
 /**
  * Create a new ACL context.
  *
@@ -145,7 +158,8 @@ struct rte_acl_param {
  *   - EINVAL - invalid parameter passed to function
  */
 struct rte_acl_ctx *
-rte_acl_create(const struct rte_acl_param *param);
+rte_acl_create(const struct rte_acl_param *param)
+	__rte_malloc __rte_dealloc(rte_acl_free, 1);
 
 /**
  * Find an existing ACL context object and return a pointer to it.
@@ -160,16 +174,6 @@ rte_acl_create(const struct rte_acl_param *param);
 struct rte_acl_ctx *
 rte_acl_find_existing(const char *name);
 
-/**
- * De-allocate all memory used by ACL context.
- *
- * @param ctx
- *   ACL context to free
- *   If ctx is NULL, no operation is performed.
- */
-void
-rte_acl_free(struct rte_acl_ctx *ctx);
-
 /**
  * Add rules to an existing ACL context.
  * This function is not multi-thread safe.
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 07/15] bitratestats: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (5 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 06/15] acl: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 08/15] member: " Stephen Hemminger
                     ` (7 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

Use function attributes to catch cases where bitratestats is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/bitratestats/rte_bitrate.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/bitratestats/rte_bitrate.h b/lib/bitratestats/rte_bitrate.h
index 979a712837..0cd3a6227c 100644
--- a/lib/bitratestats/rte_bitrate.h
+++ b/lib/bitratestats/rte_bitrate.h
@@ -17,7 +17,6 @@ extern "C" {
  */
 struct rte_stats_bitrates;
 
-
 /**
  * Allocate a bitrate statistics structure
  *
@@ -25,7 +24,8 @@ struct rte_stats_bitrates;
  *   - Pointer to structure on success
  *   - NULL on error (zmalloc failure)
  */
-struct rte_stats_bitrates *rte_stats_bitrate_create(void);
+struct rte_stats_bitrates *rte_stats_bitrate_create(void)
+	__rte_malloc __rte_dealloc(rte_stats_bitrate_free, 1);
 
 /**
  * Free bitrate statistics structure
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 08/15] member: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (6 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 07/15] bitratestats: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 09/15] mempool: " Stephen Hemminger
                     ` (6 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Yipeng Wang, Sameh Gobriel

Use function attributes to catch cases where member table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/member/rte_member.h | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/member/rte_member.h b/lib/member/rte_member.h
index 109bdd000b..0235bb0a81 100644
--- a/lib/member/rte_member.h
+++ b/lib/member/rte_member.h
@@ -341,6 +341,16 @@ struct __rte_cache_aligned rte_member_parameters {
 struct rte_member_setsum *
 rte_member_find_existing(const char *name);
 
+/**
+ * De-allocate memory used by set-summary.
+ *
+ * @param setsum
+ *   Pointer to the set summary.
+ *   If setsum is NULL, no operation is performed.
+ */
+void
+rte_member_free(struct rte_member_setsum *setsum);
+
 /**
  * Create set-summary (SS).
  *
@@ -351,7 +361,8 @@ rte_member_find_existing(const char *name);
  *   Return value is NULL if the creation failed.
  */
 struct rte_member_setsum *
-rte_member_create(const struct rte_member_parameters *params);
+rte_member_create(const struct rte_member_parameters *params)
+	__rte_malloc __rte_dealloc(rte_member_free, 1);
 
 /**
  * Lookup key in set-summary (SS).
@@ -528,17 +539,6 @@ int
 rte_member_report_heavyhitter(const struct rte_member_setsum *setsum,
 			      void **keys, uint64_t *counts);
 
-
-/**
- * De-allocate memory used by set-summary.
- *
- * @param setsum
- *   Pointer to the set summary.
- *   If setsum is NULL, no operation is performed.
- */
-void
-rte_member_free(struct rte_member_setsum *setsum);
-
 /**
  * Reset the set-summary tables. E.g. reset bits to be 0 in BF,
  * reset set_id in each entry to be RTE_MEMBER_NO_MATCH in HT based SS.
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 09/15] mempool: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (7 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 08/15] member: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 20:17     ` Morten Brørup
  2025-01-22 17:32   ` [PATCH v2 10/15] eventdev: " Stephen Hemminger
                     ` (5 subsequent siblings)
  14 siblings, 1 reply; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Andrew Rybchenko, Morten Brørup

Use function attributes to catch cases where mempool is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/mempool/rte_mempool.h | 37 ++++++++++++++++++++-----------------
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/lib/mempool/rte_mempool.h b/lib/mempool/rte_mempool.h
index 7bdc92b812..c495cc012f 100644
--- a/lib/mempool/rte_mempool.h
+++ b/lib/mempool/rte_mempool.h
@@ -1012,6 +1012,20 @@ typedef void (rte_mempool_mem_cb_t)(struct rte_mempool *mp,
  */
 typedef void (rte_mempool_ctor_t)(struct rte_mempool *, void *);
 
+/**
+ * Free a mempool
+ *
+ * Unlink the mempool from global list, free the memory chunks, and all
+ * memory referenced by the mempool. The objects must not be used by
+ * other cores as they will be freed.
+ *
+ * @param mp
+ *   A pointer to the mempool structure.
+ *   If NULL then, the function does nothing.
+ */
+void
+rte_mempool_free(struct rte_mempool *mp);
+
 /**
  * Create a new mempool named *name* in memory.
  *
@@ -1095,7 +1109,8 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
 		   unsigned cache_size, unsigned private_data_size,
 		   rte_mempool_ctor_t *mp_init, void *mp_init_arg,
 		   rte_mempool_obj_cb_t *obj_init, void *obj_init_arg,
-		   int socket_id, unsigned flags);
+		   int socket_id, unsigned int flags)
+	__rte_malloc __rte_dealloc(rte_mempool_free, 1);
 
 /**
  * Create an empty mempool
@@ -1132,22 +1147,10 @@ rte_mempool_create(const char *name, unsigned n, unsigned elt_size,
  *   with rte_errno set appropriately. See rte_mempool_create() for details.
  */
 struct rte_mempool *
-rte_mempool_create_empty(const char *name, unsigned n, unsigned elt_size,
-	unsigned cache_size, unsigned private_data_size,
-	int socket_id, unsigned flags);
-/**
- * Free a mempool
- *
- * Unlink the mempool from global list, free the memory chunks, and all
- * memory referenced by the mempool. The objects must not be used by
- * other cores as they will be freed.
- *
- * @param mp
- *   A pointer to the mempool structure.
- *   If NULL then, the function does nothing.
- */
-void
-rte_mempool_free(struct rte_mempool *mp);
+rte_mempool_create_empty(const char *name, unsigned int n, unsigned int elt_size,
+			 unsigned int cache_size, unsigned int private_data_size,
+			 int socket_id, unsigned int flags)
+		__rte_malloc __rte_dealloc(rte_mempool_free, 1);
 
 /**
  * Add physically contiguous memory for objects in the pool at init
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 10/15] eventdev: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (8 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 09/15] mempool: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 11/15] ring: " Stephen Hemminger
                     ` (4 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Jerin Jacob

Use function attributes to catch cases where eventdev is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eventdev/rte_event_ring.h | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/lib/eventdev/rte_event_ring.h b/lib/eventdev/rte_event_ring.h
index 5769da269e..a8f308e4d6 100644
--- a/lib/eventdev/rte_event_ring.h
+++ b/lib/eventdev/rte_event_ring.h
@@ -247,7 +247,18 @@ int
 rte_event_ring_init(struct rte_event_ring *r, const char *name,
 	unsigned int count, unsigned int flags);
 
-/*
+
+/**
+ * De-allocate all memory used by the ring.
+ *
+ * @param r
+ *   Pointer to ring to created with rte_event_ring_create().
+ *   If r is NULL, no operation is performed.
+ */
+void
+rte_event_ring_free(struct rte_event_ring *r);
+
+/**
  * Create an event ring structure
  *
  * This function allocates memory and initializes an event ring inside that
@@ -288,8 +299,8 @@ rte_event_ring_init(struct rte_event_ring *r, const char *name,
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
 struct rte_event_ring *
-rte_event_ring_create(const char *name, unsigned int count, int socket_id,
-		unsigned int flags);
+rte_event_ring_create(const char *name, unsigned int count, int socket_id, unsigned int flags)
+	__rte_malloc __rte_dealloc(rte_event_ring_free, 1);
 
 /**
  * Search for an event ring based on its name
@@ -304,16 +315,6 @@ rte_event_ring_create(const char *name, unsigned int count, int socket_id,
 struct rte_event_ring *
 rte_event_ring_lookup(const char *name);
 
-/**
- * De-allocate all memory used by the ring.
- *
- * @param r
- *   Pointer to ring to created with rte_event_ring_create().
- *   If r is NULL, no operation is performed.
- */
-void
-rte_event_ring_free(struct rte_event_ring *r);
-
 /**
  * Return the size of the event ring.
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 11/15] ring: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (9 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 10/15] eventdev: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 12/15] reorder: " Stephen Hemminger
                     ` (3 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Honnappa Nagarahalli, Konstantin Ananyev

Use function attributes to catch cases where ring is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/ring/rte_ring.h | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/lib/ring/rte_ring.h b/lib/ring/rte_ring.h
index 63a71d5871..15340a1981 100644
--- a/lib/ring/rte_ring.h
+++ b/lib/ring/rte_ring.h
@@ -119,6 +119,16 @@ ssize_t rte_ring_get_memsize(unsigned int count);
 int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
 	unsigned int flags);
 
+
+/**
+ * De-allocate all memory used by the ring.
+ *
+ * @param r
+ *   Ring to free.
+ *   If NULL then, the function does nothing.
+ */
+void rte_ring_free(struct rte_ring *r);
+
 /**
  * Create a new ring named *name* in memory.
  *
@@ -183,16 +193,8 @@ int rte_ring_init(struct rte_ring *r, const char *name, unsigned int count,
  *    - ENOMEM - no appropriate memory area found in which to create memzone
  */
 struct rte_ring *rte_ring_create(const char *name, unsigned int count,
-				 int socket_id, unsigned int flags);
-
-/**
- * De-allocate all memory used by the ring.
- *
- * @param r
- *   Ring to free.
- *   If NULL then, the function does nothing.
- */
-void rte_ring_free(struct rte_ring *r);
+				 int socket_id, unsigned int flags)
+	__rte_malloc __rte_dealloc(rte_ring_free, 1);
 
 /**
  * Dump the status of the ring to a file.
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 12/15] reorder: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (10 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 11/15] ring: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 13/15] compressdev: " Stephen Hemminger
                     ` (2 subsequent siblings)
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Volodymyr Fialko

Use function attributes to catch cases where reorder table is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Volodymyr Fialko <vfialko@marvell.com>
---
 lib/reorder/rte_reorder.h | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/lib/reorder/rte_reorder.h b/lib/reorder/rte_reorder.h
index 56a6507f9f..2f26ed7df3 100644
--- a/lib/reorder/rte_reorder.h
+++ b/lib/reorder/rte_reorder.h
@@ -44,6 +44,16 @@ rte_reorder_seqn(struct rte_mbuf *mbuf)
 		rte_reorder_seqn_t *);
 }
 
+/**
+ * Free reorder buffer instance.
+ *
+ * @param b
+ *   Pointer to reorder buffer instance.
+ *   If b is NULL, no operation is performed.
+ */
+void
+rte_reorder_free(struct rte_reorder_buffer *b);
+
 /**
  * Create a new reorder buffer instance
  *
@@ -64,7 +74,8 @@ rte_reorder_seqn(struct rte_mbuf *mbuf)
  *    - EINVAL - invalid parameters
  */
 struct rte_reorder_buffer *
-rte_reorder_create(const char *name, unsigned socket_id, unsigned int size);
+rte_reorder_create(const char *name, unsigned int socket_id, unsigned int size)
+	__rte_malloc __rte_dealloc(rte_reorder_free, 1);
 
 /**
  * Initializes given reorder buffer instance
@@ -111,16 +122,6 @@ rte_reorder_find_existing(const char *name);
 void
 rte_reorder_reset(struct rte_reorder_buffer *b);
 
-/**
- * Free reorder buffer instance.
- *
- * @param b
- *   Pointer to reorder buffer instance.
- *   If b is NULL, no operation is performed.
- */
-void
-rte_reorder_free(struct rte_reorder_buffer *b);
-
 /**
  * Insert given mbuf in reorder buffer in its correct position
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 13/15] compressdev: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (11 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 12/15] reorder: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 14/15] telemetry: " Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 15/15] sched: " Stephen Hemminger
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Fan Zhang, Ashish Gupta

Use function attributes to catch cases where compressdev is allocated
but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/compressdev/rte_comp.h | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/lib/compressdev/rte_comp.h b/lib/compressdev/rte_comp.h
index d66a4b1cb9..f86e773b28 100644
--- a/lib/compressdev/rte_comp.h
+++ b/lib/compressdev/rte_comp.h
@@ -480,6 +480,19 @@ struct __rte_cache_aligned rte_comp_op {
 	 */
 };
 
+
+/**
+ * Free operation structure
+ * If operation has been allocate from a rte_mempool, then the operation will
+ * be returned to the mempool.
+ *
+ * @param op
+ *   Compress operation pointer allocated from rte_comp_op_alloc()
+ *   If op is NULL, no operation is performed.
+ */
+void
+rte_comp_op_free(struct rte_comp_op *op);
+
 /**
  * Creates an operation pool
  *
@@ -501,7 +514,8 @@ struct __rte_cache_aligned rte_comp_op {
 struct rte_mempool *
 rte_comp_op_pool_create(const char *name,
 		unsigned int nb_elts, unsigned int cache_size,
-		uint16_t user_size, int socket_id);
+		uint16_t user_size, int socket_id)
+	__rte_malloc __rte_dealloc(rte_comp_op_free, 1);
 
 /**
  * Allocate an operation from a mempool with default parameters set
@@ -533,18 +547,6 @@ int
 rte_comp_op_bulk_alloc(struct rte_mempool *mempool,
 		struct rte_comp_op **ops, uint16_t nb_ops);
 
-/**
- * Free operation structure
- * If operation has been allocate from a rte_mempool, then the operation will
- * be returned to the mempool.
- *
- * @param op
- *   Compress operation pointer allocated from rte_comp_op_alloc()
- *   If op is NULL, no operation is performed.
- */
-void
-rte_comp_op_free(struct rte_comp_op *op);
-
 /**
  * Bulk free operation structures
  * If operations have been allocated from an rte_mempool, then the operations
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 14/15] telemetry: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (12 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 13/15] compressdev: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  2025-01-22 17:32   ` [PATCH v2 15/15] sched: " Stephen Hemminger
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Bruce Richardson

Use function attributes to catch cases where telemetry data
is allocated but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/telemetry/rte_telemetry.h | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/telemetry/rte_telemetry.h b/lib/telemetry/rte_telemetry.h
index 2ccfc73a5f..c4554e4028 100644
--- a/lib/telemetry/rte_telemetry.h
+++ b/lib/telemetry/rte_telemetry.h
@@ -414,16 +414,6 @@ __rte_experimental
 int
 rte_telemetry_register_cmd_arg(const char *cmd, telemetry_arg_cb fn, void *arg, const char *help);
 
-/**
- * Get a pointer to a container with memory allocated. The container is to be
- * used embedded within an existing telemetry dict/array.
- *
- * @return
- *  Pointer to a container.
- */
-struct rte_tel_data *
-rte_tel_data_alloc(void);
-
 /**
  * @internal
  * Free a container that has memory allocated.
@@ -435,6 +425,17 @@ rte_tel_data_alloc(void);
 void
 rte_tel_data_free(struct rte_tel_data *data);
 
+/**
+ * Get a pointer to a container with memory allocated. The container is to be
+ * used embedded within an existing telemetry dict/array.
+ *
+ * @return
+ *  Pointer to a container.
+ */
+struct rte_tel_data *
+rte_tel_data_alloc(void)
+	__rte_malloc __rte_dealloc(rte_tel_data_free, 1);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* [PATCH v2 15/15] sched: add allocation function attributes
  2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
                     ` (13 preceding siblings ...)
  2025-01-22 17:32   ` [PATCH v2 14/15] telemetry: " Stephen Hemminger
@ 2025-01-22 17:32   ` Stephen Hemminger
  14 siblings, 0 replies; 37+ messages in thread
From: Stephen Hemminger @ 2025-01-22 17:32 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Cristian Dumitrescu

Use function attributes to catch cases where sched port config
is allocated but not freed correctly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/sched/rte_sched.h | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lib/sched/rte_sched.h b/lib/sched/rte_sched.h
index 222e6b3583..7ae570aa1b 100644
--- a/lib/sched/rte_sched.h
+++ b/lib/sched/rte_sched.h
@@ -310,16 +310,7 @@ struct rte_sched_port_params {
  * Configuration
  */
 
-/**
- * Hierarchical scheduler port configuration
- *
- * @param params
- *   Port scheduler configuration parameter structure
- * @return
- *   Handle to port scheduler instance upon success or NULL otherwise.
- */
-struct rte_sched_port *
-rte_sched_port_config(struct rte_sched_port_params *params);
+struct rte_sched_port;
 
 /**
  * Hierarchical scheduler port free
@@ -331,6 +322,18 @@ rte_sched_port_config(struct rte_sched_port_params *params);
 void
 rte_sched_port_free(struct rte_sched_port *port);
 
+/**
+ * Hierarchical scheduler port configuration
+ *
+ * @param params
+ *   Port scheduler configuration parameter structure
+ * @return
+ *   Handle to port scheduler instance upon success or NULL otherwise.
+ */
+struct rte_sched_port *
+rte_sched_port_config(struct rte_sched_port_params *params)
+	__rte_malloc __rte_dealloc(rte_sched_port_free, 1);
+
 /**
  * Hierarchical scheduler pipe profile add
  *
-- 
2.45.2


^ permalink raw reply	[flat|nested] 37+ messages in thread

* RE: [PATCH v2 09/15] mempool: add allocation function attributes
  2025-01-22 17:32   ` [PATCH v2 09/15] mempool: " Stephen Hemminger
@ 2025-01-22 20:17     ` Morten Brørup
  0 siblings, 0 replies; 37+ messages in thread
From: Morten Brørup @ 2025-01-22 20:17 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Andrew Rybchenko

> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Wednesday, 22 January 2025 18.33
> 
> Use function attributes to catch cases where mempool is allocated
> but not freed correctly.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>



^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2025-01-22 20:17 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-20 18:03 [PATCH 00/15] Add attributes to allocation functions Stephen Hemminger
2025-01-20 18:03 ` [PATCH 01/15] fib: add allocation function attributes Stephen Hemminger
2025-01-20 18:03 ` [PATCH 02/15] rib: annotate rib allocation functions Stephen Hemminger
2025-01-20 18:03 ` [PATCH 03/15] hash: add allocation function attributes Stephen Hemminger
2025-01-20 18:03 ` [PATCH 04/15] lpm: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 05/15] pipeline: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 06/15] acl: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 07/15] bitratestats: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 08/15] member: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 09/15] mempool: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 10/15] eventdev: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 11/15] ring: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 12/15] reorder: " Stephen Hemminger
2025-01-21 12:22   ` [EXTERNAL] " Volodymyr Fialko
2025-01-20 18:03 ` [PATCH 13/15] compressdev: " Stephen Hemminger
2025-01-20 18:03 ` [PATCH 14/15] telemetry: " Stephen Hemminger
2025-01-20 18:43   ` Bruce Richardson
2025-01-20 18:03 ` [PATCH 15/15] sched: " Stephen Hemminger
2025-01-20 18:40 ` [PATCH 00/15] Add attributes to allocation functions Bruce Richardson
2025-01-20 18:42   ` Stephen Hemminger
2025-01-22 17:32 ` [PATCH v2 " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 01/15] fib: add allocation function attributes Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 02/15] rib: annotate rib allocation functions Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 03/15] hash: add allocation function attributes Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 04/15] lpm: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 05/15] pipeline: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 06/15] acl: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 07/15] bitratestats: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 08/15] member: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 09/15] mempool: " Stephen Hemminger
2025-01-22 20:17     ` Morten Brørup
2025-01-22 17:32   ` [PATCH v2 10/15] eventdev: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 11/15] ring: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 12/15] reorder: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 13/15] compressdev: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 14/15] telemetry: " Stephen Hemminger
2025-01-22 17:32   ` [PATCH v2 15/15] sched: " Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).