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 E317646130; Fri, 24 Jan 2025 19:17:25 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 768F7410EA; Fri, 24 Jan 2025 19:17:21 +0100 (CET) Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by mails.dpdk.org (Postfix) with ESMTP id 8B20A40BA4 for ; Fri, 24 Jan 2025 19:17:18 +0100 (CET) Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-2ef8c012913so3431449a91.3 for ; Fri, 24 Jan 2025 10:17:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737742638; x=1738347438; 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=pcuzV4KYPiLmYyuXLllmH4oBSEVlavZc+ttIsjYG00I=; b=c5/mngqr66MR2fDNKhBxA6teJHMaI7GniJnSS5MYAwTOmVQf6jvdviichQd3M8M63Q TjVg13TKOuAWqLox+i5gpdxLj3bmxDOZkfIfQ5JYko2Zwe0RiOaac7D4oH7JmZNcu6Pq ctCRP4JYap25kDVAGR6f+AKo7yUQEd6WU7PN9t7s965FulWBbsTEfPYroJloZp7tHNgZ S4Pg3uTbH6zy3c9+wf9dTaS3x1iAtNn7E37cmIEuQLNe5jDi8BUHHB+BT8Jb4ZUJ3o9n hTiBme0ZAkNWWCItKzVjNDf6jkcOdfWwq9yevsdTyNGGr5s5hRQ3zf1o81QE9l3pP/iJ jmSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737742638; x=1738347438; 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=pcuzV4KYPiLmYyuXLllmH4oBSEVlavZc+ttIsjYG00I=; b=D36h9QU/pMnb9inRU1qgBOomHjMv7/cDIhDzYryd8xlNHqfu0hthmvnptng757i1bB dXV+2EnOsiHgdLkX6vGJ8tMGo3QhIz82XhSLGUb12zH4RCOZ3tlvJnCokidGsVERLVUM An199Xi4Xz/kOwA00065g7iR+ZgqqfzJ5cBQDU25A9zroNCivH/9OT4uc9WbcixS45ll CssCjzZOTQyoP47FQQPeXNCrWnV9Qd6MrfCut0p7l6ACFkcSQa1PFWCft+rVsuiYzjJZ u1A8inukR8iIsrRK+Ysc41DxSXsdiUN7T/V9fzApOWwW4K7PXrj5InxTftZxoV8d+ELq 5plQ== X-Gm-Message-State: AOJu0YzCn3OgtMHbGzdPDj+MofIY95j8J+ediJjzhBLTT5IBQmFxFB3H XNztpzeAI8y8CMjWZPxU4VSytttK9DAlmWYVcwdp9OPJb/zy1u6+u1891jTQg3f6e4EiEF5lhTL z X-Gm-Gg: ASbGncseBmGQ/coFc6eK0nt9F/SqlhpQSWSxz5/+0N4Jdm/6Ch0WJNGYLiIaPiS8H7y 0mKSvGgiSfJebC8CxI6oea3wPj5EUt5EjkzXpXw1nTAXcyXSHKIORQU9Vic6VipmeOp501wS2Fk tkgcv1j57aloXzJG8QjefUL/MqibCdr5I+rgZEB0WIKPBfaG492c6yu0lXn81rl57nA6UKDiIBd P/ZAliZxE1SxZJ5fB7Qp7mmU4hG3FsODpRmESMklraF2HAGCUIBwn+M0qVcSbs053N5RzvNwemZ 5t1jeiz2UAklpJWIRbfFhrC/X0Tw278/7FexNaazN8RPynbcfFaUrHYiLA== X-Google-Smtp-Source: AGHT+IFhd/i5YAt/zfLnugpuO3MC8Xz1idsHzrKXKH/BJo9Bv1TxvHUnc3QboNQowpm6nEIbsC3VEg== X-Received: by 2002:a05:6a00:13a0:b0:72d:9ec5:922 with SMTP id d2e1a72fcca58-72dafbf04f5mr46534486b3a.24.1737742637770; Fri, 24 Jan 2025 10:17:17 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72f8a6b2ed8sm2184477b3a.41.2025.01.24.10.17.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 10:17:17 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Konstantin Ananyev , Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin Subject: [PATCH v4 03/16] hash: add allocation function attributes Date: Fri, 24 Jan 2025 10:14:54 -0800 Message-ID: <20250124181704.86567-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250124181704.86567-1-stephen@networkplumber.org> References: <20250110170603.538756-1-stephen@networkplumber.or> <20250124181704.86567-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 | 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