DPDK patches and discussions
 help / color / mirror / Atom feed
From: Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
To: dev@dpdk.org
Cc: gakhil@marvell.com, ciara.power@intel.com,
	Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
Subject: [PATCH] common/qat: fix null dereference in release function
Date: Fri,  8 Mar 2024 09:44:11 +0000	[thread overview]
Message-ID: <20240308094411.5467-1-arkadiuszx.kusztal@intel.com> (raw)

This commit fixes NULL dereference in the release function,
and three additional coverity issues related to NULL check.

Coverity issue: 415038
Coverity issue: 415050
Coverity issue: 415052
Coverity issue: 415053
Fixes: 477d7d051211 ("common/qat: decouple drivers from common code")

Signed-off-by: Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>
---
 drivers/common/qat/qat_device.c     | 14 +++++++-------
 drivers/compress/qat/qat_comp_pmd.c |  6 ++++--
 drivers/crypto/qat/qat_asym.c       |  5 ++---
 drivers/crypto/qat/qat_sym.c        |  4 ++--
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/common/qat/qat_device.c b/drivers/common/qat/qat_device.c
index 500ca0f308..666e2bb995 100644
--- a/drivers/common/qat/qat_device.c
+++ b/drivers/common/qat/qat_device.c
@@ -420,15 +420,15 @@ qat_pci_device_release(struct rte_pci_device *pci_dev)
 
 		if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
 			for (i = 0; i < QAT_MAX_SERVICES; i++) {
-				if (qat_dev->pmd[i] == NULL)
-					continue;
-				QAT_LOG(DEBUG, "QAT %s device %s is busy",
-					qat_service[i].name, name);
-				busy = 1;
+				if (qat_dev->pmd[i] != NULL) {
+					QAT_LOG(DEBUG, "QAT %s device %s is busy",
+						qat_service[i].name, name);
+					busy = 1;
+				}
+			}
 			if (busy)
 				return -EBUSY;
 			rte_memzone_free(inst->mz);
-			}
 		}
 		memset(inst, 0, sizeof(struct qat_device_info));
 		qat_nb_pci_devices--;
@@ -445,7 +445,7 @@ qat_pci_dev_destroy(struct qat_pci_device *qat_pci_dev,
 	int i;
 
 	for (i = 0; i < QAT_MAX_SERVICES; i++) {
-		if (!qat_service[i].dev_create)
+		if (!qat_service[i].dev_destroy)
 			continue;
 		qat_service[i].dev_destroy(qat_pci_dev);
 	}
diff --git a/drivers/compress/qat/qat_comp_pmd.c b/drivers/compress/qat/qat_comp_pmd.c
index c5f7c7dc67..55e510c91f 100644
--- a/drivers/compress/qat/qat_comp_pmd.c
+++ b/drivers/compress/qat/qat_comp_pmd.c
@@ -792,12 +792,14 @@ qat_comp_dev_create(struct qat_pci_device *qat_pci_dev)
 static int
 qat_comp_dev_destroy(struct qat_pci_device *qat_pci_dev)
 {
-	struct qat_comp_dev_private *dev =
-		qat_pci_dev->pmd[QAT_SERVICE_COMPRESSION];
+	struct qat_comp_dev_private *dev;
 
 	if (qat_pci_dev == NULL)
 		return -ENODEV;
 
+	dev = qat_pci_dev->pmd[QAT_SERVICE_COMPRESSION];
+	if (dev == NULL)
+		return 0;
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		rte_memzone_free(dev->capa_mz);
 
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 8ec9f65156..14d6ec358c 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -1625,16 +1625,15 @@ static int
 qat_asym_dev_destroy(struct qat_pci_device *qat_pci_dev)
 {
 	struct rte_cryptodev *cryptodev;
-	struct qat_cryptodev_private *dev =
-		qat_pci_dev->pmd[QAT_SERVICE_ASYMMETRIC];
+	struct qat_cryptodev_private *dev;
 
 	if (qat_pci_dev == NULL)
 		return -ENODEV;
+	dev = qat_pci_dev->pmd[QAT_SERVICE_ASYMMETRIC];
 	if (dev == NULL)
 		return 0;
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
 		rte_memzone_free(dev->capa_mz);
-
 	/* free crypto device */
 	cryptodev = rte_cryptodev_pmd_get_dev(dev->dev_id);
 	rte_cryptodev_pmd_destroy(cryptodev);
diff --git a/drivers/crypto/qat/qat_sym.c b/drivers/crypto/qat/qat_sym.c
index 6c7b1724ef..c530496786 100644
--- a/drivers/crypto/qat/qat_sym.c
+++ b/drivers/crypto/qat/qat_sym.c
@@ -345,11 +345,11 @@ static int
 qat_sym_dev_destroy(struct qat_pci_device *qat_pci_dev)
 {
 	struct rte_cryptodev *cryptodev;
-	struct qat_cryptodev_private *dev =
-		qat_pci_dev->pmd[QAT_SERVICE_SYMMETRIC];
+	struct qat_cryptodev_private *dev;
 
 	if (qat_pci_dev == NULL)
 		return -ENODEV;
+	dev = qat_pci_dev->pmd[QAT_SERVICE_SYMMETRIC];
 	if (dev == NULL)
 		return 0;
 	if (rte_eal_process_type() == RTE_PROC_PRIMARY)
-- 
2.13.6


             reply	other threads:[~2024-03-08  9:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08  9:44 Arkadiusz Kusztal [this message]
2024-03-11 14:39 ` Power, Ciara
2024-03-13 14:51   ` Akhil Goyal

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=20240308094411.5467-1-arkadiuszx.kusztal@intel.com \
    --to=arkadiuszx.kusztal@intel.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    /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).