diff mbox series

raw/ioat: fix dereference before null check

Message ID 20201014101110.1210264-1-kevin.laatz@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers show
Series raw/ioat: fix dereference before null check | expand

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/checkpatch success coding style OK

Commit Message

Kevin Laatz Oct. 14, 2020, 10:11 a.m. UTC
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(-)

Comments

Bruce Richardson Oct. 14, 2020, 11:34 a.m. UTC | #1
On Wed, Oct 14, 2020 at 11:11:10AM +0100, Kevin Laatz wrote:
> 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>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Thomas Monjalon Oct. 19, 2020, 8:24 a.m. UTC | #2
14/10/2020 13:34, Bruce Richardson:
> On Wed, Oct 14, 2020 at 11:11:10AM +0100, Kevin Laatz wrote:
> > 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>
> > ---
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks
diff mbox series

Patch

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);