Re: [PATCH] mm/vmstat: Fix -Wenum-enum-conversion warning in vmstat.h

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

 



On Fri, 21 Jun 2024 19:13:57 +0100 Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:

> On Fri, Jun 21, 2024 at 01:16:04PM +0200, Shivamurthy Shastri wrote:
> > A W=1 build with -Wenum-enum-conversion enabled, results in the
> > following build warning due to an arithmetic operation between different
> > enumeration types 'enum node_stat_item' and 'enum lru_list':
> 
> OK, but why do we want -Wenum-enum-conversion enabled?  The code looks
> perfectly fine before, and now it looks ugly.  What bugs does this
> warning catch?
> 
> >  static inline const char *lru_list_name(enum lru_list lru)
> >  {
> > -	return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_"
> > +	return node_stat_name(NR_LRU_BASE + (enum node_stat_item)lru) + 3; // skip "nr_"
> >  }
> 
> and honestly, I'd convert it to an int instead of enum node_stat_item.
> Because it is not a node_stat_item, and it wouldn't make sense to
> add two node_stat_items together.  Just like it doesn't make sense to
> add two pointers together (but it does make sense to add an integer to a
> pointer).

Yeah, I suppose so.  The calling code iterates across enums with an
int, imaginatively called `i'.

Then again, it seems right that a function called lru_list_name() takes
an enum lru_list.






[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