[dpdk-dev,v2] app/test-crypto-perf: fix uninitialized scalar variable

Message ID 1486718552-3741-1-git-send-email-aleksanderx.gajewski@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

Aleksander Gajewski Feb. 10, 2017, 9:22 a.m. UTC
  Fix problem with uninitialized nb_cryptodevs variable by
initialize it with 0 value. Program could jump to err label
without running cperf_initialize_cryptodev() function. Also assign 0
value to nb_cryptodevs after cperf_initialize_cryptodev() when value is
negative.

Coverity issue: 141073
Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
application")

Signed-off-by: Aleksander Gajewski <aleksanderx.gajewski@intel.com>
---
v2:
 * When nb_cryptodevs is negative after cperf_initialize_cryptodev()
assign 0 value to it.
---
 app/test-crypto-perf/main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

De Lara Guarch, Pablo Feb. 10, 2017, 9:47 a.m. UTC | #1
> -----Original Message-----
> From: Gajewski, AleksanderX
> Sent: Friday, February 10, 2017 9:23 AM
> To: Doherty, Declan
> Cc: dev@dpdk.org; De Lara Guarch, Pablo; Gajewski, AleksanderX
> Subject: [PATCH v2] app/test-crypto-perf: fix uninitialized scalar variable
> 
> Fix problem with uninitialized nb_cryptodevs variable by
> initialize it with 0 value. Program could jump to err label
> without running cperf_initialize_cryptodev() function. Also assign 0
> value to nb_cryptodevs after cperf_initialize_cryptodev() when value is
> negative.
> 
> Coverity issue: 141073
> Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> application")
> 
> Signed-off-by: Aleksander Gajewski <aleksanderx.gajewski@intel.com>

Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
  
De Lara Guarch, Pablo Feb. 10, 2017, 11:05 a.m. UTC | #2
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of De Lara Guarch,
> Pablo
> Sent: Friday, February 10, 2017 9:47 AM
> To: Gajewski, AleksanderX; Doherty, Declan
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2] app/test-crypto-perf: fix uninitialized
> scalar variable
> 
> 
> 
> > -----Original Message-----
> > From: Gajewski, AleksanderX
> > Sent: Friday, February 10, 2017 9:23 AM
> > To: Doherty, Declan
> > Cc: dev@dpdk.org; De Lara Guarch, Pablo; Gajewski, AleksanderX
> > Subject: [PATCH v2] app/test-crypto-perf: fix uninitialized scalar variable
> >
> > Fix problem with uninitialized nb_cryptodevs variable by
> > initialize it with 0 value. Program could jump to err label
> > without running cperf_initialize_cryptodev() function. Also assign 0
> > value to nb_cryptodevs after cperf_initialize_cryptodev() when value is
> > negative.
> >
> > Coverity issue: 141073
> > Fixes: f8be1786b1b8 ("app/crypto-perf: introduce performance test
> > application")
> >
> > Signed-off-by: Aleksander Gajewski <aleksanderx.gajewski@intel.com>
> 
> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Applied to dpdk-next-crypto.
Thanks,

Pablo
  

Patch

diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c
index 6c128d8..08bf5e4 100644
--- a/app/test-crypto-perf/main.c
+++ b/app/test-crypto-perf/main.c
@@ -264,7 +264,7 @@ 
 
 	void *ctx[RTE_MAX_LCORE] = { };
 
-	int nb_cryptodevs;
+	int nb_cryptodevs = 0;
 	uint8_t cdev_id, i;
 	uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 };
 
@@ -300,6 +300,7 @@ 
 	if (nb_cryptodevs < 1) {
 		RTE_LOG(ERR, USER1, "Failed to initialise requested crypto "
 				"device type\n");
+		nb_cryptodevs = 0;
 		goto err;
 	}
 
@@ -397,7 +398,6 @@ 
 err:
 	i = 0;
 	RTE_LCORE_FOREACH_SLAVE(lcore_id) {
-
 		if (i == nb_cryptodevs)
 			break;