nfs: remove incorrect fallthrough label
Subsystems (2)
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.
--- fs/nfs/super.c | 1 - 1 file changed, 1 deletion(-)
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; }dfprintk (MOUNT ,"NFS: attempting to use auth flavor %u\n" , flavor); ctx->selected_flavor = flavor;
Signature · 1 line
2.28.0.618.gf4bc123cb7-goog
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}
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
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
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.
PATCH v2 1/1 nfs: remove incorrect fallthrough label
In reply to Joe PerchesThere 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__))
---
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
@@ -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
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")Suggested-by Joe Perches <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>
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@@ -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
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?
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
__noreturnin 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
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
__noreturnin switch/case label blocks?If you look at
global_noreturnsintools/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*:' *
PATCH v3 1/1 nfs: remove incorrect fallthrough label
In reply to Joe PerchesThere 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
@@ -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
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__))Fixes 2a1390c95a69 ("nfs: Convert to use the preferred fallthrough macro")Reviewed-by Gustavo A. R. Silva <[email protected]>Reviewed-by Miaohe Lin <[email protected]>Reviewed-by Nathan Chancellor <[email protected]>Suggested-by Joe Perches <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>---
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@@ -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
Joe Perches
Acked-by Gustavo A. R. Silva Reviewed-by Gustavo A. R. Silva Reviewed-by Miaohe Lin Reviewed-by Nathan ChancellorQuoted 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
@@ -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;
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
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
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.
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
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")Suggested-by Joe Perches <[email protected]>Signed-off-by Nick Desaulniers <[email protected]>
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@@ -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