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 6F6884601A; Mon, 20 Jan 2025 19:06:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 423E34278D; Mon, 20 Jan 2025 19:06:06 +0100 (CET) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mails.dpdk.org (Postfix) with ESMTP id D99A541133 for ; Mon, 20 Jan 2025 19:06:02 +0100 (CET) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2165448243fso103035635ad.1 for ; Mon, 20 Jan 2025 10:06:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737396362; x=1738001162; 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=Jnl5ClwSiIpoNe01kWrqXfKxPCFVzfn3V/Hgh6JOEgeynx/Oq7bHIoB+KHPYK+QS5M A5+MgdcrstSIf4BSB6Eu9Obj42uP5UCvVcLb1G2SCT+SeY5Jx0bLAVTsqd+RXAx1I0ib sHuN/103D27Ih8qE3UMWAedAWAaM5OxW/EBQuZljKVABziOccGHlwTyYAW6LxDVIbmky ooUBGqV3fXVoT0RNtbE5JWYlekmwo53QYVggD/OdMs778e5HC6SknHyzpLoaCR73iYVv F0P8vdAU07rbqPmZj3KktMx8RjeOJDvzaod6A6ppur0LHVQmtspfO35NUIc6OX8vondv K04Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737396362; x=1738001162; 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=ILbWiCJDXeQC/jL+lhVkL1Wz/+2kyut08Ec/0nk/CSiZe0B9Yxo93aOFm4kudJjOq3 4JF4VwdNJALOa5bcxjzL1a+oout3nt+c82f2evFESfpzPIA+aw7LmimQS1CkeUVWMBu9 b7AolMNH9wzHJi0wxci1WSo33T7MTjUrVLOOKtkVlF14BQ5Ke+AWiUiwTz7yrFpC4POF QPJ29eD2Eug21sphZGncynzPlml5hIAHalP/AfRICOPPa7Fw8jGMmeRBJ879vra9jKUf OKg6CR7TJw6Nlx80qLG159eslrU7m1MyboGst6l3LA4nUR2Z+QN4Nm3X9cZOEKv/t1oK TImQ== X-Gm-Message-State: AOJu0Yw1MbfQMdvV7SOc4zcG6iTkKorLsPttNcVF5CFTS8iUItwWrori UIeQklt+iPefuZvu+nmthAoXCiUiN8dAcHzxocXHTX7D8MGBao1egr4KfykeTCkYyyQ3d7YJTE2 b X-Gm-Gg: ASbGnctfvh3lg9S3Rz9PmlqrvvJBBOIlaF5zOUypTrZfLRjwCdVBwzshkNCWIoHUTTl Drk7rO3KB0oX4iJANjQ49/rDoKV7XuMJRlKtk7fyD2kD1DGWnKMzTgWpikM9XdZw9GlkbGykRia zeHvmTajDXzhdxVLdtnff9pBG86qJC9oWhbC1KcBn/qIFBIRYB8KdM3h+8IjrGF4vr5VeCxPWn/ 6l/1Kh4v/V4fOwAUFefiNlLTtwg2Cq3VfIH8bb+07rt4nwR72k5ri8zJNMHKXYuYchFbX4wajQp gpLVIY3zMlJ22ObAYKso4RxuJGHFCwOFWB20TwehqM05SHY= X-Google-Smtp-Source: AGHT+IFmOSpAn8+gLi6VRGHhwdWIJ3QfxSjaCkeuVG4Ua/xKZfvaYIMa+S5iXLwbcMCwHRqUA6K04A== X-Received: by 2002:a05:6a20:12d0:b0:1db:ed7c:b8f6 with SMTP id adf61e73a8af0-1eb2144d3e6mr22259427637.2.1737396362009; Mon, 20 Jan 2025 10:06:02 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72dab848b08sm7393982b3a.71.2025.01.20.10.06.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 10:06:01 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin Subject: [PATCH 03/15] hash: add allocation function attributes Date: Mon, 20 Jan 2025 10:03:21 -0800 Message-ID: <20250120180550.198121-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250120180550.198121-1-stephen@networkplumber.org> References: <20250120180550.198121-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