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 E7EF7460FF; Thu, 23 Jan 2025 17:30:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0C6AB40C35; Thu, 23 Jan 2025 17:30:25 +0100 (CET) Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mails.dpdk.org (Postfix) with ESMTP id A164040B92 for ; Thu, 23 Jan 2025 17:30:20 +0100 (CET) Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2efe25558ddso1680378a91.2 for ; Thu, 23 Jan 2025 08:30:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737649820; x=1738254620; 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=BfMQLEmahMGEg6Smgtn+sjOaEo1sZ/34cZhbXEetQmpEsZCVzS7xpRbOkkcSnO/eDi 5g6B3B792fzpiXSuqylz8FZ8Yx1djVUXz3PKOdv3Ls/qnMkrO0FEJnUcWWjwwzgxAJHl jG1hD0JLEiuBTRBHf0Et4mNBSFqDXYYBVQnUR66tqiw4z/QtCJX5Y0QCw9LM68eBzFYW qzlGALt6KtIDO/C8AMDc0/ftYvmJG48Bx0GhTOWUmFtmK76BCkFOmlzrBI7ywyu4bkFg Uah9/lOsGowsdiwy0moUIno04qZ4RPq87VGMZ+XyhwE5SVuUeuZhuCBEf9qG6FI935/d 7orQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737649820; x=1738254620; 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=DWulqXUdQisQUXLB6vKPQcBaXST2RAjoOx5vrQFt7tz4CuUFrTRZKL6cUGVL6oUewS kwSIK1Kh+2YYJ7ws1wERWClHYrSYbzUc2LW9a91PQ9nSnKx+RmLRmIB2yu8VBIWzToLY k7+23yPxqxF/E35zlYcah9GWWp67Hm55eaWgVqs+Foy85jCi9YktX5w5MTWrbfgI3RE1 H/VRJvehyza/r9VYDW9lP110K0/7vAE9YPzdxvMErgyTskHHzwvmyqAfoqdhj/eMQ4Ob 2e6XwTrV05v1fSs+UAr15pjzoLG2espoRMusm7w3UUX8h6rQHa+wOnwHmNTLk1wn05Yq O8VA== X-Gm-Message-State: AOJu0YzF/DAdtrOAXUQLkH7ITIc71+QHjN4SPl2V+KOBrF7LwMynU0e8 9m4VfgVdVqgAbuoeOAUUamVlQUxTcRLeplmVzkKNTY+abQl3dUx4xocIP0zioU4HN7cSqtxdVPZ 5 X-Gm-Gg: ASbGncsuWAGoiqlW8+rDsiNAJ63TnrG0uM4kNeaLFa+jkpyroFmb3wc12zRglGFskhk 45qE2M/ZLX0bE+tuLPWgWEYiNLiUWmG3seh4xVrI2Hcjd/TjCU909+/9lG4yBcodu7QfJyxBTFz Gg18z3NY5B9pKNTMyhOqExD4WBC0Okr2Sbv84zkBwxsai+UhfuSAJyDTfOWHL5+lKxNlWtqbjyi r21h1PakRxr3Mm9hhI9pAxeUhk3+/lcoHfoxZ1WGOFzxPzf+CIvxfM/kx9VWgXg8dlG/4/+3rOA x1VZ0N17ZPSJfTzsWJS596gUA6GbOB0CQLLJe/MmBRsPvPpe4ilWn97CnQ== X-Google-Smtp-Source: AGHT+IHvxGtdO6Dwbbw1ZZN6O8RS5QEQsBz5PA4hfZ2isbi8XPpw4Yd0xkawVnndykYB4gtIQy+SLw== X-Received: by 2002:a05:6a00:2448:b0:725:322a:922c with SMTP id d2e1a72fcca58-72daf9abd78mr43162235b3a.3.1737649819773; Thu, 23 Jan 2025 08:30:19 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ac4907f076dsm64601a12.37.2025.01.23.08.30.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jan 2025 08:30:19 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin Subject: [PATCH v3 03/15] hash: add allocation function attributes Date: Thu, 23 Jan 2025 08:28:03 -0800 Message-ID: <20250123163003.23394-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250123163003.23394-1-stephen@networkplumber.org> References: <20250110170603.538756-1-stephen@networkplumber.or> <20250123163003.23394-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