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 B787B460E8; Wed, 22 Jan 2025 18:36:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C53C440658; Wed, 22 Jan 2025 18:35:56 +0100 (CET) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by mails.dpdk.org (Postfix) with ESMTP id B506E40649 for ; Wed, 22 Jan 2025 18:35:52 +0100 (CET) Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21654fdd5daso126205675ad.1 for ; Wed, 22 Jan 2025 09:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737567352; x=1738172152; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oJ0NKSQeQhuD6uJLudsaE+OAQdUWfj4QJxpIfPz47ps=; b=Fogc19Hbt9XySxpM+cMfGF2FDz45nltfuOMTS9hUaU8L9mMSqXrV5fgG4PzMRHaJP9 D5SdvoQif4VNmdqI4KfP8EPlbshidUyHjVmyjv2rkZsIUMEcWirgXU8xR7q/XoOtcZ6K ru6iyBtlv4RQxztwFV/CIAmmebRU2KXd4sZVoEQtp5pODH9TklfVY91afPUPtkiuz9VQ BRFV/bTQDZPGifAbJUSk7hamI6KLBckhCDU+oWHOC5cTNlEpm8zi0cCzS4m2xt/SYnf3 Di7rKNdSXl6D3NNKTbPXd61MBzmia/BCf7p2yoxBsOflYGjcg5IVdxDcoeoKy/3L9lCe 2fqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737567352; x=1738172152; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oJ0NKSQeQhuD6uJLudsaE+OAQdUWfj4QJxpIfPz47ps=; b=SYq24EVcV3bnUL5rM1REKcmRXQOWVRRiFJepc3LPbxNVwSlA5MkolEogcmpW+7aLq0 hJzay8+IcA72efbIrp1ngv+oQeom1pUTTCg3SNSTsM2fkJW4jP7/sC/9STx8cL9VK3lQ 4+qsMUBZ/ugmEzOEBxfBsAgIgCuZGlFxGB+aLWFVKOPXg4/I/11q+J70mgzoQnrKyK3m yRAk9pSNUglLbp/cSYzt8Gyzo5AAAEMeD0F0wRT/tvWJJkTp/2QZg2hBb/zy7qLqqLiy yZbwODxjXg5lt3LF+euZz0aSWnRpMlaUKbJjKRwnZoRV9NL0+86HBtyDT5I2KyuOsgnr NLBQ== X-Gm-Message-State: AOJu0Yzf64twpAyUjlAy7Cw9USdSaNKpjn5R6ULkP9XlonugO8kWHAOT vY5WpH2vz+t7uxuoUEvt9yWKRkoABc2qWXjIVlqe2lAUFJZQAHX5Vl98IWg9+c5UNuBKRZg9yii D X-Gm-Gg: ASbGnctggtnxEkux+intjreJRj7k4EobTjPG5PboizE78MTbTmxEUqNC+boHf7xMw1m 3x932NAgy1jgIJ111X7VzmYCEOHztvSYpUzryk5IMl5Lx4qs7hll5aoqyzfuSjRenYI40zlB4MK 2WLibbWHM234ntowaTaYNv9TLPMmh0IJGxBukxQlLBiCr0YkBrrXvfXWjtUSQuuF5Vxwn75iFBs ktOSzRmzs5X/1QId6au7PqGWUEJcwMYIrmTCZ2jtpqly76aKvyfkZPDuKx/XmseuEL8ss291aGR 0N8WVtG/S9MJwMhL8nopTxbntaPTCBeCWioWxlNaUq0N2V0= X-Google-Smtp-Source: AGHT+IFWL5OxtpW5YC7dKD4//Pu6c5f247FF2kKYJ3nzUdlPKzHxO7ladJMzBMNAgI/4gciNgz3PHg== X-Received: by 2002:a17:902:cf0a:b0:216:393b:23e0 with SMTP id d9443c01a7336-21c355b70d7mr363385435ad.36.1737567351875; Wed, 22 Jan 2025 09:35:51 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2d3bc64dsm97469285ad.122.2025.01.22.09.35.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jan 2025 09:35:51 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin Subject: [PATCH v2 03/15] hash: add allocation function attributes Date: Wed, 22 Jan 2025 09:32:47 -0800 Message-ID: <20250122173521.305108-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250122173521.305108-1-stephen@networkplumber.org> References: <20250120180550.198121-1-stephen@networkplumber.org> <20250122173521.305108-1-stephen@networkplumber.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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(-) 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