Skip to content

Commit 545c272

Browse files
committed
alpha: Silence -Warray-bounds warnings
GCC 11 (incorrectly[1]) assumes that literal values cast to (void *) should be treated like a NULL pointer with an offset, and raises diagnostics when doing bounds checking: In function '__memset', inlined from '__bad_pagetable' at arch/alpha/mm/init.c:79:2: ./arch/alpha/include/asm/string.h:37:32: error: '__builtin_memset' offset [0, 8191] is out of the bounds [0, 0] [-Werror=array-bounds] 37 | return __builtin_memset(s, c, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~ In function '__memset', inlined from '__bad_page' at arch/alpha/mm/init.c:86:2: ./arch/alpha/include/asm/string.h:37:32: error: '__builtin_memset' offset [0, 8191] is out of the bounds [0, 0] [-Werror=array-bounds] 37 | return __builtin_memset(s, c, n); | ^~~~~~~~~~~~~~~~~~~~~~~~~ In function '__memset', inlined from 'paging_init' at arch/alpha/mm/init.c:256:2: ./arch/alpha/include/asm/string.h:37:32: error: '__builtin_memset' offset [0, 8191] is out of the bounds [0, 0] [-Werror=array-bounds] 37 | return __builtin_memset(s, c, n); This has been solved in other places[2] already by using the recently added absolute_pointer() macro. Do the same here. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578 [2] https://lore.kernel.org/all/20210912160149.2227137-1-linux@roeck-us.net/ Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Matt Turner <mattst88@gmail.com> Cc: Guenter Roeck <linux@roeck-us.net> Cc: linux-alpha@vger.kernel.org Reviewed-and-tested-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Kees Cook <keescook@chromium.org>
1 parent 2a55550 commit 545c272

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

arch/alpha/mm/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ pgd_alloc(struct mm_struct *mm)
7676
pmd_t *
7777
__bad_pagetable(void)
7878
{
79-
memset((void *) EMPTY_PGT, 0, PAGE_SIZE);
79+
memset(absolute_pointer(EMPTY_PGT), 0, PAGE_SIZE);
8080
return (pmd_t *) EMPTY_PGT;
8181
}
8282

8383
pte_t
8484
__bad_page(void)
8585
{
86-
memset((void *) EMPTY_PGE, 0, PAGE_SIZE);
86+
memset(absolute_pointer(EMPTY_PGE), 0, PAGE_SIZE);
8787
return pte_mkdirty(mk_pte(virt_to_page(EMPTY_PGE), PAGE_SHARED));
8888
}
8989

@@ -253,7 +253,7 @@ void __init paging_init(void)
253253
free_area_init(max_zone_pfn);
254254

255255
/* Initialize the kernel's ZERO_PGE. */
256-
memset((void *)ZERO_PGE, 0, PAGE_SIZE);
256+
memset(absolute_pointer(ZERO_PGE), 0, PAGE_SIZE);
257257
}
258258

259259
#if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)

0 commit comments

Comments
 (0)