examples/packet_ordering: fix return value of parse_portmask

Message ID 20200605134114.23149-1-sarosh.arif@emumba.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series examples/packet_ordering: fix return value of parse_portmask |

Checks

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

Commit Message

Sarosh Arif June 5, 2020, 1:41 p.m. UTC
  Giving invalid or zero portmask as command line option to 
packet_ordering application will have an unexpected response.
The reason behind this is that parse_portmask's return value is
stored in a variable called portmask.The data type of portmask 
is unsigned int, hence returning -1 in case of zero or invalid
portmask causes an unexpected behaviour. 
If we return 0 instead of -1 this issue can be resolved.
The program already contains the functionality to print
"invalid portmask" and program usage if portmask is zero.

Fixes: 850f3733f840 ("examples/packet_ordering: new sample app")

Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>
---
 examples/packet_ordering/main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
  

Comments

Thomas Monjalon July 30, 2020, 9:18 p.m. UTC | #1
05/06/2020 15:41, Sarosh Arif:
> Giving invalid or zero portmask as command line option to 
> packet_ordering application will have an unexpected response.
> The reason behind this is that parse_portmask's return value is
> stored in a variable called portmask.The data type of portmask 
> is unsigned int, hence returning -1 in case of zero or invalid
> portmask causes an unexpected behaviour. 
> If we return 0 instead of -1 this issue can be resolved.
> The program already contains the functionality to print
> "invalid portmask" and program usage if portmask is zero.
> 
> Fixes: 850f3733f840 ("examples/packet_ordering: new sample app")
> 
> Signed-off-by: Sarosh Arif <sarosh.arif@emumba.com>

Merged with same fix for other examples, thanks.
  

Patch

diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c
index edaf810d9..b5fc6c54b 100644
--- a/examples/packet_ordering/main.c
+++ b/examples/packet_ordering/main.c
@@ -143,10 +143,7 @@  parse_portmask(const char *portmask)
 	/* parse hexadecimal string */
 	pm = strtoul(portmask, &end, 16);
 	if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0'))
-		return -1;
-
-	if (pm == 0)
-		return -1;
+		return 0;
 
 	return pm;
 }