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 34D1FA00C3; Mon, 15 Aug 2022 01:26:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8FD5842CE7; Mon, 15 Aug 2022 01:23:39 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id 9EBBE42CBD for ; Mon, 15 Aug 2022 01:23:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660519417; x=1692055417; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F44iJeyEan9gG2rlP4nQ62UoFmuYiCBhmAzWwyF946o=; b=YXSdktiExwhXv6bh83WWmXcuazdO68vy+oaKkA5/Dez8TQK96rDdkKFv VpPcA58j4SvWUy80FhFcJamshNuQokm2JURJDaqYQLiuFXTSGnlHx9sLU RkPyByGKyBw0oRhv2XurQquZy64hQXsUDLyfPSDNsELZrd5qeMiZ0/rPB 7VKb/3BusXcki9s5XyTe+syVbAJRZI01QTV6wbKWyv7q/je8yZYyX5QMx EApaJWosQGNU9iFbbin4UrEHmrSHbNJdzneXhjNLAXdHBHFG22KXUicJi /6rvNL8ykXcifgjw5BJyz/OtVnSsQHfosIQpKMbnlHBeo8aRQm7JOk5Jh g==; X-IronPort-AV: E=McAfee;i="6400,9594,10439"; a="274914494" X-IronPort-AV: E=Sophos;i="5.93,237,1654585200"; d="scan'208";a="274914494" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2022 16:23:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,237,1654585200"; d="scan'208";a="635283264" Received: from dpdk-qzhan15-test02.sh.intel.com ([10.67.115.4]) by orsmga008.jf.intel.com with ESMTP; 14 Aug 2022 16:23:35 -0700 From: Qi Zhang To: qiming.yang@intel.com Cc: dev@dpdk.org, Qi Zhang , Jesse Brandeburg Subject: [PATCH v2 49/70] net/ice/base: clean up with no lookups Date: Mon, 15 Aug 2022 03:31:45 -0400 Message-Id: <20220815073206.2917968-50-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220815073206.2917968-1-qi.z.zhang@intel.com> References: <20220815071306.2910599-1-qi.z.zhang@intel.com> <20220815073206.2917968-1-qi.z.zhang@intel.com> 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 The add rule functionality works fine with a NULL lookups parameter. However when running the undefined behavior sanitizer it noticed that the function could trigger a memcpy from a NULL target. Fix the code to handle NULL lkups and a zero lkups_cnt variable more explicitly, and clean up the test to just directly pass a NULL value instead of allocating a stack variable assigned to NULL and passing that as a pointer. Signed-off-by: Jesse Brandeburg Signed-off-by: Qi Zhang --- drivers/net/ice/base/ice_switch.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/ice/base/ice_switch.c b/drivers/net/ice/base/ice_switch.c index 91a959e10f..01441211ff 100644 --- a/drivers/net/ice/base/ice_switch.c +++ b/drivers/net/ice/base/ice_switch.c @@ -9002,9 +9002,13 @@ ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups, goto err_ice_add_adv_rule; } - adv_fltr->lkups = (struct ice_adv_lkup_elem *) - ice_memdup(hw, lkups, lkups_cnt * sizeof(*lkups), - ICE_NONDMA_TO_NONDMA); + if (lkups_cnt) { + adv_fltr->lkups = (struct ice_adv_lkup_elem *) + ice_memdup(hw, lkups, lkups_cnt * sizeof(*lkups), + ICE_NONDMA_TO_NONDMA); + } else { + adv_fltr->lkups = NULL; + } if (!adv_fltr->lkups && !prof_rule) { status = ICE_ERR_NO_MEMORY; goto err_ice_add_adv_rule; -- 2.31.1