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 9D6E546104; Sat, 25 Jan 2025 03:13:34 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 797474060B; Sat, 25 Jan 2025 03:13:27 +0100 (CET) Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) by mails.dpdk.org (Postfix) with ESMTP id A0AC6402E6 for ; Sat, 25 Jan 2025 03:13:18 +0100 (CET) Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2163b0c09afso52854065ad.0 for ; Fri, 24 Jan 2025 18:13:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1737771198; x=1738375998; 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=aPxKVjAXz69ZVqb4yu9czfPzhdxdwcbDegdYjlmum3g+O2vH4uby/jlA4/INBq0Q7b KRJScu2Tx/6kT1mTyEeZB0FtqtCSsUrMAToptQU+7zIGCfZXvKNEB2zY7jAdYKALZyds gMULZVrKj9NGXyQxyaK6RupRPji0Ag5r3gXS4ZyXxSVrvWwxhOtEi92WneHeoeDbSuQL ApS2S8Ks7Mxdu9vOdERvAgfOjXfR+UyPqHlP3ja/tBLblEWbUR7dA/7jpFXkrwVGJ/q7 sD0goY7wxFnTBTOhzRTMVDb8tHkYD+1A+K4ZfETE2wA6IRUMvYvzDDw+OnH2jtTKnOFS vRAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737771198; x=1738375998; 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=oEvoAodCyffd5kPXZ5ynVkmXY+C5D6StN7JTx7BY7Yv5M1c7Li+DZvKs0xqui4cdrU nXnLprPGmAl1Xd2J506IQRuSwkH0xRxZawAPJ7RwwqX9mlP+6NvwpDrE4X4Lgt951UHS Rec2xZsG20AQLLVrQVeJFvE/1YbYbjtw01l/C+INg0iVobk6JTJIipz94Je7UJJO6Zsu FmjOILi5vabi/iYu1Elp5FDGbb6dEYafe02uUIQpSXgLQ+ot29/E93NN3s981vfg1oYC J8URphp3TeIwGWCQWFlIXaW6Y65aiAcslDighYMqQSa+YSpB0pxkc17TpCVXOOs8K7Wa GzbA== X-Gm-Message-State: AOJu0Yws/EcuuuVZw9286emujmW725lMVX11UUgleT+awcLJzV5FOs6a gzUHinuUYIwPDGiEUAg4OGaHN78nnIqSMTPZ6xilEFONyubgISSggQQaIpjnDHkPX5qhpJMEStv b X-Gm-Gg: ASbGncsv0mz2GRdNwlEjBAtjETj1WVgBYJ9UCvcwtJbrWt5Y3XEhzprlwIEtn8Atl8I 1HM8hYK7iO4rUcTOsN613ZNRrb3lr4FXyislvA89H43tqzRk4GpmEvLZD1pEbUjKdziS0fEb1S2 6Uhgkvv0taK1FmRiLWwrts3XcIZJ03ji3Jyj9ChoII/kJ4r/O77qksdntI17htxOgF63hBC12gJ FBT2Krf2d2MfUaFuGulqAU0LjpBRbycZNOMbHY/tZKAILimkQJfLHtow9Hl45rjrJz0NsuObHfU UZl+aTG8fScEvTBeEPowysEKfeIoHnfm48Fr59ahwDzlNF6IKVkurqsm5Q== X-Google-Smtp-Source: AGHT+IGmnx1FAR2yi9eIT3RaSC0fXjPkP1cm71lwK+rPo1TYYdKd2uP21+/iBFJwdWpP+gSBTeQdiQ== X-Received: by 2002:a05:6a20:4f85:b0:1eb:7da4:305d with SMTP id adf61e73a8af0-1eb7da43400mr4400272637.18.1737771197880; Fri, 24 Jan 2025 18:13:17 -0800 (PST) Received: from hermes.local (204-195-96-226.wavecable.com. [204.195.96.226]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-ac48e84e199sm2345256a12.11.2025.01.24.18.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2025 18:13: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 v5 03/16] hash: add allocation function attributes Date: Fri, 24 Jan 2025 18:11:16 -0800 Message-ID: <20250125021305.76485-4-stephen@networkplumber.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250125021305.76485-1-stephen@networkplumber.org> References: <20250110170603.538756-1-stephen@networkplumber.org> <20250125021305.76485-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