Re: [PATCH] mm/vmstat: Fix a W=1 clang compiler warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 29 Jan 2025 11:22:00 +0100
Vlastimil Babka <vbabka@xxxxxxx> wrote:

> On 1/28/25 22:36, Bart Van Assche wrote:
> > On 1/21/25 5:57 PM, Ivan Shapovalov wrote:  
> >>> Spose so.  One always suspects that adding a typecast is a sign that we
> >>> screwed things up somehow.  The relationship between enums lru_list and
> >>> node_stat_item is foggy, and I'm unsure whether this is the place to
> >>> make the transition it.  Perhaps lru_list_name() should take an
> >>> `unsigned int' arg instead.  
> >> 
> >> All of these *_name() functions do seem to expect arguments in range of
> >> the corresponding enums, so perhaps keep those args typed as a form of
> >> self-documenting code, and do this instead?  
> > 
> > If nobody objects I will submit this patch for review after the merge
> > window has closed:
> > 
> > Subject: [PATCH] mm/vmstat: Fix W=1 clang compiler warnings
> > 
> > Commit 30c2de0a267c ("mm/vmstat: fix a W=1 clang compiler warning")
> > suppresses some but not all compiler warnings that are reported by clang
> > when building with W=1 about NR_LRU_BASE and NR_ZONE_LRU_BASE. Hence
> > revert commit 30c2de0a267c and instead make NR_LRU_BASE and
> > NR_ZONE_LRU_BASE integer constants instead of enumeration constants.
> > 
> > Cc: Ivan Shapovalov <intelfx@xxxxxxxxxxxx>
> > Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
> > ---
> >   include/linux/mmzone.h | 22 +++++++++++++++++++---
> >   include/linux/vmstat.h |  9 +++++++--
> >   2 files changed, 26 insertions(+), 5 deletions(-)
> > 
> > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> > index 9540b41894da..92ed919ea99d 100644
> > --- a/include/linux/mmzone.h
> > +++ b/include/linux/mmzone.h
> > @@ -135,10 +135,19 @@ enum numa_stat_item {
> >   #define NR_VM_NUMA_EVENT_ITEMS 0
> >   #endif
> > 
> > +/*
> > + * NR_ZONE_LRU_BASE and NR_VM_ZONE_STAT_ITEMS are often added to 
> > enumeration
> > + * constants of another type than enum_zone_stat_item. Define these 
> > constants
> > + * as an integer instead of enum node_stat_item to prevent that the 
> > compiler
> > + * warns about enumeration type mismatches when these constants are used.
> > + */
> > +#define NR_ZONE_LRU_BASE	(1 * __NR_ZONE_LRU_BASE)
> > +#define NR_VM_ZONE_STAT_ITEMS	(1 * __NR_VM_ZONE_STAT_ITEMS)  
> 
> Seems an acceptable approach, dunno if this multiply by one is any better
> than casting to int?

I'd probably use (enum_value + 0) rather than a multiply.
And, if you are going to use multiply, I think it should be (value * 1)
for the same reason that 'if (1 == x)' horrible.

	David





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux