Skip to contentSkip to conversation

net: netrom: mark expected switch fall-throughs

PATCH In review Gustavo A. R. Silva 6 participants 22 messages Oct 19, 2017 – Nov 8, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 net: netrom: mark expected switch fall-throughs

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

---
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(-)
net/netrom/nr_route.c +4 -1
index 0c59354..fc9cadc 100644
@@ -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:
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 2/2 net: netrom: refactor code in nr_add_node

Code refactoring in order to make the code easier to read and maintain.

---
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(-)
net/netrom/nr_route.c +20 -43
index fc9cadc..1e5165f 100644
@@ -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;
 	}
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 2/2] net: netrom: refactor code in nr_add_node

Am 19.10.2017 19:27, schrieb Gustavo A. R. Silva:

Quoted 24 lines

Code refactoring in order to make the code easier to read and maintain.

---
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(-)
net/netrom/nr_route.c +7 -0
index fc9cadc..1e5165f 100644
@@ -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)

net/netrom/nr_route.c static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign, · line 99

Quoted 10 lines
net/netrom/nr_route.c +10 -0
+			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;
+	}
+}
+

Good idea, a bit of nit picking ..
does ix_ has a special meaning ? otherwise x,y would be sufficient. From the code below i can see: y=x+1 Perhaps that can be used.

kernel.h has a swap() macro. so you can swap(nr_node->routes[x],nr_node->routes[y]);

hope that helps,
re,
wh

Quoted 65 lines
net/netrom/nr_route.c +3 -43
 /*
  *	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;
 	}
#3 lore raw

Re: [PATCH 2/2] net: netrom: refactor code in nr_add_node

Hi Walter,

Quoting walter harms <[email protected]>:

Quoted 34 lines

Am 19.10.2017 19:27, schrieb Gustavo A. R. Silva:

Quoted 33 lines

Code refactoring in order to make the code easier to read and maintain.

---
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(-)
net/netrom/nr_route.c +13 -0
index fc9cadc..1e5165f 100644
@@ -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];
Quoted 8 lines

net/netrom/nr_route.c static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign, · line 99

Quoted 4 lines
net/netrom/nr_route.c +4 -0
+		nr_node->routes[ix_y] = nr_route;
+	}
+}
+

Good idea, a bit of nit picking ..
does ix_ has a special meaning ? otherwise x,y would be sufficient.

ix typical stands for index, but I think just x and y are fine too.

Quoted 2 lines

From the code below i can see: y=x+1 Perhaps that can be used.

So are you proposing to use two arguments instead of three?

re_sort_routes(nr_node, 0);

Quoted 2 lines

kernel.h has a swap() macro. so you can swap(nr_node->routes[x],nr_node->routes[y]);

Nice, I will use that macro.

Quoted 1 line

hope that helps,

Definitely. I appreciate your comments.

Thanks!

#4 lore raw

Re: [PATCH 2/2] net: netrom: refactor code in nr_add_node

Am 20.10.2017 18:06, schrieb Gustavo A. R. Silva:

Quoted 48 lines

Hi Walter,

Quoting walter harms <[email protected]>:

Quoted 35 lines

Am 19.10.2017 19:27, schrieb Gustavo A. R. Silva:

Quoted 34 lines

Code refactoring in order to make the code easier to read and maintain.

---
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(-)
net/netrom/nr_route.c +13 -0
index fc9cadc..1e5165f 100644
@@ -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];
Quoted 8 lines

net/netrom/nr_route.c static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign, · line 99

Quoted 4 lines
net/netrom/nr_route.c +4 -0
+        nr_node->routes[ix_y] = nr_route;
+    }
+}
+

Good idea, a bit of nit picking ..
does ix_ has a special meaning ? otherwise x,y would be sufficient.

Quoted 9 lines

ix typical stands for index, but I think just x and y are fine too.

Quoted 2 lines

From the code below i can see: y=x+1 Perhaps that can be used.

So are you proposing to use two arguments instead of three?

re_sort_routes(nr_node, 0);

I am not sure, i would wait a bit and see if what improves readability. as Kevin Dawson pointed out: this is a sort here.
Maybe there a nice way to do something like that (i do not know):

case 3:
re_sort_routes(nr_node, 1,2)
case 2:
re_sort_routes(nr_node, 0,1)
case 1:
break;

The question is: Is the sorted list needed or simply the maximum ?

NTL is a good thing to chop down the function in smaller digestible peaces.

re,
wh

Quoted 25 lines
Quoted 4 lines

kernel.h has a swap() macro. so you can
swap(nr_node->routes[x],nr_node->routes[y]);

Nice, I will use that macro.

Quoted 1 line

hope that helps,

Definitely. I appreciate your comments.

Thanks!

Signature · 1 line
Gustavo A. R. Silva
#5 lore raw

Re: [PATCH 2/2] net: netrom: refactor code in nr_add_node

Hello all.

My original response just went to Gustavo and Walter because I'm not much of a kernel hacker these days; it was mainly observations that may or may not have been helpful and I'm not a regular list contributor. Looks like I shouldn't have been so shy!

Quoted 13 lines · walter harms

...

Quoted 5 lines
Quoted 1 line

From the code below i can see: y=x+1 Perhaps that can be used.

So are you proposing to use two arguments instead of three?

re_sort_routes(nr_node, 0);

I am not sure, i would wait a bit and see if what improves readability. as Kevin Dawson pointed out: this is a sort here.
Maybe there a nice way to do something like that (i do not know):

Quoted 6 lines

case 3:
re_sort_routes(nr_node, 1,2)
case 2:
re_sort_routes(nr_node, 0,1)
case 1:
break;

Nearly - you left out one of the calls to re_sort_routes. I include my original mail here, as it explains it better:

Quoted 53 lines

Hi Walter and Gustavo.

I've just left this response for the two of you, as it's a long time since I've been fiddling in the kernel and I don't know much of the current ideology regarding how people want their coding done.

I also only have a passing knowledge of NetRom, but I do recall some of the principles like routes and their quality.

Quoted 3 lines · walter harms

Am 19.10.2017 19:27, schrieb Gustavo A. R. Silva:

Quoted 1 line

Code refactoring in order to make the code easier to read and maintain.

...

[ Gustavo ]

Quoted 2 lines

net/netrom/nr_route.c static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign, · line 84

Quoted 2 lines
net/netrom/nr_route.c +2 -0
+/*      re-sort the routes in quality order.    */
+static inline void re_sort_routes(struct nr_node *nr_node, int ix_x, int ix_y)

I'm curious as to why re_sort_routes() is declared inline. Its use below hardly gains any efficiency from saving function calls; as well, it's extra code space taken.

Quoted 4 lines

net/netrom/nr_route.c static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign, · line 92

Quoted 4 lines
net/netrom/nr_route.c +4 -0
+		if (nr_node->which == ix_x)
+			nr_node->which = ix_y;
+		else if (nr_node->which == ix_y)
+			nr_node->which = ix_x;

I suspect this can be simplified too, but I don't know what the possible values for ->which might be in any particular route case.

...

[ Walter ]

Quoted 13 lines

From the code below i can see: y=x+1 Perhaps that can be used.
...

Quoted 11 lines
net/netrom/nr_route.c +0 -0
 	/* Now re-sort the routes in quality order */
 	switch (nr_node->count) {
 	case 3:
 		re_sort_routes(nr_node, 0, 1);
 		re_sort_routes(nr_node, 1, 2);
 		/* fall through */
 	case 2:
 		re_sort_routes(nr_node, 0, 1);
 	case 1:
 		break;
 	}

Yes, it can and it makes sense to do so. The algorithm is an unrolled bubblesort for up to 3 routes. If 3 is as far as it will ever go (and given that's all the original function allowed for), it's not unjustified in leaving it that way. Anything more and I'd be suggesting it be made a loop.

Quoted 1 line

kernel.h has a swap() macro. so you can swap(nr_node->routes[x],nr_node->routes[y]);

I presume the swap() macro handles arbitrary types - structs and not just ints. If the aim is to improve readability of the code, it helps.

I hope I'm not completely out of line in suggesting this. As I say, it's been quite a while since I've dabbled in the kernel (although I did start back in the 1970s on Unix...).

Thanks,
Kevin

#6 lore raw

Re: [PATCH 2/2] net: netrom: refactor code in nr_add_node

In reply to walter harms

Quoting walter harms <[email protected]>:

Quoted 70 lines

Am 20.10.2017 18:06, schrieb Gustavo A. R. Silva:

Quoted 48 lines

Hi Walter,

Quoting walter harms <[email protected]>:

Quoted 35 lines

Am 19.10.2017 19:27, schrieb Gustavo A. R. Silva:

Quoted 34 lines

Code refactoring in order to make the code easier to read and maintain.

---
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(-)
net/netrom/nr_route.c +13 -0
index fc9cadc..1e5165f 100644
@@ -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];
Quoted 8 lines

net/netrom/nr_route.c static struct nr_neigh *nr_neigh_get_dev(ax25_address *callsign, · line 99

Quoted 4 lines
net/netrom/nr_route.c +4 -0
+        nr_node->routes[ix_y] = nr_route;
+    }
+}
+

Good idea, a bit of nit picking ..
does ix_ has a special meaning ? otherwise x,y would be sufficient.

Quoted 9 lines

ix typical stands for index, but I think just x and y are fine too.

Quoted 2 lines

From the code below i can see: y=x+1 Perhaps that can be used.

So are you proposing to use two arguments instead of three?

re_sort_routes(nr_node, 0);

I am not sure, i would wait a bit and see if what improves readability. as Kevin Dawson pointed out: this is a sort here.
Maybe there a nice way to do something like that (i do not know):

case 3:
re_sort_routes(nr_node, 1,2)
case 2:
re_sort_routes(nr_node, 0,1)
case 1:
break;

Quoted 5 lines

The question is: Is the sorted list needed or simply the maximum ?

NTL is a good thing to chop down the function in smaller digestible peaces.

I'll use the swap macro as you suggested and leave the rest of this patch as is for now.

Dawson:
Thanks for pointing out the thing about the inline keyword. I'll remove it.

Thanks
--
Gustavo A. R. Silva

Quoted 28 lines

re,
wh

Quoted 25 lines
Quoted 4 lines

kernel.h has a swap() macro. so you can
swap(nr_node->routes[x],nr_node->routes[y]);

Nice, I will use that macro.

Quoted 1 line

hope that helps,

Definitely. I appreciate your comments.

Thanks!
--
Gustavo A. R. Silva

#7 lore raw

PATCH v2 2/2 net: netrom: refactor code in nr_add_node

Code refactoring in order to make it easier to read and maintain.

---
This code was tested by compilation only.

Changes in v2:
Make use of the swap macro and remove inline keyword.

 net/netrom/nr_route.c | 59 ++++++++++++++-------------------------------------
 1 file changed, 16 insertions(+), 43 deletions(-)
net/netrom/nr_route.c +16 -43
index fc9cadc..505e142 100644
@@ -80,6 +80,19 @@ 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 void re_sort_routes(struct nr_node *nr_node, int x, int y)
+{
+	if (nr_node->routes[y].quality > nr_node->routes[x].quality) {
+		if (nr_node->which == x)
+			nr_node->which = y;
+		else if (nr_node->which == y)
+			nr_node->which = x;
+
+		swap(nr_node->routes[x], nr_node->routes[y]);
+	}
+}
+
 /*
  *	Add a new route to a node, and in the process add the node and the
  *	neighbour if it is new.
@@ -90,7 +103,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 +263,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;
 	}
Signature · 1 line
2.7.4
maintainer
#8 lore raw

Re: [PATCH v2 2/2] net: netrom: refactor code in nr_add_node

From: "Gustavo A. R. Silva" <[email protected]>
Date: Sun, 22 Oct 2017 20:08:40 -0500

Quoted 3 lines

Code refactoring in order to make it easier to read and maintain.

Gustavo, always when reposting a new version of a patch that is part of a series you must _always_ repost the entire patch series.

Also, a proper patch series must begine with a "[PATCH 0/2] ..." header posting explaining at a high level what the patch series is doing, how it is doing it, and why it is doing it that way.

Thank you.

#9 lore raw

Re: [PATCH v2 2/2] net: netrom: refactor code in nr_add_node

Quoting David Miller <[email protected]>:

Quoted 10 lines

From: "Gustavo A. R. Silva" <[email protected]>
Date: Sun, 22 Oct 2017 20:08:40 -0500

Quoted 3 lines

Code refactoring in order to make it easier to read and maintain.

Gustavo, always when reposting a new version of a patch that is part of a series you must _always_ repost the entire patch series.

OK. I got it.

Quoted 4 lines

Also, a proper patch series must begine with a "[PATCH 0/2] ..." header posting explaining at a high level what the patch series is doing, how it is doing it, and why it is doing it that way.

Yeah, in this case I thought there was no need for this as both patches are not actually related in terms of functionality. But now that I'm writing this, maybe that is precisely the reason why I should have posted such header...?

Thanks
--
Gustavo A. R. Silva

#10 lore raw

v3 cover refactor code and mark expected switch fall-throughs

The aim of this patchset is firstly to refactor code in nr_route.c in order to make it easier to read and maintain and, secondly, to mark some expected switch fall-throughs in preparation to enabling -Wimplicit-fallthrough.

I have to mention that I did not implement any unit test. If someone has any suggestions on how I could test this piece of code it'd be greatly appreciated.

Thanks

Changes in v2:
- Make use of the swap macro and remove inline keyword as suggested by Walter Harms and Kevin Dawson.

Changes in v3:
- Update subject for both patches.
- Add this cover letter as suggested by David Miller.

Gustavo A. R. Silva (2):
net: netrom: nr_route: refactor code in nr_add_node
net: netrom: nr_route: mark expected switch fall-throughs

 net/netrom/nr_route.c | 62 ++++++++++++++++-----------------------------------
 1 file changed, 19 insertions(+), 43 deletions(-)
Signature · 1 line
2.7.4
#11 lore raw

PATCH v3 1/2 net: netrom: nr_route: refactor code in nr_add_node

Code refactoring in order to make the code easier to read and maintain.

---
Changes in v2:
Make use of the swap macro and remove inline keyword.

Changes in v3:
Update subject.

 net/netrom/nr_route.c | 59 ++++++++++++++-------------------------------------
 1 file changed, 16 insertions(+), 43 deletions(-)
net/netrom/nr_route.c +16 -43
index 0c59354..fba4b4c 100644
@@ -80,6 +80,19 @@ 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 void re_sort_routes(struct nr_node *nr_node, int x, int y)
+{
+	if (nr_node->routes[y].quality > nr_node->routes[x].quality) {
+		if (nr_node->which == x)
+			nr_node->which = y;
+		else if (nr_node->which == y)
+			nr_node->which = x;
+
+		swap(nr_node->routes[x], nr_node->routes[y]);
+	}
+}
+
 /*
  *	Add a new route to a node, and in the process add the node and the
  *	neighbour if it is new.
@@ -90,7 +103,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,49 +263,10 @@ 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);
 	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;
 	}
Signature · 1 line
2.7.4
#12 lore raw

PATCH v3 2/2 net: netrom: nr_route: mark expected switch fall-throughs

In reply to Gustavo A. R. Silva

In preparation to enabling -Wimplicit-fallthrough, mark switch cases where we are expecting to fall through.

---
Changes in v2:
None.

Changes in v3:
Update subject.

 net/netrom/nr_route.c | 3 +++
 1 file changed, 3 insertions(+)
net/netrom/nr_route.c +3 -0
index fba4b4c..75e6ba9 100644
@@ -265,6 +265,7 @@ static int __must_check nr_add_node(ax25_address *nr, const char *mnemonic,
 	case 3:
 		re_sort_routes(nr_node, 0, 1);
 		re_sort_routes(nr_node, 1, 2);
+		/* fall through */
 	case 2:
 		re_sort_routes(nr_node, 0, 1);
 	case 1:
@@ -357,6 +358,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:
@@ -526,6 +528,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:
Signature · 1 line
2.7.4
#13 lore raw

Re: [PATCH v3 0/2] refactor code and mark expected switch fall-throughs

In reply to Gustavo A. R. Silva

Hello Gustavo,

I appreciate you working on keeping up the kernel and maintaining some of the older feature areas like AX.25, Netrom, etc. Other than auditing your code changes, can you tell me what you're changing? I've been attempting to find who / where does regression tests for the Linus kernel to potentially ADD test suites for this area. In the recent past, we have seen a lot of toxicity creep into the kernel because no one is testing their changes and backing out this toxic code out of released Linux distributions takes a VERY long time.

I'm willing to try and help here but I really would like to follow some team's guidelines of how they would like tests to be created, supported, etc. Be it in VMs, containers, specific automation languages, etc.

--David
KI6ZHD

Quoted 25 lines · Gustavo A. R. Silva

The aim of this patchset is firstly to refactor code in nr_route.c in order to make it easier to read and maintain and, secondly, to mark some expected switch fall-throughs in preparation to enabling -Wimplicit-fallthrough.

I have to mention that I did not implement any unit test. If someone has any suggestions on how I could test this piece of code it'd be greatly appreciated.

Thanks

Changes in v2:
- Make use of the swap macro and remove inline keyword as suggested by Walter Harms and Kevin Dawson.

Changes in v3:
- Update subject for both patches.
- Add this cover letter as suggested by David Miller.

Gustavo A. R. Silva (2):
net: netrom: nr_route: refactor code in nr_add_node
net: netrom: nr_route: mark expected switch fall-throughs

  net/netrom/nr_route.c | 62 ++++++++++++++++-----------------------------------
  1 file changed, 19 insertions(+), 43 deletions(-)
#14 lore raw

Re: [PATCH v3 0/2] refactor code and mark expected switch fall-throughs

Hi David,

Quoting David Ranch <[email protected]>:

Quoted 4 lines

Hello Gustavo,

I appreciate you working on keeping up the kernel and maintaining some of the older feature areas like AX.25, Netrom, etc. Other than auditing your code changes, can you tell me what you're changing? I've been attempting to find who / where does regression tests for the Linus kernel to potentially ADD test suites for this area. In the recent past, we have seen a lot of toxicity creep into the kernel because no one is testing their changes and backing out this toxic code out of released Linux distributions takes a VERY long time.

Here you can see the patch I'm proposing to refactor some code:
https://patchwork.kernel.org/patch/10029119/

It does not add any new functionality. It's just a small function that helps to modularize and reduce the size of the code in the nr_add_node() function.

The function I'm proposing (re_sort_routes) re-sort the routes in quality order. It takes as arguments a pointer to the nr_node structure which contains the routes within and the indexes of the routes to re-sort.

This function also replaces a "manual" swap of the routes with a call to the swap macro.

Thanks
--
Gustavo A. R. Silva

Quoted 35 lines

I'm willing to try and help here but I really would like to follow some team's guidelines of how they would like tests to be created, supported, etc. Be it in VMs, containers, specific automation languages, etc.

--David
KI6ZHD

Quoted 26 lines · Gustavo A. R. Silva

The aim of this patchset is firstly to refactor code in nr_route.c in order to make it easier to read and maintain and, secondly, to mark some expected switch fall-throughs in preparation to enabling -Wimplicit-fallthrough.

I have to mention that I did not implement any unit test. If someone has any suggestions on how I could test this piece of code it'd be greatly appreciated.

Thanks

Changes in v2:
- Make use of the swap macro and remove inline keyword as suggested by Walter Harms and Kevin Dawson.

Changes in v3:
- Update subject for both patches.
- Add this cover letter as suggested by David Miller.

Gustavo A. R. Silva (2):
net: netrom: nr_route: refactor code in nr_add_node
net: netrom: nr_route: mark expected switch fall-throughs

 net/netrom/nr_route.c | 62  
++++++++++++++++-----------------------------------
 1 file changed, 19 insertions(+), 43 deletions(-)
#15 lore raw

Re: [PATCH v3 0/2] refactor code and mark expected switch fall-throughs

Hello Gustavo,

Thanks for the reply. I do appreciate the work but we've had other people contribute to keep things up to date but previous minor patches broke parts of the AX.25 stack in strange ways. The fixes weren't hard to repair or backout but due to the timing, various Linux distros based their releases on the broken kernel code and it's taken a LONG time to get things healthy for them. We need be able provide a test harness to developers to unit test / regression test their proposed code ideally AHEAD of the commit but at least after the commit.

I'm still failing to find any Linux groups that offer some sort of automated build & test environment (Travis, Jenkins, etc) tracking various kernel branches, etc. It's gotta be out there (many of them in fact) but I'm struggling to find them.

For example, here is an excellent article about what *Intel* is doing for their graphics drivers but I need something that the general community can leverage for say various protocol stacks (TCP/IP, AX.25, whatever):

https://lwn.net/Articles/735468/

From that article, it seems that maybe this could be a good place to start:

https://01.org/lkp
https://github.com/intel/lkp-tests

Looks like a good start but is that what the majority of the Linux kernel folk use today? Is it the right group for non-scaled out unit testing that I seek? I also think this email-centric approach might be an overly broad approach with WAY too much noise for various development areas.

Does anyone else have thoughts on this topic?

--David
KI6ZHD

Quoted 79 lines · Gustavo A. R. Silva

Hi David,

Quoting David Ranch <[email protected]>:

Quoted 11 lines

Hello Gustavo,

I appreciate you working on keeping up the kernel and maintaining some of the older feature areas like AX.25, Netrom, etc. Other than auditing your code changes, can you tell me what you're changing? I've been attempting to find who / where does regression tests for the Linus kernel to potentially ADD test suites for this area. In the recent past, we have seen a lot of toxicity creep into the kernel because no one is testing their changes and backing out this toxic code out of released Linux distributions takes a VERY long time.

Here you can see the patch I'm proposing to refactor some code:
https://patchwork.kernel.org/patch/10029119/

It does not add any new functionality. It's just a small function that helps to modularize and reduce the size of the code in the nr_add_node() function.

The function I'm proposing (re_sort_routes) re-sort the routes in quality order. It takes as arguments a pointer to the nr_node structure which contains the routes within and the indexes of the routes to re-sort.

This function also replaces a "manual" swap of the routes with a call to the swap macro.

Thanks
--
Gustavo A. R. Silva

Quoted 40 lines

I'm willing to try and help here but I really would like to follow some team's guidelines of how they would like tests to be created, supported, etc. Be it in VMs, containers, specific automation languages, etc.

--David
KI6ZHD

Quoted 28 lines · Gustavo A. R. Silva

The aim of this patchset is firstly to refactor code in nr_route.c in order to make it
easier to read and maintain and, secondly, to mark some expected switch fall-throughs
in preparation to enabling -Wimplicit-fallthrough.

I have to mention that I did not implement any unit test. If someone has any suggestions on how I could test this piece of code it'd be greatly appreciated.

Thanks

Changes in v2:
- Make use of the swap macro and remove inline keyword as suggested by Walter Harms and Kevin Dawson.

Changes in v3:
- Update subject for both patches.
- Add this cover letter as suggested by David Miller.

Gustavo A. R. Silva (2):
net: netrom: nr_route: refactor code in nr_add_node
net: netrom: nr_route: mark expected switch fall-throughs

 net/netrom/nr_route.c | 62
++++++++++++++++-----------------------------------
 1 file changed, 19 insertions(+), 43 deletions(-)
maintainer
#16 lore raw

Re: [PATCH v3 0/2] refactor code and mark expected switch fall-throughs

From: David Ranch <[email protected]>
Date: Sat, 28 Oct 2017 10:53:24 -0700

Quoted 1 line

Does anyone else have thoughts on this topic?

I think you are making a mountain out of a mole hill.

If you care so much about this, set things up so that entities such as the kbuild test robot run whatever tests you think are necessary.

Otherwise, continually test the stack yourself and report any regressions here as fast as you can.

If soemone can't be bothered to verify or test someone's change in 2 or 3 days, except in extreme circumstances, I absolutely refuse to burdon the submitter and let their patches rot in the queue.

That's unacceptable.

That's the proper way to deal with this, without unreasonably burdoning people who just want to keep the code across the tree modern and more up to date.

Thank you.

#17 lore raw

Re: [PATCH v3 0/2] refactor code and mark expected switch fall-throughs

Hello David,

Thanks for the reply. I completely admit that there aren't many changes going into this section of code. Unfortunately, we've had some nasty breaks that took quite a long while to get fixed.

Can you point me in the direction of this kbuild test robot (URLs, etc) so I can better understand if it makes sense to add tests there? For example, do you know if it's "changed based" so only certain tests will run if given files are updated?

--David
KI6ZHD

Quoted 24 lines · David Miller

From: David Ranch <[email protected]>
Date: Sat, 28 Oct 2017 10:53:24 -0700

Quoted 1 line

Does anyone else have thoughts on this topic?

I think you are making a mountain out of a mole hill.

If you care so much about this, set things up so that entities such as the kbuild test robot run whatever tests you think are necessary.

Otherwise, continually test the stack yourself and report any regressions here as fast as you can.

If soemone can't be bothered to verify or test someone's change in 2 or 3 days, except in extreme circumstances, I absolutely refuse to burdon the submitter and let their patches rot in the queue.

That's unacceptable.

That's the proper way to deal with this, without unreasonably burdoning people who just want to keep the code across the tree modern and more up to date.

Thank you.

#18 lore raw

Re: [PATCH v3 0/2] refactor code and mark expected switch fall-throughs

Hi all,
I just want to report that I applied the NetRom patch to most recent kernel. NetRom does not seem to be affected and connexion is doing well between my FPAC node f6bvp and f3kt.

73 de Bernard f6bvp

Sent from my iPhone

Quoted 38 lines

Le 29 oct. 2017 ¨¤ 05:15, David Ranch <[email protected]> a ¨¦crit :

Hello David,

Thanks for the reply. I completely admit that there aren't many changes going into this section of code. Unfortunately, we've had some nasty breaks that took quite a long while to get fixed.

Can you point me in the direction of this kbuild test robot (URLs, etc) so I can better understand if it makes sense to add tests there? For example, do you know if it's "changed based" so only certain tests will run if given files are updated?

--David
KI6ZHD

Quoted 25 lines · David Miller

From: David Ranch <[email protected]>
Date: Sat, 28 Oct 2017 10:53:24 -0700

Quoted 1 line

Does anyone else have thoughts on this topic?

I think you are making a mountain out of a mole hill.

If you care so much about this, set things up so that entities such as the kbuild test robot run whatever tests you think are necessary.

Otherwise, continually test the stack yourself and report any regressions here as fast as you can.

If soemone can't be bothered to verify or test someone's change in 2 or 3 days, except in extreme circumstances, I absolutely refuse to burdon the submitter and let their patches rot in the queue.

That's unacceptable.

That's the proper way to deal with this, without unreasonably burdoning people who just want to keep the code across the tree modern and more up to date.

Thank you.

maintainer
#19 lore raw

Re: [PATCH v3 0/2] refactor code and mark expected switch fall-throughs

In reply to Gustavo A. R. Silva

From: "Gustavo A. R. Silva" <[email protected]>
Date: Fri, 27 Oct 2017 00:50:57 -0500

Quoted 7 lines

The aim of this patchset is firstly to refactor code in nr_route.c in order to make it easier to read and maintain and, secondly, to mark some expected switch fall-throughs in preparation to enabling -Wimplicit-fallthrough.

I have to mention that I did not implement any unit test. If someone has any suggestions on how I could test this piece of code it'd be greatly appreciated.

Series applied, thank you.

#20 lore raw

Re: [PATCH v3 0/2] refactor code and mark expected switch fall-throughs

Quoting David Miller <[email protected]>:

Quoted 7 lines

From: "Gustavo A. R. Silva" <[email protected]>
Date: Fri, 27 Oct 2017 00:50:57 -0500

Quoted 4 lines

The aim of this patchset is firstly to refactor code in nr_route.c in order to make it easier to read and maintain and, secondly, to mark some expected switch fall-throughs in preparation to enabling -Wimplicit-fallthrough.

Quoted 5 lines
Quoted 3 lines

I have to mention that I did not implement any unit test. If someone has any suggestions on how I could test this piece of code it'd be greatly appreciated.

Series applied, thank you.

Glad to help.

Thanks
--
Gustavo A. R. Silva

#21 lore raw

PATCH v2 2/2 net: netrom: refactor code in nr_add_node

In reply to Gustavo A. R. Silva

Hey Everyone,

There are a LOT of patches coming in for the Linux AX.25 stack such as this one below where people are proposing changes and they OPENLY state:

"This code was tested by compilation only"

That's NOT testing. We have seen over the last year or two, several toxic commits have come into the kernel that have been extremely painful to rollback and/or modify to remove the toxicity. I completely appreciate people trying to keep the AX.25 stack cleaned up but it's CRITICAL that we get some AX.25 regress suites running so people can confirm that their proposed commits don't break anything before allowing the commits. I've been trying to find out who to discuss this proposed testing harness but I've been unable to get a name. Once I get a name, I'm happy to help contribute some testing suites, etc. once I understand the framework that this team(s) use.

--David
KI6ZHD

-------- Forwarded Message --------
Subject: [PATCH v2 2/2] net: netrom: refactor code in nr_add_node
Date: Sun, 22 Oct 2017 20:08:40 -0500
From: Gustavo A. R. Silva <[email protected]>
To: Ralf Baechle <[email protected]>, David S. Miller <[email protected]>, walter harms <[email protected]>
CC: [email protected], [email protected], [email protected], Gustavo A. R. Silva <[email protected]>

Code refactoring in order to make it easier to read and maintain.

---
This code was tested by compilation only.

Changes in v2:
Make use of the swap macro and remove inline keyword.

 net/netrom/nr_route.c | 59 ++++++++++++++-------------------------------------
 1 file changed, 16 insertions(+), 43 deletions(-)
net/netrom/nr_route.c +16 -43
index fc9cadc..505e142 100644
@@ -80,6 +80,19 @@ 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 void re_sort_routes(struct nr_node *nr_node, int x, int y)
+{
+	if (nr_node->routes[y].quality > nr_node->routes[x].quality) {
+		if (nr_node->which == x)
+			nr_node->which = y;
+		else if (nr_node->which == y)
+			nr_node->which = x;
+
+		swap(nr_node->routes[x], nr_node->routes[y]);
+	}
+}
+
 /*
  *	Add a new route to a node, and in the process add the node and the
  *	neighbour if it is new.
@@ -90,7 +103,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 +263,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;
 	}
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-hams" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html