From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Yipeng Wang <yipeng1.wang@intel.com>,
Sameh Gobriel <sameh.gobriel@intel.com>,
Bruce Richardson <bruce.richardson@intel.com>,
Vladimir Medvedkin <vladimir.medvedkin@intel.com>
Subject: [PATCH 03/15] hash: add allocation function attributes
Date: Mon, 20 Jan 2025 10:03:21 -0800 [thread overview]
Message-ID: <20250120180550.198121-4-stephen@networkplumber.org> (raw)
In-Reply-To: <20250120180550.198121-1-stephen@networkplumber.org>
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
next prev parent reply other threads:[~2025-01-20 18:06 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-01-20 18:03 ` [PATCH 04/15] lpm: add allocation function attributes 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-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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250120180550.198121-4-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=sameh.gobriel@intel.com \
--cc=vladimir.medvedkin@intel.com \
--cc=yipeng1.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).