Skip to contentSkip to conversation

nfs: remove incorrect fallthrough label

PATCH Superseded Nick Desaulniers 7 participants 18 messages Sep 15, 2020 – Sep 25, 2020

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

PATCH 1/1 nfs: remove incorrect fallthrough label

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just removed the comment.

Fixes 2a1390c95a69 ("nfs: Convert to use the preferred fallthrough macro")
---
 fs/nfs/super.c | 1 -
 1 file changed, 1 deletion(-)
fs/nfs/super.c +0 -1
index d20326ee0475..7de4e0b03be0 100644
@@ -889,7 +889,6 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;
 		}
 		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
 		ctx->selected_flavor = flavor;
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
#1 lore raw
Quoted 5 lines · Nick Desaulniers

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just removed the comment.

[]

fs/nfs/super.c

Quoted 1 line
fs/nfs/super.c +0 -0

[]

fs/nfs/super.c static struct nfs_server *nfs_try_mount_request(struct fs_context *fc) · line 892

Quoted 5 lines
fs/nfs/super.c +0 -1
@@ -889,7 +889,6 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;

My preference would be to convert the fallthrough to a break here so if someone ever adds another label after default: for any reason, the code would still work as expected.

Quoted 2 lines
fs/nfs/super.c +0 -0
 		}
 
#2 lore raw
Quoted 9 lines · Joe Perches
Quoted 5 lines · Nick Desaulniers

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just removed the comment.

[]

fs/nfs/super.c

Quoted 1 line
fs/nfs/super.c +0 -0

[]

Quoted 10 lines

fs/nfs/super.c static struct nfs_server *nfs_try_mount_request(struct fs_context *fc) · line 892

Quoted 5 lines
fs/nfs/super.c +0 -1
@@ -889,7 +889,6 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;

My preference would be to convert the fallthrough to a break here so if someone ever adds another label after default: for any reason, the code would still work as expected.

I agree with Joe.

Thanks
--
Gustavo

#3 lore raw
Quoted 23 lines · Gustavo A. R. Silva
Quoted 9 lines · Joe Perches
Quoted 5 lines · Nick Desaulniers

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just removed the comment.

[]

fs/nfs/super.c

Quoted 1 line
fs/nfs/super.c +0 -0

[]

Quoted 10 lines

fs/nfs/super.c static struct nfs_server *nfs_try_mount_request(struct fs_context *fc) · line 892

Quoted 5 lines
fs/nfs/super.c +0 -1
@@ -889,7 +889,6 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;

My preference would be to convert the fallthrough to a break here so if someone ever adds another label after default: for any reason, the code would still work as expected.

Quoted 1 line

I agree with Joe.

Actually, this is part of the work I plan to do to enable -Wimplicit-fallthrough for Clang: audit every place where we could use a break instead of a fallthrough.

I'm on vacation this week. So, I'll get back to this next week.

Thanks
--
Gustavo

#4 lore raw
Quoted 24 lines · Gustavo A. R. Silva
Quoted 22 lines · Gustavo A. R. Silva
Quoted 19 lines · Joe Perches
Quoted 5 lines · Nick Desaulniers

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just removed the comment.

[]

fs/nfs/super.c

Quoted 1 line
fs/nfs/super.c +0 -0

[]

fs/nfs/super.c static struct nfs_server *nfs_try_mount_request(struct fs_context *fc) · line 892

Quoted 5 lines
fs/nfs/super.c +0 -1
@@ -889,7 +889,6 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;

My preference would be to convert the fallthrough to a break here so if someone ever adds another label after default: for any reason, the code would still work as expected.

Quoted 6 lines
Quoted 1 line

I agree with Joe.

Actually, this is part of the work I plan to do to enable -Wimplicit-fallthrough for Clang: audit every place where we could use a break instead of a fallthrough.

I'm on vacation this week. So, I'll get back to this next week.

Nice, thanks Gustavo.

As part of that work, perhaps you could also find all the

	switch (<foo>) {
	[cases...]
		[code...];
		break;

	default:
		[code...]
		(no break)
	}

uawa where the last label/default block does _not_ have a break statement and add one too.

Also see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91432

gcc does _not_ warn on

	switch (<foo>) {
	case BAR:
		[code];
		(no fallthrough)

	case BAZ:
		break;
	}

It might be good to add the appropriate fallthrough for those case blocks too.

#5 lore raw

PATCH v2 1/1 nfs: remove incorrect fallthrough label

In reply to Joe Perches

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just replaced the comment with a break statement.

If we consider implicit fallthrough to be a design mistake of C, then all case statements should be terminated with one of the following statements:
* break
* continue
* return
* __attribute__(__fallthrough__)
* goto (plz no)
* (call of function with __attribute__(__noreturn__))

Fixes 2a1390c95a69 ("nfs: Convert to use the preferred fallthrough macro")

---
Changes v2:
* add break rather than no terminating statement as per Joe.
* add Joe's suggested by tag.
* add blurb about acceptable terminal statements.

 fs/nfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/super.c +1 -1
index d20326ee0475..eb2401079b04 100644
@@ -889,7 +889,7 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;
+			break;
 		}
 		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
 		ctx->selected_flavor = flavor;
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
Acked-by Reviewed-by on v2 1/1
#6 lore raw
Quoted 17 lines · Nick Desaulniers

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just replaced the comment with a break statement.

If we consider implicit fallthrough to be a design mistake of C, then all case statements should be terminated with one of the following statements:
* break
* continue
* return
* __attribute__(__fallthrough__)
* goto (plz no)
* (call of function with __attribute__(__noreturn__))

Quoted 4 lines
Fixes 2a1390c95a69 ("nfs: Convert to use the preferred fallthrough macro")

Thanks
--
Gustavo

Quoted 25 lines

---
Changes v2:
* add break rather than no terminating statement as per Joe.
* add Joe's suggested by tag.
* add blurb about acceptable terminal statements.

 fs/nfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/super.c +1 -1
index d20326ee0475..eb2401079b04 100644
@@ -889,7 +889,7 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;
+			break;
 		}
 		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
 		ctx->selected_flavor = flavor;
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
#7 lore raw
In reply to Nick Desaulniers
Quoted 7 lines · Nick Desaulniers

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just replaced the comment with a break statement.

Quoted 8 lines

If we consider implicit fallthrough to be a design mistake of C, then all case statements should be terminated with one of the following statements:

* break
* continue
* return
* __attribute__(__fallthrough__)

Just fallthrough. __attribute__((__fallthrough__) is only used once in code for the #define.

And maybe add see: Documentation/process/deprecated.rst

Quoted 1 line

* goto (plz no)

goto is a valid style inside a switch/case label block.

There are more than 1500 of these goto <label> uses in the kernel so the 'please no' here doesn't seem reasonable.

Quoted 1 line

* (call of function with __attribute__(__noreturn__))

I guess panic counts. I count 11 of those.

Are there any other uses of functions with __noreturn in switch/case label blocks?

#8 lore raw
Quoted 8 lines · Joe Perches
Quoted 1 line · Nick Desaulniers

* (call of function with __attribute__(__noreturn__))

I guess panic counts. I count 11 of those.

Are there any other uses of functions with __noreturn in switch/case label blocks?

If you look at global_noreturns in tools/objtool/check.c:
145 static const char * const global_noreturns[] = {

 146     "__stack_chk_fail",
 147     "panic",
 148     "do_exit",
 149     "do_task_dead",
 150     "__module_put_and_exit",
 151     "complete_and_exit",
 152     "__reiserfs_panic",
 153     "lbug_with_loc",
 154     "fortify_panic",
 155     "usercopy_abort",
 156     "machine_real_restart",
 157     "rewind_stack_do_exit",
 158     "kunit_try_catch_throw",

159 };

Whether they occur or not at the position you ask; I haven't checked.

Signature · 2 lines
Thanks,
~Nick Desaulniers
#9 lore raw
Quoted 24 lines · Nick Desaulniers
Quoted 7 lines · Joe Perches
Quoted 1 line · Nick Desaulniers

* (call of function with __attribute__(__noreturn__))

I guess panic counts. I count 11 of those.

Are there any other uses of functions with __noreturn in switch/case label blocks?

If you look at global_noreturns in tools/objtool/check.c:
145 static const char * const global_noreturns[] = {

 146     "__stack_chk_fail",
 147     "panic",
 148     "do_exit",
 149     "do_task_dead",
 150     "__module_put_and_exit",
 151     "complete_and_exit",
 152     "__reiserfs_panic",
 153     "lbug_with_loc",
 154     "fortify_panic",
 155     "usercopy_abort",
 156     "machine_real_restart",
 157     "rewind_stack_do_exit",
 158     "kunit_try_catch_throw",
Quoted 3 lines

159 };

Whether they occur or not at the position you ask; I haven't checked.

Just fyi:

Other than the 11 instances of panic, I found only a single use of any other function above in a switch/case:

drivers/pnp/pnpbios/core.c:163: complete_and_exit(&unload_sem, 0);
case PNP_SYSTEM_NOT_DOCKED:

Found with:

$ grep-2.5.4 -rP --include=*.[ch] -n '\b(?:__stack_chk_fail|panic|do_exit|do_task_dead|__module_put_and_exit|complete_and_exit|__reiserfs_panic|lbug_with_loc|fortify_panic|usercopy_abort|machine_real_restart|rewind_stack_do_exit|kunit_try_catch_throw)\s*(?:\([^\)]*\))?\s*;\s*(case\s+\w+|default)\s*:' *
#10 lore raw

PATCH v3 1/1 nfs: remove incorrect fallthrough label

In reply to Joe Perches

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just replaced the comment with a break statement.

If we consider implicit fallthrough to be a design mistake of C, then all case statements should be terminated with one of the following statements:
* break
* continue
* return
* fallthrough
* goto
* (call of function with __attribute__(__noreturn__))

---
Changes v3:
* update the commit message as per Joe.
* collect tags.

Changes v2:
* add break rather than no terminating statement as per Joe.
* add Joe's suggested by tag.
* add blurb about acceptable terminal statements.

 fs/nfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/super.c +1 -1
index d20326ee0475..eb2401079b04 100644
@@ -889,7 +889,7 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;
+			break;
 		}
 		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
 		ctx->selected_flavor = flavor;
Signature · 1 line
2.28.0.681.g6f77f65b4e-goog
#11 lore raw

Hello maintainers,
Would you mind please picking up this patch? KernelCI has been erroring for over a week without it.

Quoted 55 lines · Nick Desaulniers

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just replaced the comment with a break statement.

If we consider implicit fallthrough to be a design mistake of C, then all case statements should be terminated with one of the following statements:
* break
* continue
* return
* fallthrough
* goto
* (call of function with __attribute__(__noreturn__))

---
Changes v3:
* update the commit message as per Joe.
* collect tags.

Changes v2:
* add break rather than no terminating statement as per Joe.
* add Joe's suggested by tag.
* add blurb about acceptable terminal statements.

 fs/nfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/super.c +1 -2
index d20326ee0475..eb2401079b04 100644
@@ -889,7 +889,7 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
                default:
                        if (rpcauth_get_gssinfo(flavor, &info) != 0)
                                continue;
-                       fallthrough;
+                       break;
                }
                dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
                ctx->selected_flavor = flavor;
--

2.28.0.681.g6f77f65b4e-goog

Signature · 2 lines
Thanks,
~Nick Desaulniers
Acked-by Gustavo A. R. Silva Reviewed-by Gustavo A. R. Silva Reviewed-by Miaohe Lin Reviewed-by Nathan Chancellor
#12 lore raw
Quoted 3 lines · Nick Desaulniers

Hello maintainers,
Would you mind please picking up this patch? KernelCI has been erroring for over a week without it.

As it's trivial and necessary, why not go through Linus directly?

https://lore.kernel.org/patchwork/patch/1307549/

From: Nick Desaulniers <[email protected]>

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just replaced the comment with a break statement.

If we consider implicit fallthrough to be a design mistake of C, then all case statements should be terminated with one of the following statements:
* break
* continue
* return
* fallthrough
* goto
* (call of function with __attribute__(__noreturn__))

---
Changes v3:
* update the commit message as per Joe.
* collect tags.

Changes v2:
* add break rather than no terminating statement as per Joe.
* add Joe's suggested by tag.
* add blurb about acceptable terminal statements.

 fs/nfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/super.c +1 -1
index d20326ee0475..eb2401079b04 100644
@@ -889,7 +889,7 @@  static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;
+			break;
 		}
 		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
 		ctx->selected_flavor = flavor;
#13 lore raw
Quoted 6 lines · Joe Perches
Quoted 3 lines · Nick Desaulniers

Hello maintainers,
Would you mind please picking up this patch? KernelCI has been erroring for over a week without it.

As it's trivial and necessary, why not go through Linus directly?

[]

Quoted 1 line
Fixes 2a1390c95a69 ("nfs: Convert to use the preferred fallthrough macro")

Real reason why not:

the commit to be fixed is not in Linus' tree.

Quoted 1 line

https://lore.kernel.org/patchwork/patch/1307549/

#14 lore raw
Quoted 7 lines · Joe Perches
Quoted 5 lines · Joe Perches
Quoted 3 lines · Nick Desaulniers

Hello maintainers,
Would you mind please picking up this patch? KernelCI has been erroring for over a week without it.

Quoted 6 lines
Quoted 1 line

As it's trivial and necessary, why not go through Linus directly?

[]

Quoted 1 line
Fixes 2a1390c95a69 ("nfs: Convert to use the preferred fallthrough macro")

Real reason why not:

I'm planning to take this patch through the NFS tree for 5.10 (along with the patch that apparently causes the problem). I didn't think it was urgent so I haven't gotten around to pushing it out yet, but I'll do so in the next few hours.

Anna

Quoted 5 lines

the commit to be fixed is not in Linus' tree.

Quoted 1 line

https://lore.kernel.org/patchwork/patch/1307549/

#15 lore raw
Quoted 8 lines · Anna Schumaker
Quoted 1 line · Joe Perches

Real reason why not:

I'm planning to take this patch through the NFS tree for 5.10 (along with the patch that apparently causes the problem). I didn't think it was urgent so I haven't gotten around to pushing it out yet, but I'll do so in the next few hours.

FWIW NFS is quite widely used by CI systems so any build breaks with it in -next have a pretty big knock on effect on testing, even beyond the distruption people working on the build test side of things.

#16 lore raw
In reply to Nick Desaulniers
Quoted 4 lines · Nick Desaulniers

Hello maintainers,
Would you mind please picking up this patch? KernelCI has been erroring for over a week without it.

I can add this to my -next tree and queue it up for the next merge window.

Thanks
--
Gustavo

Reviewed-by on v2 1/1
#17 lore raw
In reply to Nick Desaulniers
Quoted 17 lines · Nick Desaulniers

There is no case after the default from which to fallthrough to. Clang will error in this case (unhelpfully without context, see link below) and GCC will with -Wswitch-unreachable.

The previous commit should have just replaced the comment with a break statement.

If we consider implicit fallthrough to be a design mistake of C, then all case statements should be terminated with one of the following statements:
* break
* continue
* return
* __attribute__(__fallthrough__)
* goto (plz no)
* (call of function with __attribute__(__noreturn__))

Quoted 4 lines
Fixes 2a1390c95a69 ("nfs: Convert to use the preferred fallthrough macro")
Quoted 25 lines

---
Changes v2:
* add break rather than no terminating statement as per Joe.
* add Joe's suggested by tag.
* add blurb about acceptable terminal statements.

 fs/nfs/super.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/super.c +1 -1
index d20326ee0475..eb2401079b04 100644
@@ -889,7 +889,7 @@ static struct nfs_server *nfs_try_mount_request(struct fs_context *fc)
 		default:
 			if (rpcauth_get_gssinfo(flavor, &info) != 0)
 				continue;
-			fallthrough;
+			break;
 		}
 		dfprintk(MOUNT, "NFS: attempting to use auth flavor %u\n", flavor);
 		ctx->selected_flavor = flavor;
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog