USB: serial: io_edgeport: mark expected switch fall-throughs
Subsystems (2)
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.
--- drivers/usb/serial/io_edgeport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/serial/io_edgeport.c +2 -2
@@ -1760,7 +1760,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, edge_serial->rxState =EXPECT_HDR2 ;break ; } -/* otherwise, drop on through */ +/* else: fall through */ case EXPECT_HDR2 : edge_serial->rxHeader2 = *buffer; ++buffer;
@@ -1820,7 +1820,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, edge_serial->rxState =EXPECT_DATA ;break ; } -/* Else, drop through */ +/* else: fall through */ }case EXPECT_DATA :/* Expect data */ if (bufferLength < edge_serial->rxBytesRemaining) {
Johan Hovold
maintainerQuoted 13 lines · 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 <[email protected]>--- drivers/usb/serial/io_edgeport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/usb/serial/io_edgeport.c +0
-0
drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1763
Quoted 5 lines
drivers/usb/serial/io_edgeport.c +1
-1@@ -1760,7 +1760,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, edge_serial->rxState =EXPECT_HDR2 ;break ; } -/* otherwise, drop on through */ +/* else: fall through */
This doesn't silence the compiler warning with gcc 7.2.0 as the "else: " pattern isn't recognised.
drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1824
Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1
-1case EXPECT_HDR2 : edge_serial->rxHeader2 = *buffer; ++buffer;@@ -1820,7 +1820,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, edge_serial->rxState =EXPECT_DATA ;break ; } -/* Else, drop through */ +/* else: fall through */ }
And this doesn't work either due to the "else: " as well as the fact that the compiler expects the fallthrough comment to precede the case statement directly (e.g. it would need to be moved out of the else block, but that isn't necessarily desirable as we discussed last year:
lkml.kernel.org/r/[email protected]
)
drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1826
Quoted 2 lines
drivers/usb/serial/io_edgeport.c +0
-0case EXPECT_DATA :/* Expect data */ if (bufferLength < edge_serial->rxBytesRemaining) {
How do you compile test these these patches?
Thanks,
Johan
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Johan,
Quoted 9 lines · Johan Hovold
Quoted 8 lines · 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 <[email protected]>--- drivers/usb/serial/io_edgeport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 14 lines
drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1763
Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1
-1@@ -1760,7 +1760,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, edge_serial->rxState =EXPECT_HDR2 ;break ; } -/* otherwise, drop on through */ +/* else: fall through */ This doesn't silence the compiler warning with gcc 7.2.0 as the "else: " pattern isn't recognised.
I'm using level 2:
-Wimplicit-fallthrough=2
The thing here is that some people have pointed out that it can be misleading to place a plain fall-through comment after an if-else code block containing a "break". So, the solution above has proved to be a good one.
Quoted 16 lines
drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1824
Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1
-1case EXPECT_HDR2 : edge_serial->rxHeader2 = *buffer; ++buffer;@@ -1820,7 +1820,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, edge_serial->rxState =EXPECT_DATA ;break ; } -/* Else, drop through */ +/* else: fall through */ }And this doesn't work either due to the "else: " as well as the fact that the compiler expects the fallthrough comment to precede the case statement directly (e.g. it would need to be moved out of the else block, but that isn't necessarily desirable as we discussed last year:
Quoted 2 lines
lkml.kernel.org/r/[email protected]
Yes. I'm aware of that. This certainly is still triggering a warning, so I just consider this as a temporal approach. I still need to define how are we going to manage cases like this.
Quoted 7 lines
)
drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1826
Quoted 2 lines
drivers/usb/serial/io_edgeport.c +0
-0case EXPECT_DATA :/* Expect data */ if (bufferLength < edge_serial->rxBytesRemaining) {How do you compile test these these patches?
I already explained this above.
Thanks for your comments.
---
Gustavo
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Johan Hovold
maintainerQuoted 27 lines · Gustavo A. R. Silva
Hi Johan,
Quoted 9 lines · Johan Hovold
Quoted 8 lines · 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 <[email protected]>--- drivers/usb/serial/io_edgeport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)Quoted 14 lines
drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1763
Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1
-1@@ -1760,7 +1760,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, edge_serial->rxState =EXPECT_HDR2 ;break ; } -/* otherwise, drop on through */ +/* else: fall through */ This doesn't silence the compiler warning with gcc 7.2.0 as the "else: " pattern isn't recognised.
Quoted 7 lines
I'm using level 2:
-Wimplicit-fallthrough=2
The thing here is that some people have pointed out that it can be misleading to place a plain fall-through comment after an if-else code block containing a "break". So, the solution above has proved to be a good one.
I don't mind the "else", but I would expect you to mention in the commit message that you're now relying on the non-default warning level (2).
Quoted 16 lines
Quoted 16 lines
drivers/usb/serial/io_edgeport.c static void process_rcvd_data(struct edgeport_serial *edge_serial, · line 1824
Quoted 10 lines
drivers/usb/serial/io_edgeport.c +1
-1case EXPECT_HDR2 : edge_serial->rxHeader2 = *buffer; ++buffer;@@ -1820,7 +1820,7 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial, edge_serial->rxState =EXPECT_DATA ;break ; } -/* Else, drop through */ +/* else: fall through */ }And this doesn't work either due to the "else: " as well as the fact that the compiler expects the fallthrough comment to precede the case statement directly (e.g. it would need to be moved out of the else block, but that isn't necessarily desirable as we discussed last year:
Quoted 7 lines
Quoted 2 lines
lkml.kernel.org/r/[email protected]Yes. I'm aware of that. This certainly is still triggering a warning, so I just consider this
as a temporal approach. I still need to define how are we going to manage cases like this.
Ok, so why did you not mention that in the commit message?
If this isn't even addressing the warning you get with the non-default -Wimplicit-fallthrough=2, I don't see this as much of an improvement.
Might as well leave this unchanged, until all warnings in that switch statement are addressed.
Johan
---
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html