All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v2] nfs: remove incorrect fallthrough label
@ 2020-09-17  6:21 linmiaohe
  0 siblings, 0 replies; 7+ messages in thread
From: linmiaohe @ 2020-09-17  6:21 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Gustavo A . R . Silva, Joe Perches, Nathan Chancellor, linux-nfs,
	linux-kernel, clang-built-linux, Trond Myklebust, Anna Schumaker

Nick Desaulniers <ndesaulniers@google.com> wrote:
> 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")
>Link: https://bugs.llvm.org/show_bug.cgi?id=47539
>Suggested-by: Joe Perches <joe@perches.com>
>Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
>---

Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] nfs: remove incorrect fallthrough label
  2020-09-17 21:41     ` Nick Desaulniers
@ 2020-09-18  1:36       ` Joe Perches
  0 siblings, 0 replies; 7+ messages in thread
From: Joe Perches @ 2020-09-18  1:36 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Trond Myklebust, Anna Schumaker, Gustavo A . R . Silva,
	Nathan Chancellor, Hongxiang Lou, Miaohe Lin, linux-nfs, LKML,
	clang-built-linux

On Thu, 2020-09-17 at 14:41 -0700, Nick Desaulniers wrote:
> On Wed, Sep 16, 2020 at 1:19 PM Joe Perches <joe@perches.com> wrote:
> > On Wed, 2020-09-16 at 13:02 -0700, Nick Desaulniers wrote:
> > > * (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.

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*:' *



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] nfs: remove incorrect fallthrough label
  2020-09-16 20:19   ` Joe Perches
@ 2020-09-17 21:41     ` Nick Desaulniers
  2020-09-18  1:36       ` Joe Perches
  0 siblings, 1 reply; 7+ messages in thread
From: Nick Desaulniers @ 2020-09-17 21:41 UTC (permalink / raw)
  To: Joe Perches
  Cc: Trond Myklebust, Anna Schumaker, Gustavo A . R . Silva,
	Nathan Chancellor, Hongxiang Lou, Miaohe Lin, linux-nfs, LKML,
	clang-built-linux

On Wed, Sep 16, 2020 at 1:19 PM Joe Perches <joe@perches.com> wrote:
>
> On Wed, 2020-09-16 at 13:02 -0700, Nick Desaulniers wrote:
> > * (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.
-- 
Thanks,
~Nick Desaulniers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] nfs: remove incorrect fallthrough label
  2020-09-16 20:02 ` [PATCH v2] " Nick Desaulniers
  2020-09-16 20:18   ` Gustavo A. R. Silva
  2020-09-16 20:19   ` Joe Perches
@ 2020-09-17  4:35   ` Nathan Chancellor
  2 siblings, 0 replies; 7+ messages in thread
From: Nathan Chancellor @ 2020-09-17  4:35 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Trond Myklebust, Anna Schumaker, Gustavo A . R . Silva,
	Joe Perches, Hongxiang Lou, Miaohe Lin, linux-nfs, linux-kernel,
	clang-built-linux

On Wed, Sep 16, 2020 at 01:02:55PM -0700, Nick Desaulniers wrote:
> 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")
> Link: https://bugs.llvm.org/show_bug.cgi?id=47539
> Suggested-by: Joe Perches <joe@perches.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Reviewed-by: Nathan Chancellor <natechancellor@gmail.com>

> ---
> 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(-)
> 
> diff --git a/fs/nfs/super.c b/fs/nfs/super.c
> index d20326ee0475..eb2401079b04 100644
> --- a/fs/nfs/super.c
> +++ b/fs/nfs/super.c
> @@ -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.618.gf4bc123cb7-goog
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] nfs: remove incorrect fallthrough label
  2020-09-16 20:02 ` [PATCH v2] " Nick Desaulniers
  2020-09-16 20:18   ` Gustavo A. R. Silva
@ 2020-09-16 20:19   ` Joe Perches
  2020-09-17 21:41     ` Nick Desaulniers
  2020-09-17  4:35   ` Nathan Chancellor
  2 siblings, 1 reply; 7+ messages in thread
From: Joe Perches @ 2020-09-16 20:19 UTC (permalink / raw)
  To: Nick Desaulniers, Trond Myklebust, Anna Schumaker
  Cc: Gustavo A . R . Silva, Nathan Chancellor, Hongxiang Lou,
	Miaohe Lin, linux-nfs, linux-kernel, clang-built-linux

On Wed, 2020-09-16 at 13:02 -0700, Nick Desaulniers wrote:
> 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__)

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

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

> * 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.

> * (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?



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] nfs: remove incorrect fallthrough label
  2020-09-16 20:02 ` [PATCH v2] " Nick Desaulniers
@ 2020-09-16 20:18   ` Gustavo A. R. Silva
  2020-09-16 20:19   ` Joe Perches
  2020-09-17  4:35   ` Nathan Chancellor
  2 siblings, 0 replies; 7+ messages in thread
From: Gustavo A. R. Silva @ 2020-09-16 20:18 UTC (permalink / raw)
  To: Nick Desaulniers
  Cc: Trond Myklebust, Anna Schumaker, Gustavo A . R . Silva,
	Joe Perches, Nathan Chancellor, Hongxiang Lou, Miaohe Lin,
	linux-nfs, linux-kernel, clang-built-linux

On Wed, Sep 16, 2020 at 01:02:55PM -0700, Nick Desaulniers wrote:
> 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")
> Link: https://bugs.llvm.org/show_bug.cgi?id=47539
> Suggested-by: Joe Perches <joe@perches.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>

Acked-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Thanks
--
Gustavo

> ---
> 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(-)
> 
> diff --git a/fs/nfs/super.c b/fs/nfs/super.c
> index d20326ee0475..eb2401079b04 100644
> --- a/fs/nfs/super.c
> +++ b/fs/nfs/super.c
> @@ -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.618.gf4bc123cb7-goog
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] nfs: remove incorrect fallthrough label
  2020-09-15 23:29 [PATCH] " Joe Perches
@ 2020-09-16 20:02 ` Nick Desaulniers
  2020-09-16 20:18   ` Gustavo A. R. Silva
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Nick Desaulniers @ 2020-09-16 20:02 UTC (permalink / raw)
  To: Trond Myklebust, Anna Schumaker
  Cc: Gustavo A . R . Silva, Joe Perches, Nick Desaulniers,
	Nathan Chancellor, Hongxiang Lou, Miaohe Lin, linux-nfs,
	linux-kernel, clang-built-linux

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")
Link: https://bugs.llvm.org/show_bug.cgi?id=47539
Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
---
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(-)

diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index d20326ee0475..eb2401079b04 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -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.618.gf4bc123cb7-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-09-18  1:36 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17  6:21 [PATCH v2] nfs: remove incorrect fallthrough label linmiaohe
  -- strict thread matches above, loose matches on Subject: below --
2020-09-15 23:29 [PATCH] " Joe Perches
2020-09-16 20:02 ` [PATCH v2] " Nick Desaulniers
2020-09-16 20:18   ` Gustavo A. R. Silva
2020-09-16 20:19   ` Joe Perches
2020-09-17 21:41     ` Nick Desaulniers
2020-09-18  1:36       ` Joe Perches
2020-09-17  4:35   ` Nathan Chancellor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.