[dpdk-dev,v2] cryptodev: fix segmentation fault

Message ID 1486137302-28074-1-git-send-email-slawomirx.mrozowicz@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Pablo de Lara Guarch
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel compilation success Compilation OK

Commit Message

Slawomir Mrozowicz Feb. 3, 2017, 3:55 p.m. UTC
  This patch fix problem in function rte_cryptodev_devices_get().
Program received signal SIGSEGV, Segmentation fault.
It rework the function to use correct types and clean up visibility.
It also fix Coverity ID 141073

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

Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
---
 lib/librte_cryptodev/rte_cryptodev.c | 33 ++++++++++++++-------------------
 lib/librte_cryptodev/rte_cryptodev.h |  2 +-
 2 files changed, 15 insertions(+), 20 deletions(-)
  

Comments

De Lara Guarch, Pablo Feb. 3, 2017, 3:13 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Slawomir
> Mrozowicz
> Sent: Friday, February 03, 2017 3:55 PM
> To: Doherty, Declan
> Cc: dev@dpdk.org; Mrozowicz, SlawomirX
> Subject: [dpdk-dev] [PATCH v2] cryptodev: fix segmentation fault
> 
> This patch fix problem in function rte_cryptodev_devices_get().
> Program received signal SIGSEGV, Segmentation fault.
> It rework the function to use correct types and clean up visibility.
> It also fix Coverity ID 141073

Better to use our current format for Coverity issues:

Coverity issue: 141073
> 
> Fixes: 38227c0e3ad2 ("cryptodev: retrieve device info")
> 
> Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>

Apart from comment above:

Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
  
De Lara Guarch, Pablo Feb. 9, 2017, 3:29 p.m. UTC | #2
Hi Slawomir,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Slawomir
> Mrozowicz
> Sent: Friday, February 03, 2017 3:55 PM
> To: Doherty, Declan
> Cc: dev@dpdk.org; Mrozowicz, SlawomirX
> Subject: [dpdk-dev] [PATCH v2] cryptodev: fix segmentation fault
> 
> This patch fix problem in function rte_cryptodev_devices_get().
> Program received signal SIGSEGV, Segmentation fault.
> It rework the function to use correct types and clean up visibility.
> It also fix Coverity ID 141073
> 
> Fixes: 38227c0e3ad2 ("cryptodev: retrieve device info")
> 
> Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>

I think this patch fixes coverity issue 141067, not 141073.
Could you submit a v3 for this patch? Make sure to follow the format:

Coverity issue: XXXXXX

Thanks,
Pablo
  
De Lara Guarch, Pablo Feb. 9, 2017, 10:21 p.m. UTC | #3
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of De Lara Guarch,
> Pablo
> Sent: Thursday, February 09, 2017 3:29 PM
> To: Mrozowicz, SlawomirX; Doherty, Declan
> Cc: dev@dpdk.org; Mrozowicz, SlawomirX
> Subject: Re: [dpdk-dev] [PATCH v2] cryptodev: fix segmentation fault
> 
> Hi Slawomir,
> 
> > -----Original Message-----
> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Slawomir
> > Mrozowicz
> > Sent: Friday, February 03, 2017 3:55 PM
> > To: Doherty, Declan
> > Cc: dev@dpdk.org; Mrozowicz, SlawomirX
> > Subject: [dpdk-dev] [PATCH v2] cryptodev: fix segmentation fault
> >
> > This patch fix problem in function rte_cryptodev_devices_get().
> > Program received signal SIGSEGV, Segmentation fault.
> > It rework the function to use correct types and clean up visibility.
> > It also fix Coverity ID 141073
> >
> > Fixes: 38227c0e3ad2 ("cryptodev: retrieve device info")
> >
> > Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
> 
> I think this patch fixes coverity issue 141067, not 141073.
> Could you submit a v3 for this patch? Make sure to follow the format:

I have done it for you.

Applied to dpdk-next-crypto.
Thanks,

Pablo
  
Slawomir Mrozowicz Feb. 10, 2017, 12:53 p.m. UTC | #4
>-----Original Message-----
>From: De Lara Guarch, Pablo
>Sent: Thursday, February 9, 2017 11:21 PM
>To: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>; Mrozowicz,
>SlawomirX <slawomirx.mrozowicz@intel.com>; Doherty, Declan
><declan.doherty@intel.com>
>Cc: dev@dpdk.org; Mrozowicz, SlawomirX <slawomirx.mrozowicz@intel.com>
>Subject: RE: [dpdk-dev] [PATCH v2] cryptodev: fix segmentation fault
>
>
>
>> -----Original Message-----
>> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of De Lara Guarch,
>> Pablo
>> Sent: Thursday, February 09, 2017 3:29 PM
>> To: Mrozowicz, SlawomirX; Doherty, Declan
>> Cc: dev@dpdk.org; Mrozowicz, SlawomirX
>> Subject: Re: [dpdk-dev] [PATCH v2] cryptodev: fix segmentation fault
>>
>> Hi Slawomir,
>>
>> > -----Original Message-----
>> > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Slawomir
>> > Mrozowicz
>> > Sent: Friday, February 03, 2017 3:55 PM
>> > To: Doherty, Declan
>> > Cc: dev@dpdk.org; Mrozowicz, SlawomirX
>> > Subject: [dpdk-dev] [PATCH v2] cryptodev: fix segmentation fault
>> >
>> > This patch fix problem in function rte_cryptodev_devices_get().
>> > Program received signal SIGSEGV, Segmentation fault.
>> > It rework the function to use correct types and clean up visibility.
>> > It also fix Coverity ID 141073
>> >
>> > Fixes: 38227c0e3ad2 ("cryptodev: retrieve device info")
>> >
>> > Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
>>
>> I think this patch fixes coverity issue 141067, not 141073.
>> Could you submit a v3 for this patch? Make sure to follow the format:
>
>I have done it for you.
>
>Applied to dpdk-next-crypto.
>Thanks,
>
>Pablo

Thanks Pablo.
Sławomir
  

Patch

diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c
index e557e77..a64320e 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)
 {
-	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;
 
-			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 37f08ae..82f3bc3 100644
--- a/lib/librte_cryptodev/rte_cryptodev.h
+++ b/lib/librte_cryptodev/rte_cryptodev.h
@@ -435,7 +435,7 @@  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);
 /*