From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 17D754611A; Fri, 24 Jan 2025 09:37:33 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EB9A840E11; Fri, 24 Jan 2025 09:37:32 +0100 (CET) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by mails.dpdk.org (Postfix) with ESMTP id E6C47402E9 for ; Fri, 24 Jan 2025 09:37:30 +0100 (CET) Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4YfWQF2F3zz6GDFR; Fri, 24 Jan 2025 16:37:09 +0800 (CST) Received: from frapeml100007.china.huawei.com (unknown [7.182.85.133]) by mail.maildlp.com (Postfix) with ESMTPS id 59990140119; Fri, 24 Jan 2025 16:37:30 +0800 (CST) Received: from frapeml500007.china.huawei.com (7.182.85.172) by frapeml100007.china.huawei.com (7.182.85.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Fri, 24 Jan 2025 09:37:30 +0100 Received: from frapeml500007.china.huawei.com ([7.182.85.172]) by frapeml500007.china.huawei.com ([7.182.85.172]) with mapi id 15.01.2507.039; Fri, 24 Jan 2025 09:37:30 +0100 From: Konstantin Ananyev To: Stephen Hemminger , "dev@dpdk.org" CC: Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin Subject: RE: [PATCH v3 03/15] hash: add allocation function attributes Thread-Topic: [PATCH v3 03/15] hash: add allocation function attributes Thread-Index: AQHbbbQ/3isU4BRF4kKjA3PJ7X5dmrMlmuDw Date: Fri, 24 Jan 2025 08:37:30 +0000 Message-ID: <59e97d2ca1f6483bb9ea006f5cdfb5a7@huawei.com> References: <20250110170603.538756-1-stephen@networkplumber.or> <20250123163003.23394-1-stephen@networkplumber.org> <20250123163003.23394-4-stephen@networkplumber.org> In-Reply-To: <20250123163003.23394-4-stephen@networkplumber.org> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.48.156.8] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org > Use function attributes to catch cases where hash table is allocated > but not freed correctly. >=20 > Signed-off-by: Stephen Hemminger > --- > lib/hash/rte_fbk_hash.h | 24 +++++++++++++----------- > lib/hash/rte_hash.h | 21 +++++++++++---------- > 2 files changed, 24 insertions(+), 21 deletions(-) >=20 > 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_tab= le *ht) > */ > struct rte_fbk_hash_table *rte_fbk_hash_find_existing(const char *name); >=20 > + > +/** > + * 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_existin= g(const char *name); > * - EEXIST - a memzone with the same name already exists > * - ENOMEM - no appropriate memory area found in which to create mem= zone > */ > -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); >=20 > #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; >=20 > +/** > + * 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 mem= zone > */ > 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); >=20 > /** > * 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_h= ash_cmp_eq_t func); > struct rte_hash * > rte_hash_find_existing(const char *name); >=20 > -/** > - * 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, > -- Acked-by: Konstantin Ananyev > 2.45.2