* [Drbd-dev] [PATCH RESEND] drbd: avoid clang warning about pointless switch statement
@ 2018-10-02 17:14 Nathan Chancellor
2018-10-04 19:18 ` Lars Ellenberg
2018-10-04 20:09 ` [Drbd-dev] [PATCH v2] drbd: Avoid Clang warning about pointless switch statment Nathan Chancellor
0 siblings, 2 replies; 7+ messages in thread
From: Nathan Chancellor @ 2018-10-02 17:14 UTC (permalink / raw)
To: Philipp Reisner, Lars Ellenberg, Jens Axboe
Cc: linux-block, Nathan Chancellor, linux-kernel, Arnd Bergmann,
drbd-dev
From: Arnd Bergmann <arnd@arndb.de>
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>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
This was recently resent by Philipp Klocke but the attribution on it
was incorrect (had Arnd's signoff but no From: line) and linux-block
wasn't cc'd, who presumably should take this patch since this file was
introduced by commit ec2c35ac1ea2 ("drbd: prepare the transition from
connector to genetlink"). If that is the case, perhaps these files
should be added to the drbd MAINTAINERS entry since they were introduced
by drbd and have been the only consumers since; I'd be happy to send a
patch if others agree.
It was acked by Lars on https://lore.kernel.org/patchwork/patch/756723/
so I don't know if this patch should carry
Acked-by: Lars Ellenberg <lars.ellenberg@linbit.com>
or not. I'll leave that up to the maintainer to decide.
Thanks!
Nathan
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 5972e4969197..c11f42179c63 100644
--- a/include/linux/genl_magic_struct.h
+++ b/include/linux/genl_magic_struct.h
@@ -191,6 +191,7 @@ static inline void ct_assert_unique_operations(void)
{
switch (0) {
#include GENL_MAGIC_INCLUDE_FILE
+ default:
;
}
}
@@ -209,6 +210,7 @@ static inline void ct_assert_unique_top_level_attributes(void)
{
switch (0) {
#include GENL_MAGIC_INCLUDE_FILE
+ default:
;
}
}
@@ -219,6 +221,7 @@ static inline void ct_assert_unique_ ## s_name ## _attributes(void) \
{ \
switch (0) { \
s_fields \
+ default: \
; \
} \
}
--
2.19.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [Drbd-dev] [PATCH RESEND] drbd: avoid clang warning about pointless switch statement
2018-10-02 17:14 [Drbd-dev] [PATCH RESEND] drbd: avoid clang warning about pointless switch statement Nathan Chancellor
@ 2018-10-04 19:18 ` Lars Ellenberg
2018-10-04 19:22 ` Nathan Chancellor
2018-10-04 20:09 ` [Drbd-dev] [PATCH v2] drbd: Avoid Clang warning about pointless switch statment Nathan Chancellor
1 sibling, 1 reply; 7+ messages in thread
From: Lars Ellenberg @ 2018-10-04 19:18 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Jens Axboe, Arnd Bergmann, Philipp Reisner, linux-kernel,
linux-block, drbd-dev
On Tue, Oct 02, 2018 at 10:14:48AM -0700, Nathan Chancellor wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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.
Actually, I think I'd prefer a "case 0:" instead of the "default:",
because that would assert that we don't use a 0 for op or field numbers.
As at least some people seem to care, I suggest we bundle up
this and the other clang warning you just resent the patch for
with whatever else we may come up with for the next merge window
and send a pull request to Jens then.
In case we forget, please send a friendly reminder.
Thanks,
Lars
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [Drbd-dev] [PATCH RESEND] drbd: avoid clang warning about pointless switch statement
2018-10-04 19:18 ` Lars Ellenberg
@ 2018-10-04 19:22 ` Nathan Chancellor
0 siblings, 0 replies; 7+ messages in thread
From: Nathan Chancellor @ 2018-10-04 19:22 UTC (permalink / raw)
To: Lars Ellenberg
Cc: Jens Axboe, Arnd Bergmann, Philipp Reisner, linux-kernel,
linux-block, drbd-dev
On Thu, Oct 04, 2018 at 09:18:54PM +0200, Lars Ellenberg wrote:
> On Tue, Oct 02, 2018 at 10:14:48AM -0700, Nathan Chancellor wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > 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.
>
> Actually, I think I'd prefer a "case 0:" instead of the "default:",
> because that would assert that we don't use a 0 for op or field numbers.
>
> As at least some people seem to care, I suggest we bundle up
> this and the other clang warning you just resent the patch for
> with whatever else we may come up with for the next merge window
> and send a pull request to Jens then.
> In case we forget, please send a friendly reminder.
>
> Thanks,
>
> Lars
>
Hi Lars,
I will go ahead and test that change shortly and send it over for
review.
Thanks for the quick reply!
Nathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Drbd-dev] [PATCH v2] drbd: Avoid Clang warning about pointless switch statment
2018-10-02 17:14 [Drbd-dev] [PATCH RESEND] drbd: avoid clang warning about pointless switch statement Nathan Chancellor
2018-10-04 19:18 ` Lars Ellenberg
@ 2018-10-04 20:09 ` Nathan Chancellor
[not found] ` <20181217172401.GA30635@flashbox>
1 sibling, 1 reply; 7+ messages in thread
From: Nathan Chancellor @ 2018-10-04 20:09 UTC (permalink / raw)
To: Philipp Reisner, Lars Ellenberg, Jens Axboe
Cc: linux-block, Nathan Chancellor, linux-kernel, Arnd Bergmann,
drbd-dev
There are several warnings from Clang about no case statement matching
the constant 0:
In file included from drivers/block/drbd/drbd_receiver.c:48:
In file included from drivers/block/drbd/drbd_int.h:48:
In file included from ./include/linux/drbd_genl_api.h:54:
In file included from ./include/linux/genl_magic_struct.h:236:
./include/linux/drbd_genl.h:321:1: warning: no case matching constant
switch condition '0'
GENL_struct(DRBD_NLA_HELPER, 24, drbd_helper_info,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/linux/genl_magic_struct.h:220:10: note: expanded from macro
'GENL_struct'
switch (0) {
^
Silence this warning by adding a 'case 0:' statement. Additionally,
adjust the alignment of the statements in the ct_assert_unique macro to
avoid a checkpatch warning.
This solution was originally sent by Arnd Bergmann with a default case
statement: https://lore.kernel.org/patchwork/patch/756723/
Link: https://github.com/ClangBuiltLinux/linux/issues/43
Suggested-by: Lars Ellenberg <lars.ellenberg@linbit.com>
Signed-off-by: Nathan Chancellor <natechancellor@gmail.com>
---
Since this is not the same as Arnd's patch, I took authorship for it
while leaving a link to the original patch in the commit message. If
this is not how it should have been done, please let me know.
include/linux/genl_magic_struct.h | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/linux/genl_magic_struct.h b/include/linux/genl_magic_struct.h
index 5972e4969197..eeae59d3ceb7 100644
--- a/include/linux/genl_magic_struct.h
+++ b/include/linux/genl_magic_struct.h
@@ -191,6 +191,7 @@ static inline void ct_assert_unique_operations(void)
{
switch (0) {
#include GENL_MAGIC_INCLUDE_FILE
+ case 0:
;
}
}
@@ -209,6 +210,7 @@ static inline void ct_assert_unique_top_level_attributes(void)
{
switch (0) {
#include GENL_MAGIC_INCLUDE_FILE
+ case 0:
;
}
}
@@ -218,7 +220,8 @@ static inline void ct_assert_unique_top_level_attributes(void)
static inline void ct_assert_unique_ ## s_name ## _attributes(void) \
{ \
switch (0) { \
- s_fields \
+ s_fields \
+ case 0: \
; \
} \
}
--
2.19.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-12-18 13:36 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-10-02 17:14 [Drbd-dev] [PATCH RESEND] drbd: avoid clang warning about pointless switch statement Nathan Chancellor
2018-10-04 19:18 ` Lars Ellenberg
2018-10-04 19:22 ` Nathan Chancellor
2018-10-04 20:09 ` [Drbd-dev] [PATCH v2] drbd: Avoid Clang warning about pointless switch statment Nathan Chancellor
[not found] ` <20181217172401.GA30635@flashbox>
2018-12-17 17:29 ` Jens Axboe
2018-12-18 9:22 ` Lars Ellenberg
2018-12-18 13:29 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox