mm/sparse: guard the size of mem_section is power of 2
authorWei Yang <richard.weiyang@gmail.com>
Tue, 16 Apr 2024 01:25:59 +0000 (01:25 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Mon, 6 May 2024 00:53:40 +0000 (17:53 -0700)
We usually have this check, while commit 2a3cb8baef71 ("mm/sparse: delete
old sparse_init and enable new one") missed to take it.

Link: https://lkml.kernel.org/r/20240416012559.4536-1-richard.weiyang@gmail.com
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
Acked-by: Oscar Salvador <osalvador@suse.de>
Reviewed-by: Pasha Tatashin <pasha.tatashin@soleen.com>
Cc: "Mike Rapoport (IBM)" <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/sparse.c

index 46e88549d1a6a9b62d67755e5c61bd288d27fa80..de40b2c7340673ca7505ebccc1c7ab05303dd771 100644 (file)
@@ -560,6 +560,8 @@ void __init sparse_init(void)
        unsigned long pnum_end, pnum_begin, map_count = 1;
        int nid_begin;
 
+       /* see include/linux/mmzone.h 'struct mem_section' definition */
+       BUILD_BUG_ON(!is_power_of_2(sizeof(struct mem_section)));
        memblocks_present();
 
        pnum_begin = first_present_section_nr();