[dpdk-dev] [PATCH] cryptodev: fix segmentation fault

Slawomir Mrozowicz slawomirx.mrozowicz at intel.com
Fri Feb 3 10:17:55 CET 2017


This patch fix problem in function rte_cryptodev_devices_get().
Program received signal SIGSEGV, Segmentation fault.
It also rework the function to use correct types and clean up visibility.

Fixes: 38227c0e3ad2 ("cryptodev: retrieve device info")

Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz at intel.com>
---
 lib/librte_cryptodev/rte_cryptodev.c | 35 +++++++++++++++--------------------
 lib/librte_cryptodev/rte_cryptodev.h |  4 ++--
 2 files changed, 17 insertions(+), 22 deletions(-)

diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
index e557e77..10a59ba 100644
--- a/lib/librte_cryptodev/rte_cryptodev.c
+++ b/lib/librte_cryptodev/rte_cryptodev.c
@@ -482,34 +482,29 @@ rte_cryptodev_count_devtype(enum rte_cryptodev_type type)
 	return dev_count;
 }
 
-int
+uint8_t
 rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices,
-	uint8_t nb_devices)
+	const uint8_t nb_devices)
 {
-	uint8_t i, cmp, count = 0;
-	struct rte_cryptodev **devs = &rte_cryptodev_globals->devs;
-	struct rte_device *dev;
-
-	for (i = 0; i < rte_cryptodev_globals->max_devs && count < nb_devices;
-			i++) {
+	uint8_t i, count = 0;
+	struct rte_cryptodev *devs = rte_cryptodev_globals->devs;
+	uint8_t max_devs = rte_cryptodev_globals->max_devs;
 
-		if ((*devs + i)
-				&& (*devs + i)->attached ==
-						RTE_CRYPTODEV_ATTACHED) {
+	for (i = 0; i < max_devs && count < nb_devices;	i++) {
 
-			dev = (*devs + i)->device;
+		if (devs[i].attached == RTE_CRYPTODEV_ATTACHED) {
+			const struct rte_cryptodev_driver *drv = devs[i].driver;
+			int cmp = -1;
 
-			if (dev)
-				cmp = strncmp(dev->driver->name,
-						dev_name,
-						strlen(dev_name));
+			if (drv)
+				cmp = strncmp(drv->pci_drv.driver.name,
+						dev_name, strlen(dev_name));
 			else
-				cmp = strncmp((*devs + i)->data->name,
-						dev_name,
-						strlen(dev_name));
+				cmp = strncmp(devs[i].data->name,
+						dev_name, strlen(dev_name));
 
 			if (cmp == 0)
-				devices[count++] = (*devs + i)->data->dev_id;
+				devices[count++] = devs[i].data->dev_id;
 		}
 	}
 
diff --git a/lib/librte_cryptodev/rte_cryptodev.h b/lib/librte_cryptodev/rte_cryptodev.h
index 67d0f84..0a49de2 100644
--- a/lib/librte_cryptodev/rte_cryptodev.h
+++ b/lib/librte_cryptodev/rte_cryptodev.h
@@ -432,9 +432,9 @@ rte_cryptodev_count_devtype(enum rte_cryptodev_type type);
  * @return
  *   Returns number of attached crypto device.
  */
-int
+uint8_t
 rte_cryptodev_devices_get(const char *dev_name, uint8_t *devices,
-		uint8_t nb_devices);
+		const uint8_t nb_devices);
 /*
  * Return the NUMA socket to which a device is connected
  *
-- 
2.5.0



More information about the dev mailing list