All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] devlink: Convert conditional in dl_argv_handle_port() to switch()
@ 2016-10-09  2:14 Hangbin Liu
  2016-10-09  9:10 ` Phil Sutter
  2016-10-17 12:31 ` Stephen Hemminger
  0 siblings, 2 replies; 3+ messages in thread
From: Hangbin Liu @ 2016-10-09  2:14 UTC (permalink / raw)
  To: netdev; +Cc: Stephen Hemminger, Hangbin Liu, Phil Sutter

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

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2] devlink: Convert conditional in dl_argv_handle_port() to switch()
  2016-10-09  2:14 [PATCH iproute2] devlink: Convert conditional in dl_argv_handle_port() to switch() Hangbin Liu
@ 2016-10-09  9:10 ` Phil Sutter
  2016-10-17 12:31 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Phil Sutter @ 2016-10-09  9:10 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, Stephen Hemminger

On Sun, Oct 09, 2016 at 10:14:18AM +0800, Hangbin Liu wrote:
> 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>

Acked-by: Phil Sutter <phil@nwl.cc>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH iproute2] devlink: Convert conditional in dl_argv_handle_port() to switch()
  2016-10-09  2:14 [PATCH iproute2] devlink: Convert conditional in dl_argv_handle_port() to switch() Hangbin Liu
  2016-10-09  9:10 ` Phil Sutter
@ 2016-10-17 12:31 ` Stephen Hemminger
  1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2016-10-17 12:31 UTC (permalink / raw)
  To: Hangbin Liu; +Cc: netdev, Phil Sutter

On Sun,  9 Oct 2016 10:14:18 +0800
Hangbin Liu <liuhangbin@gmail.com> wrote:

> 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>

Applied thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-10-17 12:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-09  2:14 [PATCH iproute2] devlink: Convert conditional in dl_argv_handle_port() to switch() Hangbin Liu
2016-10-09  9:10 ` Phil Sutter
2016-10-17 12:31 ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.