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 3F5E545B37; Mon, 14 Oct 2024 12:19:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0493B4027F; Mon, 14 Oct 2024 12:19:32 +0200 (CEST) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by mails.dpdk.org (Postfix) with ESMTP id B602140273 for ; Mon, 14 Oct 2024 12:19:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1728901171; x=1760437171; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Lf7QhDu+Mn12Nf+wytwOQgRI70Fk1Naa2Yrnp6r2xLg=; b=ZFN1kB++mNwNjl7hkK3F5PdL9nrwAN0q4TEgEsaCGdcbLekWp8xucMVH SbuCTtbRM6CLVa+NbGSxEbsM02KxpS7VlIT854zuhntE/g2f1+XMEju30 ktLFa9a/pMk2AFVAB4oKb1STCoH7UZeL+r0fBW33A3+7HF3PbuVJ36hEf cpvsdEC88AvwGfvEwMRaPE24WWc2/QqxQLNbWP4uEH0/Ct25xDBqHqDOp 7W9VGJUeluPmeldeeNxhtQDPHzIy5xWVHjQ/P2UVdSAHDQW6OATOZSLKm kjRgha8zZGUJyUfFC03zv+gyLDJPDzqJmEVMPQwRz0KhYbQTdH8Duk5xI Q==; X-CSE-ConnectionGUID: W/D4Vj94Qi6S6lGFUZhkkQ== X-CSE-MsgGUID: gkJywZPpST2Ym3QzE+mfwA== X-IronPort-AV: E=McAfee;i="6700,10204,11224"; a="27725868" X-IronPort-AV: E=Sophos;i="6.11,202,1725346800"; d="scan'208";a="27725868" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2024 03:19:30 -0700 X-CSE-ConnectionGUID: 8DeFUcySQ+CO+HraNOlb0Q== X-CSE-MsgGUID: Uofhlr8JTdKFX/lx10Dm7g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,202,1725346800"; d="scan'208";a="108326235" Received: from unknown (HELO silpixa00401183.ir.intel.com) ([10.55.128.177]) by orviesa002.jf.intel.com with ESMTP; 14 Oct 2024 03:19:27 -0700 From: Niall Meade To: Thomas Monjalon , Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin Cc: dev@dpdk.org, Niall Meade Subject: [PATCH v3] hash: separate param checks in hash create func Date: Mon, 14 Oct 2024 10:19:16 +0000 Message-Id: <20241014101916.2043948-1-niall.meade@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241010164602.1794534-1-niall.meade@intel.com> References: <20241010164602.1794534-1-niall.meade@intel.com> MIME-Version: 1.0 Organization: Intel Research and Development Ireland Ltd - Co. Reg. #308263 - Collinstown Industrial Park, Leixlip, County Kildare, Ireland 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 Separated name, entries and key_len parameter checks in rte_hash_create(). Also made the error messages more informative/verbose to help with debugging. Also added myself to the mailing list. Signed-off-by: Niall Meade --- v3: * code indentation fix and rte_errno set correctly v2: * change hash log messages to be one line I had name set to NULL in the parameters I was passing to rte_hash_create() and the error message I got didn't specify which parameter was invalid. --- .mailmap | 1 + lib/hash/rte_cuckoo_hash.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.mailmap b/.mailmap index a66da3c8cb..93df2effb2 100644 --- a/.mailmap +++ b/.mailmap @@ -1055,6 +1055,7 @@ Nelson Escobar Nemanja Marjanovic Netanel Belgazal Netanel Gonen +Niall Meade Niall Power Nicholas Pratte Nick Connolly diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c index 577b5839d3..9575e8aa0c 100644 --- a/lib/hash/rte_cuckoo_hash.c +++ b/lib/hash/rte_cuckoo_hash.c @@ -184,17 +184,24 @@ rte_hash_create(const struct rte_hash_parameters *params) hash_list = RTE_TAILQ_CAST(rte_hash_tailq.head, rte_hash_list); if (params == NULL) { + rte_errno = EINVAL; HASH_LOG(ERR, "%s has no parameters", __func__); return NULL; } /* Check for valid parameters */ if ((params->entries > RTE_HASH_ENTRIES_MAX) || - (params->entries < RTE_HASH_BUCKET_ENTRIES) || - (params->name == NULL) || - (params->key_len == 0)) { + (params->entries < RTE_HASH_BUCKET_ENTRIES)) { + rte_errno = EINVAL; + HASH_LOG(ERR, "%s() entries (%u) must be in range [%d, %d] inclusive", + __func__, params->entries, RTE_HASH_BUCKET_ENTRIES, + RTE_HASH_ENTRIES_MAX); + return NULL; + } + + if (params->key_len == 0) { rte_errno = EINVAL; - HASH_LOG(ERR, "%s has invalid parameters", __func__); + HASH_LOG(ERR, "%s() key_len must be greater than 0", __func__); return NULL; } @@ -204,6 +211,13 @@ rte_hash_create(const struct rte_hash_parameters *params) return NULL; } + if (params->name == NULL) { + rte_errno = EINVAL; + HASH_LOG(ERR, "%s() has invalid parameters, name can't be NULL", + __func__); + return NULL; + } + /* Validate correct usage of extra options */ if ((params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY) && (params->extra_flag & RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF)) { -- 2.34.1