Skip to contentSkip to conversation

drbd_receiver: mark expected switch fall-throughs

PATCH In review Gustavo A. R. Silva 2 participants 3 messages Feb 12, 2019 – Feb 15, 2019

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

PATCH 1/1 drbd_receiver: mark expected switch fall-throughs

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

This patch fixes the following warnings:

drivers/block/drbd/drbd_receiver.c: In function ‘drbd_asb_recover_0p’:
drivers/block/drbd/drbd_receiver.c:3093:6: warning: this statement may fall through [-Wimplicit-fallthrough=]

   if (self == 1 && peer == 0) {
      ^

drivers/block/drbd/drbd_receiver.c:3098:2: note: here
case ASB_DISCARD_OLDER_PRI:
^~~~
drivers/block/drbd/drbd_receiver.c:3120:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
if (after_sb_0p == ASB_DISCARD_ZERO_CHG)

      ^

drivers/block/drbd/drbd_receiver.c:3123:2: note: here
case ASB_DISCARD_LEAST_CHG:
^~~~

Warning level 3 was used: -Wimplicit-fallthrough=3

Notice that in some cases, the code comment is modified in accordance with what GCC is expecting to find.

This patch is part of the ongoing efforts to enable -Wimplicit-fallthrough.

---
 drivers/block/drbd/drbd_receiver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_receiver.c +2 -2
index c7ad88d91a09..78bb763a367d 100644
@@ -3094,7 +3094,7 @@ static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold
 			rv =  1;
 			break;
 		}
-		/* Else fall through to one of the other strategies... */
+		/* Else fall through - to one of the other strategies... */
 	case ASB_DISCARD_OLDER_PRI:
 		if (self == 0 && peer == 1) {
 			rv = 1;
@@ -3119,7 +3119,7 @@ static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold
 		}
 		if (after_sb_0p == ASB_DISCARD_ZERO_CHG)
 			break;
-		/* else: fall through */
+		/* Else fall through */
 	case ASB_DISCARD_LEAST_CHG:
 		if	(ch_self < ch_peer)
 			rv = -1;
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 46 lines · Gustavo A. R. Silva

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

This patch fixes the following warnings:

drivers/block/drbd/drbd_receiver.c: In function ‘drbd_asb_recover_0p’:
drivers/block/drbd/drbd_receiver.c:3093:6: warning: this statement may fall through [-Wimplicit-fallthrough=]

   if (self == 1 && peer == 0) {
      ^

drivers/block/drbd/drbd_receiver.c:3098:2: note: here
case ASB_DISCARD_OLDER_PRI:
^~~~
drivers/block/drbd/drbd_receiver.c:3120:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
if (after_sb_0p == ASB_DISCARD_ZERO_CHG)

      ^

drivers/block/drbd/drbd_receiver.c:3123:2: note: here
case ASB_DISCARD_LEAST_CHG:
^~~~

Warning level 3 was used: -Wimplicit-fallthrough=3

Notice that in some cases, the code comment is modified in accordance with what GCC is expecting to find.

This patch is part of the ongoing efforts to enable -Wimplicit-fallthrough.

---
 drivers/block/drbd/drbd_receiver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_receiver.c +1 -1
index c7ad88d91a09..78bb763a367d 100644
@@ -3094,7 +3094,7 @@ static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold
 			rv =  1;
 			break;
 		}
-		/* Else fall through to one of the other strategies... */
+		/* Else fall through - to one of the other strategies... */
 	case ASB_DISCARD_OLDER_PRI:
 		if (self == 0 && peer == 1) {
 			rv = 1;

drivers/block/drbd/drbd_receiver.c static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold · line 3122

Quoted 5 lines
drivers/block/drbd/drbd_receiver.c +1 -1
@@ -3119,7 +3119,7 @@ static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold
 		}
 		if (after_sb_0p == ASB_DISCARD_ZERO_CHG)
 			break;
-		/* else: fall through */
+		/* Else fall through */

This is getting really silly, as these two hunks both aptly demonstrate. Can we please inject some sanity into this fall through witch hunt?

The last hunk is updating ANOTHER patch that also attempted to silence this stuff.

Signature · 1 line
Jens Axboe
#2 lore raw
Quoted 47 lines · Jens Axboe
Quoted 46 lines · Gustavo A. R. Silva

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

This patch fixes the following warnings:

drivers/block/drbd/drbd_receiver.c: In function ‘drbd_asb_recover_0p’:
drivers/block/drbd/drbd_receiver.c:3093:6: warning: this statement may fall through [-Wimplicit-fallthrough=]

   if (self == 1 && peer == 0) {
      ^

drivers/block/drbd/drbd_receiver.c:3098:2: note: here
case ASB_DISCARD_OLDER_PRI:
^~~~
drivers/block/drbd/drbd_receiver.c:3120:6: warning: this statement may fall through [-Wimplicit-fallthrough=]
if (after_sb_0p == ASB_DISCARD_ZERO_CHG)

      ^

drivers/block/drbd/drbd_receiver.c:3123:2: note: here
case ASB_DISCARD_LEAST_CHG:
^~~~

Warning level 3 was used: -Wimplicit-fallthrough=3

Notice that in some cases, the code comment is modified in accordance with what GCC is expecting to find.

This patch is part of the ongoing efforts to enable -Wimplicit-fallthrough.

---
 drivers/block/drbd/drbd_receiver.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/drbd/drbd_receiver.c +1 -1
index c7ad88d91a09..78bb763a367d 100644
@@ -3094,7 +3094,7 @@ static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold
 			rv =  1;
 			break;
 		}
-		/* Else fall through to one of the other strategies... */
+		/* Else fall through - to one of the other strategies... */
 	case ASB_DISCARD_OLDER_PRI:
 		if (self == 0 && peer == 1) {
 			rv = 1;
@@ -3119,7 +3119,7 @@ static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold
Quoted 9 lines

drivers/block/drbd/drbd_receiver.c static int drbd_asb_recover_0p(struct drbd_peer_device *peer_device) __must_hold · line 3122

Quoted 5 lines
drivers/block/drbd/drbd_receiver.c +1 -1
 		}
 		if (after_sb_0p == ASB_DISCARD_ZERO_CHG)
 			break;
-		/* else: fall through */
+		/* Else fall through */

This is getting really silly, as these two hunks both aptly demonstrate. Can we please inject some sanity into this fall through witch hunt?

No witch hunt here. This work has proved to be very valuable. I've fixed years-old bugs thanks to this effort.

Quoted 3 lines

The last hunk is updating ANOTHER patch that also attempted to silence this stuff.

Yeah. Sorry about that.

Previously, I was using level 2: -Wimplicit-fallthrough=2, but this time I'm using level 3: -Wimplicit-fallthrough=3, which is stricter and maps to -Wextra.

Thanks
--
Gustavo