Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sh: machvec: Use char[] for section boundaries

As done for other sections, define the extern as a character array,
which relaxes many of the compiler-time object size checks, which would
otherwise assume it's a single long. Solves the following build error:

arch/sh/kernel/machvec.c: error: array subscript 'struct sh_machine_vector[0]' is partly outside array bounds of 'long int[1]' [-Werror=array-bounds]: => 105:33

Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: linux-sh@vger.kernel.org
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Link: https://lore.kernel.org/lkml/alpine.DEB.2.22.394.2209050944290.964530@ramsan.of.borg/
Fixes: 9655ad03af2d ("sh: Fixup machvec support.")
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Acked-by: Rich Felker <dalias@libc.org>
Signed-off-by: Kees Cook <keescook@chromium.org>

+6 -6
+1 -1
arch/sh/include/asm/sections.h
··· 4 4 5 5 #include <asm-generic/sections.h> 6 6 7 - extern long __machvec_start, __machvec_end; 7 + extern char __machvec_start[], __machvec_end[]; 8 8 extern char __uncached_start, __uncached_end; 9 9 extern char __start_eh_frame[], __stop_eh_frame[]; 10 10
+5 -5
arch/sh/kernel/machvec.c
··· 20 20 #define MV_NAME_SIZE 32 21 21 22 22 #define for_each_mv(mv) \ 23 - for ((mv) = (struct sh_machine_vector *)&__machvec_start; \ 24 - (mv) && (unsigned long)(mv) < (unsigned long)&__machvec_end; \ 23 + for ((mv) = (struct sh_machine_vector *)__machvec_start; \ 24 + (mv) && (unsigned long)(mv) < (unsigned long)__machvec_end; \ 25 25 (mv)++) 26 26 27 27 static struct sh_machine_vector * __init get_mv_byname(const char *name) ··· 87 87 if (!machvec_selected) { 88 88 unsigned long machvec_size; 89 89 90 - machvec_size = ((unsigned long)&__machvec_end - 91 - (unsigned long)&__machvec_start); 90 + machvec_size = ((unsigned long)__machvec_end - 91 + (unsigned long)__machvec_start); 92 92 93 93 /* 94 94 * Sanity check for machvec section alignment. Ensure ··· 102 102 * vector (usually the only one) from .machvec.init. 103 103 */ 104 104 if (machvec_size >= sizeof(struct sh_machine_vector)) 105 - sh_mv = *(struct sh_machine_vector *)&__machvec_start; 105 + sh_mv = *(struct sh_machine_vector *)__machvec_start; 106 106 } 107 107 108 108 pr_notice("Booting machvec: %s\n", get_system_type());