DPDK patches and discussions
 help / color / mirror / Atom feed
From: Kevin Laatz <kevin.laatz@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, Kevin Laatz <kevin.laatz@intel.com>
Subject: [dpdk-dev] [PATCH] raw/ioat: fix dereference before null check
Date: Wed, 14 Oct 2020 11:11:10 +0100	[thread overview]
Message-ID: <20201014101110.1210264-1-kevin.laatz@intel.com> (raw)

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 <kevin.laatz@intel.com>
---
 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);
-- 
2.25.1


             reply	other threads:[~2020-10-14 10:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-14 10:11 Kevin Laatz [this message]
2020-10-14 11:34 ` Bruce Richardson
2020-10-19  8:24   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201014101110.1210264-1-kevin.laatz@intel.com \
    --to=kevin.laatz@intel.com \
    --cc=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).