From patchwork Wed Oct 14 10:11:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Laatz X-Patchwork-Id: 80713 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0F0ABA04B7; Wed, 14 Oct 2020 12:15:46 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id DBBF61DDEB; Wed, 14 Oct 2020 12:15:44 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 0FDCD1DDDF for ; Wed, 14 Oct 2020 12:15:42 +0200 (CEST) IronPort-SDR: Uho2bVyUqsgyDYYx2dQoY/POJhVuPp6hISLtPz8het1LKGamlshxCqV+/jgzg8zkUM3U5KSqwQ GyiTQsr2LjRg== X-IronPort-AV: E=McAfee;i="6000,8403,9773"; a="166137961" X-IronPort-AV: E=Sophos;i="5.77,374,1596524400"; d="scan'208";a="166137961" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Oct 2020 03:15:41 -0700 IronPort-SDR: rumNVM1Xm3Fj1WTmbolUI+OIdN8TiRMNV20HdIjpBDgmEIlfPBaq7KEq05V2hJyLXlZY4vjGO5 uBASrIR3Cihg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,374,1596524400"; d="scan'208";a="314114167" Received: from silpixa00399838.ir.intel.com ([10.237.213.224]) by orsmga003.jf.intel.com with ESMTP; 14 Oct 2020 03:15:39 -0700 From: Kevin Laatz To: dev@dpdk.org Cc: bruce.richardson@intel.com, Kevin Laatz Date: Wed, 14 Oct 2020 11:11:10 +0100 Message-Id: <20201014101110.1210264-1-kevin.laatz@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH] raw/ioat: fix dereference before null check X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The 'idxd' pointer in 'idxd_rawdev_destroy()' is being dereferenced before it is checked. To fix this, the null pointer check was moved to occur earlier in the code. Coverity issue: 363040 Fixes: ff06fa2cf3ba ("raw/ioat: probe idxd PCI") Signed-off-by: Kevin Laatz Acked-by: Bruce Richardson --- drivers/raw/ioat/idxd_pci.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/raw/ioat/idxd_pci.c b/drivers/raw/ioat/idxd_pci.c index 165a9ea7f1..d4d87b199d 100644 --- a/drivers/raw/ioat/idxd_pci.c +++ b/drivers/raw/ioat/idxd_pci.c @@ -290,6 +290,10 @@ idxd_rawdev_destroy(const char *name) } idxd = rdev->dev_private; + if (!idxd) { + IOAT_PMD_ERR("Error getting dev_private"); + return -EINVAL; + } /* disable the device */ err_code = idxd_pci_dev_command(idxd, idxd_disable_dev); @@ -300,13 +304,11 @@ idxd_rawdev_destroy(const char *name) IOAT_PMD_DEBUG("IDXD Device disabled OK"); /* free device memory */ - if (rdev->dev_private != NULL) { - IOAT_PMD_DEBUG("Freeing device driver memory"); - rdev->dev_private = NULL; - rte_free(idxd->public.batch_ring); - rte_free(idxd->public.hdl_ring); - rte_memzone_free(idxd->mz); - } + IOAT_PMD_DEBUG("Freeing device driver memory"); + rdev->dev_private = NULL; + rte_free(idxd->public.batch_ring); + rte_free(idxd->public.hdl_ring); + rte_memzone_free(idxd->mz); /* rte_rawdev_close is called by pmd_release */ ret = rte_rawdev_pmd_release(rdev);