From: Hangbin Liu <liuhangbin@gmail.com>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Hangbin Liu <liuhangbin@gmail.com>, Phil Sutter <phil@nwl.cc>
Subject: [PATCH iproute2] devlink: Convert conditional in dl_argv_handle_port() to switch()
Date: Sun, 9 Oct 2016 10:14:18 +0800 [thread overview]
Message-ID: <1475979258-29222-1-git-send-email-liuhangbin@gmail.com> (raw)
Discovered by Phil's covscan. The final return statement is never reached.
This is not inherently clear from looking at the code, so change the
conditional to a switch() statement which should clarify this.
CC: Phil Sutter <phil@nwl.cc>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
devlink/devlink.c | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index e91dc50..ccca0fb 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -524,19 +524,18 @@ static int dl_argv_handle_port(struct dl *dl, char **p_bus_name,
return -EINVAL;
}
slash_count = strslashcount(str);
- if (slash_count != 2 && slash_count != 0) {
+ switch (slash_count) {
+ case 0:
+ return __dl_argv_handle_port_ifname(dl, str, p_bus_name,
+ p_dev_name, p_port_index);
+ case 2:
+ return __dl_argv_handle_port(str, p_bus_name,
+ p_dev_name, p_port_index);
+ default:
pr_err("Wrong port identification string format.\n");
pr_err("Expected \"bus_name/dev_name/port_index\" or \"netdev_ifname\".\n");
return -EINVAL;
}
- if (slash_count == 2) {
- return __dl_argv_handle_port(str, p_bus_name,
- p_dev_name, p_port_index);
- } else if (slash_count == 0) {
- return __dl_argv_handle_port_ifname(dl, str, p_bus_name,
- p_dev_name, p_port_index);
- }
- return 0;
}
static int dl_argv_handle_both(struct dl *dl, char **p_bus_name,
--
2.5.5
next reply other threads:[~2016-10-09 2:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-09 2:14 Hangbin Liu [this message]
2016-10-09 9:10 ` [PATCH iproute2] devlink: Convert conditional in dl_argv_handle_port() to switch() Phil Sutter
2016-10-17 12:31 ` Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1475979258-29222-1-git-send-email-liuhangbin@gmail.com \
--to=liuhangbin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=phil@nwl.cc \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).