linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drbd: avoid clang warning about pointless switch statement
@ 2017-02-01 16:55 Arnd Bergmann
  2017-02-06 13:43 ` Lars Ellenberg
  0 siblings, 1 reply; 4+ messages in thread
From: Arnd Bergmann @ 2017-02-01 16:55 UTC (permalink / raw)
  To: Philipp Reisner, Lars Ellenberg
  Cc: drbd-dev, Arnd Bergmann, Nicolas Dichtel, David S. Miller, linux-kernel

The drbd code causes warnings that we cannot easily disable when building with clang:

In file included from drivers/block/drbd/drbd_debugfs.c:10:
In file included from drivers/block/drbd/drbd_int.h:48:
In file included from include/linux/drbd_genl_api.h:53:
In file included from include/linux/genl_magic_struct.h:237:
include/linux/drbd_genl.h:300:1: warning: no case matching constant switch condition '0'

There is nothing wrong with the code, and adding 'default:' labels
in the right place is enough to let clang shut up about the warning.

Fixes: ec2c35ac1ea2 ("drbd: prepare the transition from connector to genetlink")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/genl_magic_struct.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/genl_magic_struct.h b/include/linux/genl_magic_struct.h
index 6270a56e5edc..c6fbafb834f1 100644
--- a/include/linux/genl_magic_struct.h
+++ b/include/linux/genl_magic_struct.h
@@ -190,6 +190,7 @@ static inline void ct_assert_unique_operations(void)
 {
 	switch (0) {
 #include GENL_MAGIC_INCLUDE_FILE
+	default:
 		;
 	}
 }
@@ -208,6 +209,7 @@ static inline void ct_assert_unique_top_level_attributes(void)
 {
 	switch (0) {
 #include GENL_MAGIC_INCLUDE_FILE
+	default:
 		;
 	}
 }
@@ -218,6 +220,7 @@ static inline void ct_assert_unique_ ## s_name ## _attributes(void)	\
 {									\
 	switch (0) {							\
 		s_fields						\
+		default:						\
 			;						\
 	}								\
 }
-- 
2.9.0

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

* Re: [PATCH] drbd: avoid clang warning about pointless switch statement
  2017-02-01 16:55 [PATCH] drbd: avoid clang warning about pointless switch statement Arnd Bergmann
@ 2017-02-06 13:43 ` Lars Ellenberg
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ellenberg @ 2017-02-06 13:43 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Philipp Reisner, drbd-dev, Nicolas Dichtel, David S. Miller,
	linux-kernel

Ack.

Ok, not exactly "pintless", it's a valid compile time assert for uniq ids,
basically a BUILD_BUG_ON(duplicate-ids). But adding a default clause
there does not hurt.

Thanks,
    Lars


On Wed, Feb 01, 2017 at 05:55:02PM +0100, Arnd Bergmann wrote:
> The drbd code causes warnings that we cannot easily disable when building with clang:
> 
> In file included from drivers/block/drbd/drbd_debugfs.c:10:
> In file included from drivers/block/drbd/drbd_int.h:48:
> In file included from include/linux/drbd_genl_api.h:53:
> In file included from include/linux/genl_magic_struct.h:237:
> include/linux/drbd_genl.h:300:1: warning: no case matching constant switch condition '0'
> 
> There is nothing wrong with the code, and adding 'default:' labels
> in the right place is enough to let clang shut up about the warning.
> 
> Fixes: ec2c35ac1ea2 ("drbd: prepare the transition from connector to genetlink")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/linux/genl_magic_struct.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/include/linux/genl_magic_struct.h b/include/linux/genl_magic_struct.h
> index 6270a56e5edc..c6fbafb834f1 100644
> --- a/include/linux/genl_magic_struct.h
> +++ b/include/linux/genl_magic_struct.h
> @@ -190,6 +190,7 @@ static inline void ct_assert_unique_operations(void)
>  {
>  	switch (0) {
>  #include GENL_MAGIC_INCLUDE_FILE
> +	default:
>  		;
>  	}
>  }
> @@ -208,6 +209,7 @@ static inline void ct_assert_unique_top_level_attributes(void)
>  {
>  	switch (0) {
>  #include GENL_MAGIC_INCLUDE_FILE
> +	default:
>  		;
>  	}
>  }
> @@ -218,6 +220,7 @@ static inline void ct_assert_unique_ ## s_name ## _attributes(void)	\
>  {									\
>  	switch (0) {							\
>  		s_fields						\
> +		default:						\
>  			;						\
>  	}								\
>  }
> -- 
> 2.9.0

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

* Re: [PATCH] drbd: avoid clang warning about pointless switch statement
  2018-09-12 10:01 Philipp Klocke
@ 2018-09-12 10:24 ` Arnd Bergmann
  0 siblings, 0 replies; 4+ messages in thread
From: Arnd Bergmann @ 2018-09-12 10:24 UTC (permalink / raw)
  To: 20170201165532.2605534-1-arnd
  Cc: philipp.reisner, lars.ellenberg, drbd-dev, Nicolas Dichtel,
	David Miller, Linux Kernel Mailing List

On Wed, Sep 12, 2018 at 12:01 PM Philipp Klocke <Phil_K97@gmx.de> wrote:
>
> Hello,
>
> I've also stumbled across the "warning: no case matching constant switch
> condition '0'" and wanted to fix it.
> As your suggestion is probably the best way, I wanted to ask why it
> didn't get merged yet.
>
> Maybe the patch got lost?

I think I never followed up on the patch when it didn't get merged the
first time around. If you have a copy at hand, could you add your
Signed-off-by and send a version that applies to the current kernel?

    Arnd

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

* Re: [PATCH] drbd: avoid clang warning about pointless switch statement
@ 2018-09-12 10:01 Philipp Klocke
  2018-09-12 10:24 ` Arnd Bergmann
  0 siblings, 1 reply; 4+ messages in thread
From: Philipp Klocke @ 2018-09-12 10:01 UTC (permalink / raw)
  To: arnd, philipp.reisner, lars.ellenberg
  Cc: drbd-dev, nicolas.dichtel, davem, linux-kernel

Hello,

I've also stumbled across the "warning: no case matching constant switch
condition '0'" and wanted to fix it.
As your suggestion is probably the best way, I wanted to ask why it
didn't get merged yet.

Maybe the patch got lost?

Best regards,
Philipp



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

end of thread, other threads:[~2018-09-12 10:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-01 16:55 [PATCH] drbd: avoid clang warning about pointless switch statement Arnd Bergmann
2017-02-06 13:43 ` Lars Ellenberg
2018-09-12 10:01 Philipp Klocke
2018-09-12 10:24 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).