All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Bart Van Assche <bvanassche@acm.org>,
	Ivan Shapovalov <intelfx@intelfx.name>,
	Andrew Morton <akpm@linux-foundation.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	David Rientjes <rientjes@google.com>,
	David Hildenbrand <david@redhat.com>,
	Joel Granados <joel.granados@kernel.org>,
	Sourav Panda <souravpanda@google.com>,
	Kaiyang Zhao <kaiyang2@cs.cmu.edu>,
	Johannes Weiner <hannes@cmpxchg.org>,
	Konstantin Khlebnikov <koct9i@gmail.com>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH] mm/vmstat: Fix a W=1 clang compiler warning
Date: Wed, 29 Jan 2025 22:46:44 +0000	[thread overview]
Message-ID: <20250129224644.0f7228db@pumpkin> (raw)
In-Reply-To: <a4dc3313-b9b7-4075-b082-7232b3b7717b@suse.cz>

On Wed, 29 Jan 2025 11:22:00 +0100
Vlastimil Babka <vbabka@suse.cz> 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@intelfx.name>
> > Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> > ---
> >   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


      parent reply	other threads:[~2025-01-29 22:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-12 21:31 [PATCH] mm/vmstat: Fix a W=1 clang compiler warning Bart Van Assche
2024-12-13  2:24 ` Andrew Morton
2024-12-13 22:01   ` Bart Van Assche
2025-01-22  1:57   ` Ivan Shapovalov
2025-01-22 21:55     ` Bart Van Assche
2025-01-28 21:36     ` Bart Van Assche
2025-01-29 10:22       ` Vlastimil Babka
2025-01-29 17:30         ` Bart Van Assche
2025-01-29 22:46         ` David Laight [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250129224644.0f7228db@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bvanassche@acm.org \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=intelfx@intelfx.name \
    --cc=joel.granados@kernel.org \
    --cc=justinstitt@google.com \
    --cc=kaiyang2@cs.cmu.edu \
    --cc=koct9i@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=llvm@lists.linux.dev \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=rientjes@google.com \
    --cc=souravpanda@google.com \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.