From: Sarosh Arif Date: Thu, 11 Jun 2020 12:36:24 +0000 (+0500) Subject: examples: fix port mask parsing failure handling X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=ce6b8c31548b4d71a986d9807cd06cf3a616d1ab examples: fix port mask parsing failure handling Giving invalid or zero portmask as command line option to these applications will have an unexpected response. The reason behind this is that the return value of function that parses portmask is stored in a variable whose datatype 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 zero is returned. Signed-off-by: Sarosh Arif Acked-by: Bruce Richardson --- diff --git a/examples/distributor/main.c b/examples/distributor/main.c index 567c5e9891..dca48c2abd 100644 --- a/examples/distributor/main.c +++ b/examples/distributor/main.c @@ -647,10 +647,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; } diff --git a/examples/ioat/ioatfwd.c b/examples/ioat/ioatfwd.c index b66ee73bce..75d8d5b9fe 100644 --- a/examples/ioat/ioatfwd.c +++ b/examples/ioat/ioatfwd.c @@ -584,7 +584,7 @@ ioat_parse_portmask(const char *portmask) /* Parse hexadecimal string */ pm = strtoul(portmask, &end, 16); if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) - return -1; + return 0; return pm; } diff --git a/examples/ip_reassembly/main.c b/examples/ip_reassembly/main.c index 494d7ee776..550fb53bec 100644 --- a/examples/ip_reassembly/main.c +++ b/examples/ip_reassembly/main.c @@ -580,10 +580,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; } diff --git a/examples/l2fwd-event/main.c b/examples/l2fwd-event/main.c index 4fe500333c..6f2076696a 100644 --- a/examples/l2fwd-event/main.c +++ b/examples/l2fwd-event/main.c @@ -39,10 +39,7 @@ l2fwd_event_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; } diff --git a/examples/l2fwd-jobstats/main.c b/examples/l2fwd-jobstats/main.c index 47a3b09765..29d5705840 100644 --- a/examples/l2fwd-jobstats/main.c +++ b/examples/l2fwd-jobstats/main.c @@ -565,10 +565,7 @@ l2fwd_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; } diff --git a/examples/l2fwd-keepalive/main.c b/examples/l2fwd-keepalive/main.c index b2742633bc..35d10e5a0e 100644 --- a/examples/l2fwd-keepalive/main.c +++ b/examples/l2fwd-keepalive/main.c @@ -307,10 +307,7 @@ l2fwd_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; } diff --git a/examples/l2fwd/main.c b/examples/l2fwd/main.c index e04c601b5c..b5fb905624 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -325,10 +325,7 @@ l2fwd_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; } diff --git a/examples/l3fwd-acl/main.c b/examples/l3fwd-acl/main.c index f22fca7328..112ec3d2cc 100644 --- a/examples/l3fwd-acl/main.c +++ b/examples/l3fwd-acl/main.c @@ -1567,10 +1567,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; } diff --git a/examples/l3fwd-graph/main.c b/examples/l3fwd-graph/main.c index c70270c4d1..d3fcf411ce 100644 --- a/examples/l3fwd-graph/main.c +++ b/examples/l3fwd-graph/main.c @@ -302,10 +302,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; } diff --git a/examples/l3fwd-power/main.c b/examples/l3fwd-power/main.c index 6a4a27984b..afa38c158c 100644 --- a/examples/l3fwd-power/main.c +++ b/examples/l3fwd-power/main.c @@ -1635,10 +1635,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; } diff --git a/examples/l3fwd/main.c b/examples/l3fwd/main.c index 24ede42903..de6c62293a 100644 --- a/examples/l3fwd/main.c +++ b/examples/l3fwd/main.c @@ -340,10 +340,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; } diff --git a/examples/link_status_interrupt/main.c b/examples/link_status_interrupt/main.c index 9bbcadfcf8..d1ce6abed5 100644 --- a/examples/link_status_interrupt/main.c +++ b/examples/link_status_interrupt/main.c @@ -314,10 +314,7 @@ lsi_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; } diff --git a/examples/packet_ordering/main.c b/examples/packet_ordering/main.c index b397b318e6..5c654c11c6 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; } diff --git a/examples/performance-thread/l3fwd-thread/main.c b/examples/performance-thread/l3fwd-thread/main.c index 84c1d7b3a2..e32802aa9b 100644 --- a/examples/performance-thread/l3fwd-thread/main.c +++ b/examples/performance-thread/l3fwd-thread/main.c @@ -2681,10 +2681,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; } diff --git a/examples/ptpclient/ptpclient.c b/examples/ptpclient/ptpclient.c index bfa86eec5a..20da325170 100644 --- a/examples/ptpclient/ptpclient.c +++ b/examples/ptpclient/ptpclient.c @@ -650,10 +650,7 @@ ptp_parse_portmask(const char *portmask) pm = strtoul(portmask, &end, 16); if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0')) - return -1; - - if (pm == 0) - return -1; + return 0; return pm; } diff --git a/examples/qos_meter/main.c b/examples/qos_meter/main.c index 6d057abfe3..ce87b2eca2 100644 --- a/examples/qos_meter/main.c +++ b/examples/qos_meter/main.c @@ -220,10 +220,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; } diff --git a/examples/tep_termination/main.c b/examples/tep_termination/main.c index b9fffca020..232ed59b6e 100644 --- a/examples/tep_termination/main.c +++ b/examples/tep_termination/main.c @@ -203,10 +203,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; } diff --git a/examples/vhost/main.c b/examples/vhost/main.c index 312829e8b9..e1578e7956 100644 --- a/examples/vhost/main.c +++ b/examples/vhost/main.c @@ -407,10 +407,7 @@ parse_portmask(const char *portmask) /* parse hexadecimal string */ pm = strtoul(portmask, &end, 16); if ((portmask[0] == '\0') || (end == NULL) || (*end != '\0') || (errno != 0)) - return -1; - - if (pm == 0) - return -1; + return 0; return pm; diff --git a/examples/vm_power_manager/main.c b/examples/vm_power_manager/main.c index 77797b1e16..3a89580589 100644 --- a/examples/vm_power_manager/main.c +++ b/examples/vm_power_manager/main.c @@ -144,10 +144,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; } diff --git a/examples/vmdq/main.c b/examples/vmdq/main.c index d08826c868..660be4011e 100644 --- a/examples/vmdq/main.c +++ b/examples/vmdq/main.c @@ -370,10 +370,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; } diff --git a/examples/vmdq_dcb/main.c b/examples/vmdq_dcb/main.c index f417b2fd9b..83a6843ee5 100644 --- a/examples/vmdq_dcb/main.c +++ b/examples/vmdq_dcb/main.c @@ -424,10 +424,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; }