net/dsa: remove unused macros to tame gcc warning
Subsystems (5)
PATCH 1/1 net/dsa: remove unused macros to tame gcc warning
There are some macros unused, they causes much gcc warnings. Let's remove them to tame gcc.
net/dsa/tag_brcm.c:51:0: warning: macro "BRCM_EG_RC_SWITCH" is not used [-Wunused-macros]net/dsa/tag_brcm.c:53:0: warning: macro "BRCM_EG_RC_MIRROR" is not used [-Wunused-macros]net/dsa/tag_brcm.c:55:0: warning: macro "BRCM_EG_TC_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:35:0: warning: macro "BRCM_IG_TS_SHIFT" is not used [-Wunused-macros]net/dsa/tag_brcm.c:46:0: warning: macro "BRCM_EG_RC_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:49:0: warning: macro "BRCM_EG_RC_PROT_SNOOP" is not used [-Wunused-macros]net/dsa/tag_brcm.c:34:0: warning: macro "BRCM_IG_TE_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:43:0: warning: macro "BRCM_EG_CID_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:50:0: warning: macro "BRCM_EG_RC_PROT_TERM" is not used [-Wunused-macros]net/dsa/tag_brcm.c:54:0: warning: macro "BRCM_EG_TC_SHIFT" is not used [-Wunused-macros]net/dsa/tag_brcm.c:52:0: warning: macro "BRCM_EG_RC_MAC_LEARN" is not used [-Wunused-macros]net/dsa/tag_brcm.c:48:0: warning: macro "BRCM_EG_RC_EXCEPTION" is not used [-Wunused-macros]
--- net/dsa/tag_brcm.c | 15 --------------- 1 file changed, 15 deletions(-)
net/dsa/tag_brcm.c +0 -15
@@ -30,29 +30,14 @@/* 1st byte in the tag */ #define BRCM_IG_TC_SHIFT 2#define BRCM_IG_TC_MASK 0x7 -/* 2nd byte in the tag */ -#define BRCM_IG_TE_MASK 0x3 -#define BRCM_IG_TS_SHIFT 7/* 3rd byte in the tag */ #define BRCM_IG_DSTMAP2_MASK 1#define BRCM_IG_DSTMAP1_MASK 0xff/* Egress fields */ -/* 2nd byte in the tag */ -#define BRCM_EG_CID_MASK 0xff -/* 3rd byte in the tag */ -#define BRCM_EG_RC_MASK 0xff#define BRCM_EG_RC_RSVD (3 << 6) -#define BRCM_EG_RC_EXCEPTION (1 << 5) -#define BRCM_EG_RC_PROT_SNOOP (1 << 4) -#define BRCM_EG_RC_PROT_TERM (1 << 3) -#define BRCM_EG_RC_SWITCH (1 << 2) -#define BRCM_EG_RC_MAC_LEARN (1 << 1) -#define BRCM_EG_RC_MIRROR (1 << 0) -#define BRCM_EG_TC_SHIFT 5 -#define BRCM_EG_TC_MASK 0x7#define BRCM_EG_PID_MASK 0x1f #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) || \
Signature · 1 line
1.8.3.1
Quoted 2 lines · Alex Shi
There are some macros unused, they causes much gcc warnings. Let's remove them to tame gcc.
I believe these to be essentially poor warnings.
Aren't these warnings generated only when adding W=2 to the make command line?
Perhaps it's better to move the warning to level 3
---
scripts/Makefile.extrawarn +1 -1
@@ -68,7 +68,6 @@ KBUILD_CFLAGS += $(call cc-option, -Wlogical-op) KBUILD_CFLAGS += -Wmissing-field-initializers KBUILD_CFLAGS += -Wtype-limits KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) -KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2
@@ -89,6 +88,7 @@ KBUILD_CFLAGS += -Wredundant-decls KBUILD_CFLAGS += -Wsign-compare KBUILD_CFLAGS += -Wswitch-default KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) +KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
Quoted 16 lines · Joe Perches
Quoted 2 lines · Alex Shi
There are some macros unused, they causes much gcc warnings. Let's remove them to tame gcc.
I believe these to be essentially poor warnings.
Aren't these warnings generated only when adding W=2 to the make command line?
Perhaps it's better to move the warning to level 3
---scripts/Makefile.extrawarn +0
-0
scripts/Makefile.extrawarn KBUILD_CFLAGS += $(call cc-option, -Wlogical-op) · line 71
Quoted 4 lines
scripts/Makefile.extrawarn +0
-1@@ -68,7 +68,6 @@ KBUILD_CFLAGS += $(call cc-option, -Wlogical-op) KBUILD_CFLAGS += -Wmissing-field-initializers KBUILD_CFLAGS += -Wtype-limits KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) -KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)
This changed too much, and impact others. May not good. :)
Thanks
Alex
Quoted 12 lines
scripts/Makefile.extrawarn +1
-0KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN2@@ -89,6 +88,7 @@ KBUILD_CFLAGS += -Wredundant-decls KBUILD_CFLAGS += -Wsign-compare KBUILD_CFLAGS += -Wswitch-default KBUILD_CFLAGS += $(call cc-option, -Wpacked-bitfield-compat) +KBUILD_CFLAGS += $(call cc-option, -Wunused-macros) KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARN3
Quoted 11 lines · Alex Shi
Quoted 9 lines · Joe Perches
Quoted 2 lines · Alex Shi
There are some macros unused, they causes much gcc warnings. Let's remove them to tame gcc.
I believe these to be essentially poor warnings.
Aren't these warnings generated only when adding W=2 to the make command line?
Quoted 13 lines
Quoted 11 lines
Perhaps it's better to move the warning to level 3
---scripts/Makefile.extrawarn +0
-0@@ -68,7 +68,6 @@ KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)KBUILD_CFLAGS += -Wmissing-field-initializers
KBUILD_CFLAGS+= -Wtype-limits
KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) -KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)This changed too much, and impact others. May not good. :)
Can you clarify what you mean?
Quoted 26 lines · Joe Perches
Quoted 11 lines · Alex Shi
Quoted 9 lines · Joe Perches
Quoted 2 lines · Alex Shi
There are some macros unused, they causes much gcc warnings. Let's remove them to tame gcc.
I believe these to be essentially poor warnings.
Aren't these warnings generated only when adding W=2 to the make command line?
Quoted 13 lines
Quoted 11 lines
Perhaps it's better to move the warning to level 3
---scripts/Makefile.extrawarn +0
-0@@ -68,7 +68,6 @@ KBUILD_CFLAGS += $(call cc-option, -Wlogical-op)KBUILD_CFLAGS += -Wmissing-field-initializers
KBUILD_CFLAGS+= -Wtype-limits
KBUILD_CFLAGS += $(call cc-option, -Wmaybe-uninitialized) -KBUILD_CFLAGS += $(call cc-option, -Wunused-macros)This changed too much, and impact others. May not good. :)
Quoted 2 lines
Can you clarify what you mean?
Uh, change in this file will impact all kernels not only for net/dsa. If you want to keep these unused macros, maybe better to put them into comments?
Thanks!
Alex
From: Joe Perches
Quoted 7 lines
Sent: 06 November 2020 06:36
Quoted 2 lines · Alex Shi
There are some macros unused, they causes much gcc warnings. Let's remove them to tame gcc.
I believe these to be essentially poor warnings.
Indeed.
One 'solution' is to move the #defines into an included .h file.
Quoted 4 lines
Aren't these warnings generated only when adding W=2 to the make command line?
Perhaps it's better to move the warning to level 3
I'd move then to level 9999999999.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Andrew Lunn
maintainerQuoted 46 lines · Alex Shi
There are some macros unused, they causes much gcc warnings. Let's remove them to tame gcc.
net/dsa/tag_brcm.c:51:0: warning: macro "BRCM_EG_RC_SWITCH" is not used [-Wunused-macros]net/dsa/tag_brcm.c:53:0: warning: macro "BRCM_EG_RC_MIRROR" is not used [-Wunused-macros]net/dsa/tag_brcm.c:55:0: warning: macro "BRCM_EG_TC_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:35:0: warning: macro "BRCM_IG_TS_SHIFT" is not used [-Wunused-macros]net/dsa/tag_brcm.c:46:0: warning: macro "BRCM_EG_RC_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:49:0: warning: macro "BRCM_EG_RC_PROT_SNOOP" is not used [-Wunused-macros]net/dsa/tag_brcm.c:34:0: warning: macro "BRCM_IG_TE_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:43:0: warning: macro "BRCM_EG_CID_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:50:0: warning: macro "BRCM_EG_RC_PROT_TERM" is not used [-Wunused-macros]net/dsa/tag_brcm.c:54:0: warning: macro "BRCM_EG_TC_SHIFT" is not used [-Wunused-macros]net/dsa/tag_brcm.c:52:0: warning: macro "BRCM_EG_RC_MAC_LEARN" is not used [-Wunused-macros]net/dsa/tag_brcm.c:48:0: warning: macro "BRCM_EG_RC_EXCEPTION" is not used [-Wunused-macros]Signed-off-by Alex Shi <[email protected]>Cc Andrew Lunn <[email protected]>Cc Vivien Didelot <[email protected]>Cc Florian Fainelli <[email protected]>Cc Vladimir Oltean <[email protected]>Cc "David S. Miller" <[email protected]>Cc Jakub Kicinski <[email protected]>--- net/dsa/tag_brcm.c | 15 --------------- 1 file changed, 15 deletions(-)net/dsa/tag_brcm.c +0
-0
net/dsa/tag_brcm.c line 35
Quoted 9 lines
net/dsa/tag_brcm.c +0
-3@@ -30,29 +30,14 @@/* 1st byte in the tag */ #define BRCM_IG_TC_SHIFT 2#define BRCM_IG_TC_MASK 0x7 -/* 2nd byte in the tag */ -#define BRCM_IG_TE_MASK 0x3 -#define BRCM_IG_TS_SHIFT 7/* 3rd byte in the tag */ #define BRCM_IG_DSTMAP2_MASK 1#define BRCM_IG_DSTMAP1_MASK 0xff
Hi Alex
It is good to remember that there are multiple readers of source files. There is the compiler which generates code from it, and there is the human trying to understand what is going on, what the hardware can do, how we could maybe extend the code in the future to make use of bits are currently don't, etc.
The compiler has no use of these macros, at the moment. But i as a human do. It is valuable documentation, given that there is no open datasheet for this hardware.
I would say these warnings are bogus, and the code should be left alone.
Andrew
Quoted 65 lines · Andrew Lunn
Quoted 46 lines · Alex Shi
There are some macros unused, they causes much gcc warnings. Let's remove them to tame gcc.
net/dsa/tag_brcm.c:51:0: warning: macro "BRCM_EG_RC_SWITCH" is not used [-Wunused-macros]net/dsa/tag_brcm.c:53:0: warning: macro "BRCM_EG_RC_MIRROR" is not used [-Wunused-macros]net/dsa/tag_brcm.c:55:0: warning: macro "BRCM_EG_TC_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:35:0: warning: macro "BRCM_IG_TS_SHIFT" is not used [-Wunused-macros]net/dsa/tag_brcm.c:46:0: warning: macro "BRCM_EG_RC_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:49:0: warning: macro "BRCM_EG_RC_PROT_SNOOP" is not used [-Wunused-macros]net/dsa/tag_brcm.c:34:0: warning: macro "BRCM_IG_TE_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:43:0: warning: macro "BRCM_EG_CID_MASK" is not used [-Wunused-macros]net/dsa/tag_brcm.c:50:0: warning: macro "BRCM_EG_RC_PROT_TERM" is not used [-Wunused-macros]net/dsa/tag_brcm.c:54:0: warning: macro "BRCM_EG_TC_SHIFT" is not used [-Wunused-macros]net/dsa/tag_brcm.c:52:0: warning: macro "BRCM_EG_RC_MAC_LEARN" is not used [-Wunused-macros]net/dsa/tag_brcm.c:48:0: warning: macro "BRCM_EG_RC_EXCEPTION" is not used [-Wunused-macros]Signed-off-by Alex Shi <[email protected]>Cc Andrew Lunn <[email protected]>Cc Vivien Didelot <[email protected]>Cc Florian Fainelli <[email protected]>Cc Vladimir Oltean <[email protected]>Cc "David S. Miller" <[email protected]>Cc Jakub Kicinski <[email protected]>--- net/dsa/tag_brcm.c | 15 --------------- 1 file changed, 15 deletions(-)net/dsa/tag_brcm.c +0
-0net/dsa/tag_brcm.c line 35
Quoted 9 lines
net/dsa/tag_brcm.c +0
-3@@ -30,29 +30,14 @@/* 1st byte in the tag */ #define BRCM_IG_TC_SHIFT 2#define BRCM_IG_TC_MASK 0x7 -/* 2nd byte in the tag */ -#define BRCM_IG_TE_MASK 0x3 -#define BRCM_IG_TS_SHIFT 7/* 3rd byte in the tag */ #define BRCM_IG_DSTMAP2_MASK 1#define BRCM_IG_DSTMAP1_MASK 0xffHi Alex
It is good to remember that there are multiple readers of source files. There is the compiler which generates code from it, and there is the human trying to understand what is going on, what the hardware can do, how we could maybe extend the code in the future to make use of bits are currently don't, etc.
Quoted 6 lines
The compiler has no use of these macros, at the moment. But i as a human do. It is valuable documentation, given that there is no open datasheet for this hardware.
I would say these warnings are bogus, and the code should be left alone.
Agreed, these definitions are intended to document what the hardware does. These warnings are getting too far.
Signature · 1 line
Florian
Quoted 8 lines · Florian Fainelli
Quoted 8 lines
Hi Alex
It is good to remember that there are multiple readers of source files. There is the compiler which generates code from it, and there is the human trying to understand what is going on, what the hardware can do, how we could maybe extend the code in the future to make use of bits are currently don't, etc.
Quoted 9 lines
Quoted 6 lines
The compiler has no use of these macros, at the moment. But i as a human do. It is valuable documentation, given that there is no open datasheet for this hardware.
I would say these warnings are bogus, and the code should be left alone.
Agreed, these definitions are intended to document what the hardware does. These warnings are getting too far.
Thanks for all comments! I agree these info are much meaningful. Is there other way to tame the gcc warning? like put them into a .h file or covered by comments?
Thanks
Alex
Quoted 11 lines · Alex Shi
Quoted 10 lines · Florian Fainelli
Quoted 10 lines
It is good to remember that there are multiple readers of source files. There is the compiler which generates code from it, and there is the human trying to understand what is going on, what the hardware can do, how we could maybe extend the code in the future to make use of bits are currently don't, etc.
The compiler has no use of these macros, at the moment. But i as a human do. It is valuable documentation, given that there is no open datasheet for this hardware.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I would say these warnings are bogus, and the code should be left alone.
Agreed, these definitions are intended to document what the hardware does. These warnings are getting too far.
Thanks for all comments! I agree these info are much meaningful. Is there other way to tame the gcc warning? like put them into a .h file or covered by comments?
Does _any_ version of gcc have this warning on by default?
I still think my proposal of moving the warning from W=2 to W=3 quite reasonable.
Another possibility is to turn the warning off altogether.
Andrew Lunn
maintainerQuoted 21 lines · Joe Perches
Quoted 11 lines · Alex Shi
Quoted 10 lines · Florian Fainelli
Quoted 10 lines
It is good to remember that there are multiple readers of source files. There is the compiler which generates code from it, and there is the human trying to understand what is going on, what the hardware can do, how we could maybe extend the code in the future to make use of bits are currently don't, etc.
The compiler has no use of these macros, at the moment. But i as a human do. It is valuable documentation, given that there is no open datasheet for this hardware.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I would say these warnings are bogus, and the code should be left alone.
Agreed, these definitions are intended to document what the hardware does. These warnings are getting too far.
Thanks for all comments! I agree these info are much meaningful. Is there other way to tame the gcc warning? like put them into a .h file or covered by comments?
Quoted 6 lines
Does _any_ version of gcc have this warning on by default?
I still think my proposal of moving the warning from W=2 to W=3 quite reasonable.
Another possibility is to turn the warning off altogether.
Lets tern the question around first. How many real bugs have you found with this warning? Places where the #define should of been used, but was not? Then we can get an idea of the value of this warning. My guess would be, its value is ~ 0 for the kernel. If so, we should just turn it off.
Andrew
From: Andrew Lunn
Quoted 29 lines
Sent: 07 November 2020 22:33
Quoted 26 lines · Joe Perches
Quoted 11 lines · Alex Shi
Quoted 10 lines · Florian Fainelli
Quoted 10 lines
It is good to remember that there are multiple readers of source files. There is the compiler which generates code from it, and there is the human trying to understand what is going on, what the hardware can do, how we could maybe extend the code in the future to make use of bits are currently don't, etc.
The compiler has no use of these macros, at the moment. But i as a human do. It is valuable documentation, given that there is no open datasheet for this hardware.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
I would say these warnings are bogus, and the code should be left alone.
Agreed, these definitions are intended to document what the hardware does. These warnings are getting too far.
Thanks for all comments! I agree these info are much meaningful. Is there other way to tame the gcc warning? like put them into a .h file or covered by comments?
Does _any_ version of gcc have this warning on by default?
I still think my proposal of moving the warning from W=2 to W=3 quite reasonable.
Quoted 7 lines
Quoted 1 line
Another possibility is to turn the warning off altogether.
Lets tern the question around first. How many real bugs have you found with this warning? Places where the #define should of been used, but was not? Then we can get an idea of the value of this warning. My guess would be, its value is ~ 0 for the kernel. If so, we should just turn it off.
Sometimes there are defines for 0, 1 and 2 (enumeration or bitmap) and the one for 0 is never used.
Rather than delete the define for 0 (which has been proposed at least once in this series) the 'fix' would be to find the initialisation and replace the literal 0 with the define. OTOH it is probably implicit from a memset().
Even if never actually used the define for 0 helps the human reading the code.
The same is true when there are defines for hardware register bits. It is useful to know what they all mean - even if some aren't used.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)