* [PATCH 1/2] net: netrom: mark expected switch fall-throughs
@ 2017-10-19 17:21 Gustavo A. R. Silva
2017-10-19 17:27 ` [PATCH 2/2] net: netrom: refactor code in nr_add_node Gustavo A. R. Silva
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2017-10-19 17:21 UTC (permalink / raw)
To: Ralf Baechle, David S. Miller
Cc: linux-hams, netdev, linux-kernel, Gustavo A. R. Silva
In preparation to enabling -Wimplicit-fallthrough, mark switch cases
where we are expecting to fall through.
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
This code was tested by compilation only (GCC 7.2.0 was used).
Please, verify if the actual intention of the code is to fall through.
net/netrom/nr_route.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index 0c59354..fc9cadc 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -279,6 +279,7 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
nr_node->routes[1] = nr_node->routes[2];
nr_node->routes[2] = nr_route;
}
+ /* fall through */
case 2:
if (nr_node->routes[1].quality > nr_node->routes[0].quality) {
switch (nr_node->which) {
@@ -384,6 +385,7 @@ static int nr_del_node(ax25_address *callsign, ax25_address *neighbour, struct n
switch (i) {
case 0:
nr_node->routes[0] = nr_node->routes[1];
+ /* fall through */
case 1:
nr_node->routes[1] = nr_node->routes[2];
case 2:
@@ -506,7 +508,7 @@ static int nr_dec_obs(void)
switch (i) {
case 0:
s->routes[0] = s->routes[1];
- /* Fallthrough */
+ /* fall through */
case 1:
s->routes[1] = s->routes[2];
case 2:
@@ -553,6 +555,7 @@ void nr_rt_device_down(struct net_device *dev)
switch (i) {
case 0:
t->routes[0] = t->routes[1];
+ /* fall through */
case 1:
t->routes[1] = t->routes[2];
case 2:
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [PATCH 2/2] net: netrom: refactor code in nr_add_node
2017-10-19 17:21 [PATCH 1/2] net: netrom: mark expected switch fall-throughs Gustavo A. R. Silva
@ 2017-10-19 17:27 ` Gustavo A. R. Silva
0 siblings, 0 replies; 2+ messages in thread
From: Gustavo A. R. Silva @ 2017-10-19 17:27 UTC (permalink / raw)
To: Ralf Baechle, David S. Miller
Cc: linux-hams, netdev, linux-kernel, Gustavo A. R. Silva
Code refactoring in order to make the code easier to read and maintain.
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
This code was tested by compilation only (GCC 7.2.0 was used).
net/netrom/nr_route.c | 63 ++++++++++++++++-----------------------------------
1 file changed, 20 insertions(+), 43 deletions(-)
diff --git a/net/netrom/nr_route.c b/net/netrom/nr_route.c
index fc9cadc..1e5165f 100644
--- a/net/netrom/nr_route.c
+++ b/net/netrom/nr_route.c
@@ -80,6 +80,23 @@ static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign,
static void nr_remove_neigh(struct nr_neigh *);
+/* re-sort the routes in quality order. */
+static inline void re_sort_routes(struct nr_node *nr_node, int ix_x, int ix_y)
+{
+ struct nr_route nr_route;
+
+ if (nr_node->routes[ix_y].quality > nr_node->routes[ix_x].quality) {
+ if (nr_node->which == ix_x)
+ nr_node->which = ix_y;
+ else if (nr_node->which == ix_y)
+ nr_node->which = ix_x;
+
+ nr_route = nr_node->routes[ix_x];
+ nr_node->routes[ix_x] = nr_node->routes[ix_y];
+ nr_node->routes[ix_y] = nr_route;
+ }
+}
+
/*
* Add a new route to a node, and in the process add the node and the
* neighbour if it is new.
@@ -90,7 +107,6 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
{
struct nr_node *nr_node;
struct nr_neigh *nr_neigh;
- struct nr_route nr_route;
int i, found;
struct net_device *odev;
@@ -251,50 +267,11 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
/* Now re-sort the routes in quality order */
switch (nr_node->count) {
case 3:
- if (nr_node->routes[1].quality > nr_node->routes[0].quality) {
- switch (nr_node->which) {
- case 0:
- nr_node->which = 1;
- break;
- case 1:
- nr_node->which = 0;
- break;
- }
- nr_route = nr_node->routes[0];
- nr_node->routes[0] = nr_node->routes[1];
- nr_node->routes[1] = nr_route;
- }
- if (nr_node->routes[2].quality > nr_node->routes[1].quality) {
- switch (nr_node->which) {
- case 1: nr_node->which = 2;
- break;
-
- case 2: nr_node->which = 1;
- break;
-
- default:
- break;
- }
- nr_route = nr_node->routes[1];
- nr_node->routes[1] = nr_node->routes[2];
- nr_node->routes[2] = nr_route;
- }
+ re_sort_routes(nr_node, 0, 1);
+ re_sort_routes(nr_node, 1, 2);
/* fall through */
case 2:
- if (nr_node->routes[1].quality > nr_node->routes[0].quality) {
- switch (nr_node->which) {
- case 0: nr_node->which = 1;
- break;
-
- case 1: nr_node->which = 0;
- break;
-
- default: break;
- }
- nr_route = nr_node->routes[0];
- nr_node->routes[0] = nr_node->routes[1];
- nr_node->routes[1] = nr_route;
- }
+ re_sort_routes(nr_node, 0, 1);
case 1:
break;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-19 17:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-19 17:21 [PATCH 1/2] net: netrom: mark expected switch fall-throughs Gustavo A. R. Silva
2017-10-19 17:27 ` [PATCH 2/2] net: netrom: refactor code in nr_add_node Gustavo A. R. Silva
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox