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 ED9CD46114; Sat, 25 Jan 2025 19:40:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AC3554060B; Sat, 25 Jan 2025 19:40:27 +0100 (CET) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by mails.dpdk.org (Postfix) with ESMTP id 11A89402B7 for ; Sat, 25 Jan 2025 19:40:24 +0100 (CET) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-21631789fcdso56531625ad.1 for ; Sat, 25 Jan 2025 10:40:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737830423; x=1738435223; 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=TSlA9vsG4ImHpLaPjYt8xMo/aXBoEywmCiPYZzRVbUc=; b=myE6BfNCHxaOocXDntQD+9qyxlSzflolXhyP6VsEelZObbrT7RlLPh9ToKxwt5X+HB 9BvJqAJUZq+dmdjPDD0HElmAA5HoFbhki8HMj/Xk3lOZD/30aUH2YLvGzeL1CfT/st46 qPOSAEAq/A8N1yasy/qEQI4PkX6evrzofbWBeJakhtrZSCtedbEWtkwtOx3KrliBwcKH 0H8Mt7PDDxqPbG7MmRKSzVD8f7BU+8vVJo7f3AZbtKrCxne3++uIOlyo/7OB+hQ07kcL HzIX1IqkyLs31nnYVYuBbB2t4EznHfAddCIbYcpKjtwFIvJHhdFA1kT4MYTGDYplrxYZ bIMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737830423; x=1738435223; 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=TSlA9vsG4ImHpLaPjYt8xMo/aXBoEywmCiPYZzRVbUc=; b=VxB2YiF3qhCNVsvDnJ7A3o9H0EM2fo3Zx+gB7HJ321ZnQ7UHRS/Gbkzc54nigC1l3Q pfNXvFz31yKRBOT3c4ZxvBUY9kmviK/hvXE9p3YN5CvgJVDLYDg+XeV+K2rBwiplN0fa SvF+qiZYJgVtCtQ8H4TnM6KeJxHxlpxgL3fYHeNsqtP0s3VvwXdW/MgKf4p0j2yTXZyQ CAF69sotgQoEZ1W2oZjoOqaMw8xxGuKwKePyZvLDR/KC1uh7+mOmKSdhtqvceuKO9NPV fYqXgYZLpDYCZu/k8X0CAe7mYIwmFRbalYOgWsbk16oWpoSrygd+tDgJddkgsh11I9hJ 8yyQ== X-Gm-Message-State: AOJu0YzsVaLKooA9hEcXKcsChQVPzemxpNvaxVZ8XZbH/R0tJupMGRoV TntdbgTWncKqOWzCjewjYErtMI5Kkk2cuytENSRIDRdScGl4+jL+S8Hkt37al91rYAjVcQY5WjE 0 X-Gm-Gg: ASbGncvb6xdWzfC8fN8yCCtguWaNvpTSzlTeYywql36hfwBROheghPsVIf7VVdqXJIF UY3pOZ7SOKVWW0KHrof9Z1Y/gqhftMJS5/9+1V8q3sSD7acfu7u1l/4KQq8nm4PqymZg7QNxIAj V+GjkPTlvVAyJQFvWR2trQHqIr9jEGk0b9WTkErtZg1FOX6h4V1AqJDMrAui0bNf0zhQ5wwLKwv /LLMnSPbRxmOR9nTKailtlenFBhJKqN9kUchH0f3E609Pk4AbghsRO8LgeanbxRZCvWWSOIFz8/ 5mgxtEMnMKdu/RcY/a036EH/96TjAiqespQaWTmRA+PLd/O/uRqwt2B6Gg== X-Google-Smtp-Source: AGHT+IGvysYL7BOo1PLS5gmRSOn4axbdkf+1NyV2XOl2WnUjPGeYxftzO6DYjCmZIHiPOgrNE00iLw== X-Received: by 2002:a05:6a21:6d9f:b0:1e1:ad90:dda6 with SMTP id adf61e73a8af0-1eb697c1bb0mr20145482637.20.1737830423240; Sat, 25 Jan 2025 10:40:23 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a7614f4sm4100547b3a.97.2025.01.25.10.40.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Jan 2025 10:40:22 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev Subject: [PATCH v6 03/15] hash: add allocation function attributes Date: Sat, 25 Jan 2025 10:36:37 -0800 Message-ID: <20250125184010.782330-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250125184010.782330-1-stephen@networkplumber.org> References: <20250120180550.198121-1-stephen@networkplumber.org> <20250125184010.782330-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 Acked-by: Konstantin Ananyev --- lib/hash/rte_fbk_hash.h | 25 ++++++++++++++----------- lib/hash/rte_hash.h | 22 ++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/hash/rte_fbk_hash.h b/lib/hash/rte_fbk_hash.h index 1f0c1d1b6c..14041e2d45 100644 --- a/lib/hash/rte_fbk_hash.h +++ b/lib/hash/rte_fbk_hash.h @@ -20,6 +20,7 @@ #include +#include #include #include @@ -322,6 +323,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 +350,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..f692e0868d 100644 --- a/lib/hash/rte_hash.h +++ b/lib/hash/rte_hash.h @@ -14,6 +14,7 @@ #include #include +#include #include #ifdef __cplusplus @@ -125,6 +126,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 +153,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 +182,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