From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B93CCA00C5; Thu, 11 Jun 2020 14:38:04 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4032E2C15; Thu, 11 Jun 2020 14:38:04 +0200 (CEST) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by dpdk.org (Postfix) with ESMTP id 5683D2BE2 for ; Thu, 11 Jun 2020 14:38:03 +0200 (CEST) Received: by mail-wr1-f66.google.com with SMTP id x13so6000620wrv.4 for ; Thu, 11 Jun 2020 05:38:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=emumba-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=VVk3TqC/gDlTv0eW5fBLQZXkQEvkwAINLQlgqPndRPk=; b=awpByL5BUcX4Xbtd9OmIDJP7yuU7TFv2lCZtjV+YAXG2GKCf89yVU2deYN+9mjpDux 5fk//z8doR//2F1avQoOBam4XFBPTyBaa68YYlXs/GZM+EkjFGXPPVGzIgYwPWkjdh57 mAuPUI1dYqDONFUez8IQPt8eBv7waQALVUrhuNfhhUIQsgYA8cY86joq2m87U+Ehm6QX 6VaEN1CCIYzYD+ZFZRvcGi/0ooZ8759AcGVTjKO2CsqKThrr1ppdVSXfAipYoI5FYO/L I9pthsdgzgeARNfS1d77t9d5D+iYQ5t3SzHxtnmEBZsJVw3BhVPNXkc+EJpWtn60boZJ q1lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VVk3TqC/gDlTv0eW5fBLQZXkQEvkwAINLQlgqPndRPk=; b=CuY85eDFUBj4KtTjUXcCNgZU+2CGylqsrx+nix1NyUAttbKilG1Zeic1P87H3EjBgd /tElSi6r5f/I28Q1HRJvU7rqoZQ89zl1YOJRrQFNaNXpV+Mb0UzR6iCwiiQCjvpEqzMC 1H1eXibNVfUoWXAz2EYLA6FVC53bKwS9azwD01rJg8BJd+olLvQbfNwnQhXaEP0Pp1n/ vbx+aEE1bMkwnPuVtkE7y4cu7T1hL6CpPXTwzAcLPYWJ12KJeqgVUXRUv1zdsPHiVEjG F5iUM4Tz3OPd3NZEhzzfwnOhsrYcot5m1LaQl+3fbKt9IaDTnCNUu/TtQYlRf9BNzM5R 1Zpw== X-Gm-Message-State: AOAM5317PtsShiG4JJ8p5sRqgykM/UFqfWBqMQMJrntT3NwDv9sX+H0x UN+zVWug13JXujxmb8MENYUPQENvL4joiqaG X-Google-Smtp-Source: ABdhPJyEsBZwc7Gd3Ixt9/4nM02xh2kfxJBRb4xTgS5y/MRfIsOkO76iuQOBOlJ8q2LmZtdGmbE5gg== X-Received: by 2002:a5d:6802:: with SMTP id w2mr9421579wru.68.1591879082582; Thu, 11 Jun 2020 05:38:02 -0700 (PDT) Received: from localhost.localdomain ([182.191.83.208]) by smtp.gmail.com with ESMTPSA id u12sm4722642wrq.90.2020.06.11.05.37.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 05:38:02 -0700 (PDT) From: Sarosh Arif To: dev@dpdk.org, drc@linux.vnet.ibm.com, maxime.coquelin@redhat.com, zhihong.wang@intel.com, xiaolong.ye@intel.com, bruce.richardson@intel.com, konstantin.ananyev@intel.com, david.hunt@intel.com, jerinj@marvell.com, skori@marvell.com, john.mcnamara@intel.com, kirill.rybalchenko@intel.com Cc: stable@dpdk.org, Sarosh Arif Date: Thu, 11 Jun 2020 17:36:24 +0500 Message-Id: <20200611123624.25319-1-sarosh.arif@emumba.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] examples: fix return value of function that parses portmask X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- examples/distributor/main.c | 5 +---- examples/ioat/ioatfwd.c | 2 +- examples/ip_reassembly/main.c | 5 +---- examples/l2fwd-event/main.c | 5 +---- examples/l2fwd-jobstats/main.c | 5 +---- examples/l2fwd-keepalive/main.c | 5 +---- examples/l2fwd/main.c | 5 +---- examples/l3fwd-acl/main.c | 5 +---- examples/l3fwd-graph/main.c | 5 +---- examples/l3fwd-power/main.c | 5 +---- examples/l3fwd/main.c | 5 +---- examples/link_status_interrupt/main.c | 5 +---- examples/performance-thread/l3fwd-thread/main.c | 5 +---- examples/ptpclient/ptpclient.c | 5 +---- examples/qos_meter/main.c | 5 +---- examples/tep_termination/main.c | 5 +---- examples/vhost/main.c | 5 +---- examples/vm_power_manager/main.c | 5 +---- examples/vmdq/main.c | 5 +---- examples/vmdq_dcb/main.c | 5 +---- 20 files changed, 20 insertions(+), 77 deletions(-) diff --git a/examples/distributor/main.c b/examples/distributor/main.c index 567c5e989..dca48c2ab 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 53de23179..863dc0454 100644 --- a/examples/ioat/ioatfwd.c +++ b/examples/ioat/ioatfwd.c @@ -582,7 +582,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 494d7ee77..550fb53be 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 9593ef11e..951a02106 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 396fd89db..275407419 100644 --- a/examples/l2fwd-jobstats/main.c +++ b/examples/l2fwd-jobstats/main.c @@ -562,10 +562,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 b7585d55e..8d4a65990 100644 --- a/examples/l2fwd-keepalive/main.c +++ b/examples/l2fwd-keepalive/main.c @@ -305,10 +305,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 f8d14b843..a99b7558a 100644 --- a/examples/l2fwd/main.c +++ b/examples/l2fwd/main.c @@ -311,10 +311,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 f22fca732..112ec3d2c 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 c70270c4d..d3fcf411c 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 9db94ce04..9dde35c7d 100644 --- a/examples/l3fwd-power/main.c +++ b/examples/l3fwd-power/main.c @@ -1470,10 +1470,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 24ede4290..de6c62293 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 25efe2b09..a6b4aa1dc 100644 --- a/examples/link_status_interrupt/main.c +++ b/examples/link_status_interrupt/main.c @@ -312,10 +312,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/performance-thread/l3fwd-thread/main.c b/examples/performance-thread/l3fwd-thread/main.c index 84c1d7b3a..e32802aa9 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 bfa86eec5..20da32517 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 6d057abfe..ce87b2eca 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 ab956ad7c..4cb102119 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 ab649bf14..690b50f85 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 273bfec29..ef9c0684a 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 d08826c86..660be4011 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 f417b2fd9..83a6843ee 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; } -- 2.17.1