mm: use ARRAY_END() instead of open-coding it
authorAlejandro Colomar <alx@kernel.org>
Thu, 11 Dec 2025 10:44:04 +0000 (11:44 +0100)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 21 Jan 2026 03:44:20 +0000 (19:44 -0800)
There aren't any bugs in this code; it's purely cosmetic.

By using ARRAY_END(), we prevent future issues, in case the code is
modified; it has less moving parts.  Also, it should be more readable (and
perhaps more importantly, greppable), as there are several ways of writing
an expression that gets the end of an array, which are unified by this API
name.

Link: https://lkml.kernel.org/r/2335917d123891fec074ab1b3acfb517cf14b5a7.1765449750.git.alx@kernel.org
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Alexander Potapenko <glider@google.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Christopher Bazley <chris.bazley.wg14@gmail.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Jann Horn <jannh@google.com>
Cc: Maciej W. Rozycki <macro@orcam.me.uk>
Cc: Marco Elver <elver@google.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/kmemleak.c
mm/memcontrol-v1.c

index 1ac56ce..fe33f2e 100644 (file)
@@ -510,7 +510,7 @@ static void mem_pool_free(struct kmemleak_object *object)
 {
        unsigned long flags;
 
-       if (object < mem_pool || object >= mem_pool + ARRAY_SIZE(mem_pool)) {
+       if (object < mem_pool || object >= ARRAY_END(mem_pool)) {
                kmem_cache_free(object_cache, object);
                return;
        }
index 6eed14b..b2f37bd 100644 (file)
@@ -1794,7 +1794,7 @@ static int memcg_numa_stat_show(struct seq_file *m, void *v)
 
        mem_cgroup_flush_stats(memcg);
 
-       for (stat = stats; stat < stats + ARRAY_SIZE(stats); stat++) {
+       for (stat = stats; stat < ARRAY_END(stats); stat++) {
                seq_printf(m, "%s=%lu", stat->name,
                           mem_cgroup_nr_lru_pages(memcg, stat->lru_mask,
                                                   false));
@@ -1805,7 +1805,7 @@ static int memcg_numa_stat_show(struct seq_file *m, void *v)
                seq_putc(m, '\n');
        }
 
-       for (stat = stats; stat < stats + ARRAY_SIZE(stats); stat++) {
+       for (stat = stats; stat < ARRAY_END(stats); stat++) {
 
                seq_printf(m, "hierarchical_%s=%lu", stat->name,
                           mem_cgroup_nr_lru_pages(memcg, stat->lru_mask,