From patchwork Wed Jun 8 07:34:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pei, Andy" X-Patchwork-Id: 112532 X-Patchwork-Delegate: maxime.coquelin@redhat.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 5B7ADA0544; Wed, 8 Jun 2022 10:23:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4E70341132; Wed, 8 Jun 2022 10:23:20 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id D7BF240687 for ; Wed, 8 Jun 2022 10:23:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654676599; x=1686212599; h=from:to:cc:subject:date:message-id; bh=3xPJny590EM5xCmn7faaXQ62bt4lB8iyCRqUWa9IeUE=; b=ngON/N3CaELt3wCTbfJB86VHf7SZa3od5Oh59bwQFFtWbW9m9xKpV0wz UDoKM9mQdDHLgrBrJuNZpEPotlMdkGQAobwrm1I2ARPQmIf0Qugysqedq bAwpvhSglB3wYtwY9CNYMcxS9fZwgqUlKigEyUsJiP3iqYyTbNYOk/Acn 6Fg9EUQslFCRmxindR44HcRwXDFkRC0DuocLKhwbRulhFC8lZ57O5ByM6 cXoXv6ADWsgLFNeeq9LpJO5hHyqUG09NHh0/jCdUawU7OqM5in4HxR0zi Psdr6+ofkfooATeMCNPo4FCMPkZQr+TCza6nrTR04ZmE3lcYnvSTGVSUS w==; X-IronPort-AV: E=McAfee;i="6400,9594,10371"; a="277996866" X-IronPort-AV: E=Sophos;i="5.91,285,1647327600"; d="scan'208";a="277996866" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2022 01:23:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,285,1647327600"; d="scan'208";a="907548079" Received: from dpdk-dipei.sh.intel.com ([10.67.110.238]) by fmsmga005.fm.intel.com with ESMTP; 08 Jun 2022 01:23:03 -0700 From: Andy Pei To: dev@dpdk.org Cc: chenbo.xia@intel.com, maxime.coquelin@redhat.com, xiao.w.wang@intel.com, rosen.xu@intel.com, qimaix.xiao@intel.com Subject: [PATCH] vdpa/ifc: fix null pointer dereference Date: Wed, 8 Jun 2022 15:34:02 +0800 Message-Id: <1654673642-151882-1-git-send-email-andy.pei@intel.com> X-Mailer: git-send-email 1.8.3.1 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 Fix null pointer dereference reported in coverity scan. Coverity issue: 378882 Fixes: 8162a4a9 ("vdpa/ifc/base: access correct register for blk device") Signed-off-by: Andy Pei Acked-by: Xiao Wang --- drivers/vdpa/ifc/base/ifcvf.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/vdpa/ifc/base/ifcvf.c b/drivers/vdpa/ifc/base/ifcvf.c index dd475a7..0a9f71a 100644 --- a/drivers/vdpa/ifc/base/ifcvf.c +++ b/drivers/vdpa/ifc/base/ifcvf.c @@ -255,6 +255,10 @@ u32 ring_state; cfg = hw->common_cfg; + if (!cfg) { + DEBUGOUT("common_cfg in HW is NULL.\n"); + return; + } IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg->msix_config); for (i = 0; i < hw->nr_vring; i++) { @@ -262,6 +266,11 @@ IFCVF_WRITE_REG16(0, &cfg->queue_enable); IFCVF_WRITE_REG16(IFCVF_MSI_NO_VECTOR, &cfg->queue_msix_vector); + if (!hw->lm_cfg) { + DEBUGOUT("live migration cfg in HW is NULL.\n"); + continue; + } + if (hw->device_type == IFCVF_BLK) ring_state = *(u32 *)(hw->lm_cfg + IFCVF_LM_RING_STATE_OFFSET +