From nobody Tue Dec 16 23:58:44 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BACD305048 for ; Thu, 11 Dec 2025 10:44:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765449850; cv=none; b=hca7Coo8p3BUpdRUe0N6LANFZmxf5OJddXajFw4CTtlD5ooY0+HMj6r/Y70ukZpLDSirdHMYhlyI9rPojRQOdJUaiJm9/8qWC1vimwIrxi+BGIUVgCanxtE8+WaKyMU6UO2jwdC5MnQ3DwhnjlMf0WC2hUEktEp+5dYhkT9/Blg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765449850; c=relaxed/simple; bh=AW/I4n2Zznh3mDRmErapu5OH/Tja5kRysX9LI6GHSSM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=aO8SS1oHkkcmFnhHtPGaGEh94YJi57CdBHNwzTLB/mTHU/LxEqKXvO4PR/pMHiDENAnFIlVa9Jcro+OrIeftUIOVYWY53uEn1e9FxhqOdlwJxcIC19460snPU97riMK9rO5lkvxQ3XRkzFBmF714BBhP14V8t9HU/DDYNDdEhBc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SXtVyLRF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SXtVyLRF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99F56C4CEF7; Thu, 11 Dec 2025 10:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765449849; bh=AW/I4n2Zznh3mDRmErapu5OH/Tja5kRysX9LI6GHSSM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SXtVyLRFXLgpEWU+aax8xuITVDHdmrMq+nnthPMygNMw5SkAnUEj6yknaLr4eWU3f 6eFi4lDk28GP9T46f4tUYnCS7/MoJp9AOPZayUCFHJc/RDkimACUxwqXl2Kx0UEub3 wPvDrZ3rddz9+9Cc7N36icqNi117vRnZ1aew/G1A3D1ipWNu62Jc0XwLVoZDwVulog Z1C5glIzpBNfTlRotN0Nd+vnZqwUV7633bgj7S+uChyIWfpOnPjAlnEcaifU3k4s0d 4L7rpMWLyJ7ubUoXq5olYCWQA5BQkHKRiB8DLYM3OUmLDN1tlY/DyMFg6xwXntnF/A gqG3ttEBz+EaQ== Date: Thu, 11 Dec 2025 11:44:04 +0100 From: Alejandro Colomar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Alejandro Colomar , Kees Cook , Christopher Bazley , Rasmus Villemoes , Marco Elver , Michal Hocko , Linus Torvalds , Al Viro , Alexander Potapenko , Dmitry Vyukov , Jann Horn , Andrew Morton , "Maciej W. Rozycki" Subject: [PATCH v6 4/4] mm: Use ARRAY_END() instead of open-coding it Message-ID: <2335917d123891fec074ab1b3acfb517cf14b5a7.1765449750.git.alx@kernel.org> X-Mailer: git-send-email 2.51.0 References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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. Cc: Kees Cook Cc: Linus Torvalds Signed-off-by: Alejandro Colomar --- mm/kmemleak.c | 2 +- mm/memcontrol-v1.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 1ac56ceb29b6..fe33f2edfe07 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -510,7 +510,7 @@ static void mem_pool_free(struct kmemleak_object *objec= t) { unsigned long flags; =20 - if (object < mem_pool || object >=3D mem_pool + ARRAY_SIZE(mem_pool)) { + if (object < mem_pool || object >=3D ARRAY_END(mem_pool)) { kmem_cache_free(object_cache, object); return; } diff --git a/mm/memcontrol-v1.c b/mm/memcontrol-v1.c index 6eed14bff742..b2f37bd939fa 100644 --- a/mm/memcontrol-v1.c +++ b/mm/memcontrol-v1.c @@ -1794,7 +1794,7 @@ static int memcg_numa_stat_show(struct seq_file *m, v= oid *v) =20 mem_cgroup_flush_stats(memcg); =20 - for (stat =3D stats; stat < stats + ARRAY_SIZE(stats); stat++) { + for (stat =3D stats; stat < ARRAY_END(stats); stat++) { seq_printf(m, "%s=3D%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, v= oid *v) seq_putc(m, '\n'); } =20 - for (stat =3D stats; stat < stats + ARRAY_SIZE(stats); stat++) { + for (stat =3D stats; stat < ARRAY_END(stats); stat++) { =20 seq_printf(m, "hierarchical_%s=3D%lu", stat->name, mem_cgroup_nr_lru_pages(memcg, stat->lru_mask, --=20 2.51.0