From patchwork Mon Aug 15 07:12:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zhang X-Patchwork-Id: 115006 X-Patchwork-Delegate: qi.z.zhang@intel.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 04B1FA00C3; Mon, 15 Aug 2022 01:08:02 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3CD2642C8B; Mon, 15 Aug 2022 01:04:30 +0200 (CEST) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 0B99140A79 for ; Mon, 15 Aug 2022 01:04:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660518267; x=1692054267; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F44iJeyEan9gG2rlP4nQ62UoFmuYiCBhmAzWwyF946o=; b=OwprAhQkPHTDSu5wS23njxxiLzYxaimjloWG8ZRee8Tiy26SpaO+qXfE k2Hj5ID8iLrbYf3K9hoRsYLWkTHZpq5uZNNowbmyOyDE2koB7WGRTnr+S OKXDQP8NVbAzcxkAg/GO+EjgvKUN64tweLvvlg/zj4gLb46PH2/jtM542 3nxZ9tt6jRX/0LTTPaHN1B9xTBVwtrXccm0ufLq/8NAZVJbGmNqoyiH+i XTb0pYk/h3gN8wsiOhWU3dKDmPawVL4Oa/IeRDpnFgMzlvzwXjpJ3OHeF qGjTwC/NDcJH3S24OC5sHpOblkQymKLv8zTfXbhYDT2wGdwK6c9vGfRPs A==; X-IronPort-AV: E=McAfee;i="6400,9594,10439"; a="289427641" X-IronPort-AV: E=Sophos;i="5.93,237,1654585200"; d="scan'208";a="289427641" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Aug 2022 16:04:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,237,1654585200"; d="scan'208";a="934296834" Received: from dpdk-qzhan15-test02.sh.intel.com ([10.67.115.4]) by fmsmga005.fm.intel.com with ESMTP; 14 Aug 2022 16:04:25 -0700 From: Qi Zhang To: qiming.yang@intel.com Cc: dev@dpdk.org, Qi Zhang , Jesse Brandeburg Subject: [PATCH 49/70] net/ice/base: clean up with no lookups Date: Mon, 15 Aug 2022 03:12:45 -0400 Message-Id: <20220815071306.2910599-50-qi.z.zhang@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220815071306.2910599-1-qi.z.zhang@intel.com> References: <20220815071306.2910599-1-qi.z.zhang@intel.com> MIME-Version: 1.0 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;