The patch titled Subject: mm: Fix clang W=1 compiler warnings has been added to the -mm mm-unstable branch. Its filename is mm-fix-clang-w=1-compiler-warnings.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-fix-clang-w=1-compiler-warnings.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Bart Van Assche <bvanassche@xxxxxxx> Subject: mm: Fix clang W=1 compiler warnings Date: Fri, 31 Jan 2025 11:12:23 -0800 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 mm/ with W=1. Hence revert commit 30c2de0a267c and instead make NR_LRU_BASE and NR_ZONE_LRU_BASE integer constants instead of enumeration constants. Additionally, convert the item##_NORMAL constants from type enum vm_event_item into int before subtracting ZONE_NORMAL. The latter constant has type enum zone_type. Link: https://lkml.kernel.org/r/20250131191231.1370466-1-bvanassche@xxxxxxx Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx> Cc: Ivan Shapovalov <intelfx@xxxxxxxxxxxx> Cc: Vlastimil Babka <vbabka@xxxxxxx> Cc: David Laight <david.laight@xxxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: David Rientjes <rientjes@xxxxxxxxxx> Cc: Joel Granados <joel.granados@xxxxxxxxxx> Cc: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Kaiyang Zhao <kaiyang2@xxxxxxxxxx> Cc: Nathan Chancellor <nathan@xxxxxxxxxx> Cc: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx> Cc: Sourav Panda <souravpanda@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- include/linux/mmzone.h | 26 +++++++++++++++++++++----- include/linux/vmstat.h | 9 +++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) --- a/include/linux/mmzone.h~mm-fix-clang-w=1-compiler-warnings +++ a/include/linux/mmzone.h @@ -135,11 +135,20 @@ 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 (__NR_ZONE_LRU_BASE + 0) +#define NR_VM_ZONE_STAT_ITEMS (__NR_VM_ZONE_STAT_ITEMS + 0) + enum zone_stat_item { /* First 128 byte cacheline (assuming 64 bit words) */ NR_FREE_PAGES, - NR_ZONE_LRU_BASE, /* Used only for compaction and reclaim retry */ - NR_ZONE_INACTIVE_ANON = NR_ZONE_LRU_BASE, + __NR_ZONE_LRU_BASE, /* Used only for compaction and reclaim retry */ + NR_ZONE_INACTIVE_ANON = __NR_ZONE_LRU_BASE, NR_ZONE_ACTIVE_ANON, NR_ZONE_INACTIVE_FILE, NR_ZONE_ACTIVE_FILE, @@ -155,11 +164,18 @@ enum zone_stat_item { #ifdef CONFIG_UNACCEPTED_MEMORY NR_UNACCEPTED, #endif - NR_VM_ZONE_STAT_ITEMS }; + __NR_VM_ZONE_STAT_ITEMS }; + +/* + * enum lru_list constants are often added to NR_LRU_BASE. Define NR_LRU_BASE + * as an integer instead of enum node_stat_item to prevent that the compiler + * warns about enumeration type mismatches. + */ +#define NR_LRU_BASE (__NR_LRU_BASE + 0) enum node_stat_item { - NR_LRU_BASE, - NR_INACTIVE_ANON = NR_LRU_BASE, /* must match order of LRU_[IN]ACTIVE */ + __NR_LRU_BASE, + NR_INACTIVE_ANON = __NR_LRU_BASE, /*must match order of LRU_[IN]ACTIVE*/ NR_ACTIVE_ANON, /* " " " " " */ NR_INACTIVE_FILE, /* " " " " " */ NR_ACTIVE_FILE, /* " " " " " */ --- a/include/linux/vmstat.h~mm-fix-clang-w=1-compiler-warnings +++ a/include/linux/vmstat.h @@ -135,8 +135,13 @@ static inline void vm_events_fold_cpu(in #define count_vm_vma_lock_event(x) do {} while (0) #endif +/* + * item##_NORMAL has type enum vm_event_item while ZONE_NORMAL and zid have + * type enum zone_type. Suppress compiler warnings about mixing different + * enumeration types by converting item##_NORMAL into an int with '+ 0'. + */ #define __count_zid_vm_events(item, zid, delta) \ - __count_vm_events(item##_NORMAL - ZONE_NORMAL + zid, delta) + __count_vm_events((item##_NORMAL + 0) - ZONE_NORMAL + zid, delta) /* * Zone and node-based page accounting with per cpu differentials. @@ -515,7 +520,7 @@ static inline const char *node_stat_name static inline const char *lru_list_name(enum lru_list lru) { - return node_stat_name(NR_LRU_BASE + (enum node_stat_item)lru) + 3; // skip "nr_" + return node_stat_name(NR_LRU_BASE + lru) + 3; // skip "nr_" } #if defined(CONFIG_VM_EVENT_COUNTERS) || defined(CONFIG_MEMCG) _ Patches currently in -mm which might be from bvanassche@xxxxxxx are procfs-fix-a-locking-bug-in-a-vmcore_add_device_dump-error-path.patch mm-fix-clang-w=1-compiler-warnings.patch