Skip to contentSkip to conversation

USB: serial: io_edgeport: mark expected switch fall-throughs

PATCH In review Gustavo A. R. Silva 4 participants 7 messages Oct 27, 2017 – Oct 31, 2017

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

PATCH 1/1 USB: serial: io_edgeport: mark expected switch fall-throughs

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

Notice that in this particular case I replaced "...drop on through" comments with a proper "fall through" comment on its own line, which is what GCC is expecting to find.

---
 drivers/usb/serial/io_edgeport.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/serial/io_edgeport.c +2 -2
index bdf8bd8..8d96e12 100644
@@ -1759,7 +1759,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial,
 				edge_serial->rxState = EXPECT_HDR2;
 				break;
 			}
-			/* otherwise, drop on through */
+			/* fall through */
 		case EXPECT_HDR2:
 			edge_serial->rxHeader2 = *buffer;
 			++buffer;
@@ -1819,8 +1819,8 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial,
 					edge_serial->rxState = EXPECT_DATA;
 					break;
 				}
-				/* Else, drop through */
 			}
+			/* fall through */
 		case EXPECT_DATA: /* Expect data */
 			if (bufferLength < edge_serial->rxBytesRemaining) {
 				rxLen = bufferLength;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · Gustavo A. R. Silva

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

Notice that in this particular case I replaced "...drop on through" comments with a proper "fall through" comment on its own line, which is what GCC is expecting to find.

Sounds to me like GCC is the wrong tool for this. But I would of course not mind if it was *just* the text. However, as your patch cleary shows, the simplified logic leads to real problems:

drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1826

Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1 -1
@@ -1819,8 +1819,8 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial,
 					edge_serial->rxState = EXPECT_DATA;
 					break;
 				}
-				/* Else, drop through */
 			}
+			/* fall through */
 		case EXPECT_DATA: /* Expect data */
 			if (bufferLength < edge_serial->rxBytesRemaining) {
 				rxLen = bufferLength;

The original comment clearly marked a *conditional* fall through at the correct place. Your patch makes it appear as if there is an unconditional fall through here. There is not. The fallthrough only applies to one of a number of nested if blocks. There are no less than 3 break statements in the same case block.

Not a big deal maybe, just as the lack of any "fall through" comment isn't a big deal in the first place. But this change is clearly making this code harder to read, and the change is therefore harmful IMHO.

If you can't make -Wimplicit-fallthrough work without removing such precise fallthrough markings, then my proposal is to drop it and use some other tool.

Bjørn

#2 lore raw

Quoting Bjørn Mork <[email protected]>:

Quoted 23 lines
Quoted 6 lines · Gustavo A. R. Silva

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

Notice that in this particular case I replaced "...drop on through" comments with a proper "fall through" comment on its own line, which is what GCC is expecting to find.

Sounds to me like GCC is the wrong tool for this. But I would of course not mind if it was *just* the text. However, as your patch cleary shows, the simplified logic leads to real problems:

Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1 -1
@@ -1819,8 +1819,8 @@ static void process_rcvd_data(struct  
 edgeport_serial *edge_serial,
 					edge_serial->rxState = EXPECT_DATA;
 					break;
 				}
-				/* Else, drop through */
 			}
+			/* fall through */
 		case EXPECT_DATA: /* Expect data */
 			if (bufferLength < edge_serial->rxBytesRemaining) {
Quoted 9 lines
Quoted 1 line

rxLen = bufferLength;

The original comment clearly marked a *conditional* fall through at the correct place. Your patch makes it appear as if there is an unconditional fall through here. There is not. The fallthrough only applies to one of a number of nested if blocks. There are no less than 3 break statements in the same case block.

I see.
You are right.

Quoted 8 lines

Not a big deal maybe, just as the lack of any "fall through" comment isn't a big deal in the first place. But this change is clearly making this code harder to read, and the change is therefore harmful IMHO.

If you can't make -Wimplicit-fallthrough work without removing such precise fallthrough markings, then my proposal is to drop it and use some other tool.

I will talk with the hardening guys to see what we can do about this.

I appreciate for your comments.
Thanks
--
Gustavo A. R. Silva

#3 lore raw
In reply to Bjørn Mork

From: Bjørn Mork

Quoted 30 lines

Sent: 28 October 2017 11:57

Quoted 6 lines

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

Notice that in this particular case I replaced "...drop on through" comments with a proper "fall through" comment on its own line, which is what GCC is expecting to find.

Sounds to me like GCC is the wrong tool for this. But I would of course not mind if it was *just* the text. However, as your patch cleary shows, the simplified logic leads to real problems:

drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1826

Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1 -1
@@ -1819,8 +1819,8 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial,
 					edge_serial->rxState = EXPECT_DATA;
 					break;
 				}
-				/* Else, drop through */
 			}
+			/* fall through */
 		case EXPECT_DATA: /* Expect data */
 			if (bufferLength < edge_serial->rxBytesRemaining) {
 				rxLen = bufferLength;

The original comment clearly marked a *conditional* fall through at the correct place. Your patch makes it appear as if there is an unconditional fall through here. There is not. The fallthrough only applies to one of a number of nested if blocks. There are no less than 3 break statements in the same case block.

Quoted 7 lines

Not a big deal maybe, just as the lack of any "fall through" comment isn't a big deal in the first place. But this change is clearly making this code harder to read, and the change is therefore harmful IMHO.

If you can't make -Wimplicit-fallthrough work without removing such precise fallthrough markings, then my proposal is to drop it and use some other tool.

Just remove the 'else' after the 'break' further up.

David

maintainer
#4 lore raw
Quoted 35 lines · David Laight

From: Bjørn Mork

Quoted 34 lines

Sent: 28 October 2017 11:57

Quoted 6 lines

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

Notice that in this particular case I replaced "...drop on through" comments with a proper "fall through" comment on its own line, which is what GCC is expecting to find.

Sounds to me like GCC is the wrong tool for this. But I would of course not mind if it was *just* the text. However, as your patch cleary shows, the simplified logic leads to real problems:

drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1826

Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1 -1
@@ -1819,8 +1819,8 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial,
 					edge_serial->rxState = EXPECT_DATA;
 					break;
 				}
-				/* Else, drop through */
 			}
+			/* fall through */
 		case EXPECT_DATA: /* Expect data */
 			if (bufferLength < edge_serial->rxBytesRemaining) {
 				rxLen = bufferLength;

The original comment clearly marked a *conditional* fall through at the correct place. Your patch makes it appear as if there is an unconditional fall through here. There is not. The fallthrough only applies to one of a number of nested if blocks. There are no less than 3 break statements in the same case block.

Not a big deal maybe, just as the lack of any "fall through" comment isn't a big deal in the first place. But this change is clearly making this code harder to read, and the change is therefore harmful IMHO.

Quoted 5 lines
Quoted 3 lines

If you can't make -Wimplicit-fallthrough work without removing such precise fallthrough markings, then my proposal is to drop it and use some other tool.

Just remove the 'else' after the 'break' further up.

Yeah, that might be a good way to resolve this. I was gonna suggest adding the "fall though" comment before the case while keeping the "Else, drop through" comment in the branch, but removing the else might be better.

This code is pretty hard to read as is and could really use some clean up...

Thanks,
Johan

#5 lore raw

Hi David, Johan,

Quoting Johan Hovold <[email protected]>:

Quoted 41 lines · David Laight
Quoted 40 lines

From: Bjørn Mork

Quoted 8 lines

Sent: 28 October 2017 11:57

Quoted 6 lines

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

Notice that in this particular case I replaced "...drop on through" comments with a proper "fall through" comment on its own line, which is what GCC is expecting to find.

Quoted 5 lines

Sounds to me like GCC is the wrong tool for this. But I would of course not mind if it was *just* the text. However, as your patch cleary shows, the simplified logic leads to real problems:

Review static void process_rcvd_data(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -1819,8 +1819,8 @@ static void process_rcvd_data(struct  

edgeport_serial *edge_serial,

Quoted 24 lines

drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1826

Quoted 9 lines
drivers/usb/serial/io_edgeport.c +1 -1
 					edge_serial->rxState = EXPECT_DATA;
 					break;
 				}
-				/* Else, drop through */
 			}
+			/* fall through */
 		case EXPECT_DATA: /* Expect data */
 			if (bufferLength < edge_serial->rxBytesRemaining) {
 				rxLen = bufferLength;

The original comment clearly marked a *conditional* fall through at the correct place. Your patch makes it appear as if there is an unconditional fall through here. There is not. The fallthrough only applies to one of a number of nested if blocks. There are no less than 3 break statements in the same case block.

Not a big deal maybe, just as the lack of any "fall through" comment isn't a big deal in the first place. But this change is clearly making this code harder to read, and the change is therefore harmful IMHO.

If you can't make -Wimplicit-fallthrough work without removing such precise fallthrough markings, then my proposal is to drop it and use some other tool.

Quoted 7 lines
Quoted 1 line

Just remove the 'else' after the 'break' further up.

Yeah, that might be a good way to resolve this. I was gonna suggest adding the "fall though" comment before the case while keeping the "Else, drop through" comment in the branch, but removing the else might be better.

Thanks for the suggestion.

Quoted 3 lines

This code is pretty hard to read as is and could really use some clean up...

I agree. I'll send a V2 of this patch and then let's see if I can help with some code refactoring.

Thank you
--
Gustavo A. R. Silva

maintainer
#6 lore raw
Quoted 8 lines · Gustavo A. R. Silva

Quoting Johan Hovold <[email protected]>:

Quoted 3 lines

This code is pretty hard to read as is and could really use some clean up...

I agree. I'll send a V2 of this patch and then let's see if I can help with some code refactoring.

Sounds good!

Thanks,
Johan