RE: [PATCH] net/dsa: remove unused macros to tame gcc warning

From: David Laight
Date: Sun Nov 08 2020 - 07:39:20 EST


From: Andrew Lunn
> Sent: 07 November 2020 22:33
>
> On Sat, Nov 07, 2020 at 09:39:42AM -0800, Joe Perches wrote:
> > On Sat, 2020-11-07 at 20:54 +0800, Alex Shi wrote:
> > > 在 2020/11/7 上午12:39, Florian Fainelli 写道:
> > > > > 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.
> > > > 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.
>
> 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)