Message ID | 20230810141947.1236730-16-arnd@kernel.org |
---|---|
State | New |
Headers | show |
Series | -Wmissing-prototype warning fixes | expand |
On Sat, Aug 12, 2023 at 3:30 AM Arnd Bergmann <arnd@kernel.org> wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > When -Wmissing-prototypes is enabled, the some asm-offsets.c files fail > to build, even when this warning is disabled in the Makefile for normal > files: > > arch/sparc/kernel/asm-offsets.c:22:5: error: no previous prototype for 'sparc32_foo' [-Werror=missing-prototypes] > arch/sparc/kernel/asm-offsets.c:48:5: error: no previous prototype for 'foo' [-Werror=missing-prototypes] > > Address this by making use of the same trick we have on other architectures, > renaming the unused global function to main(), which has an implicit > prototype. main() only works for one function call, but there are some cases where splitting the code into some functions makes the code cleaner. > On loongarch, there are many functions in this file, so the trick does > not work, adding explicit declarations works around it in a slightly > more ugly way but is the best I could come up with here. I do not like repeating the function names. Could you try "static + __used" as in arch/x86/kernel/asm-offsets.c ? -- Best Regards Masahiro Yamada
On Sat, Aug 12, 2023, at 00:12, Masahiro Yamada wrote: > On Sat, Aug 12, 2023 at 3:30 AM Arnd Bergmann <arnd@kernel.org> wrote: >> >> From: Arnd Bergmann <arnd@arndb.de> >> >> When -Wmissing-prototypes is enabled, the some asm-offsets.c files fail >> to build, even when this warning is disabled in the Makefile for normal >> files: >> >> arch/sparc/kernel/asm-offsets.c:22:5: error: no previous prototype for 'sparc32_foo' [-Werror=missing-prototypes] >> arch/sparc/kernel/asm-offsets.c:48:5: error: no previous prototype for 'foo' [-Werror=missing-prototypes] >> >> Address this by making use of the same trick we have on other architectures, >> renaming the unused global function to main(), which has an implicit >> prototype. > > > main() only works for one function call, but > there are some cases where splitting the code > into some functions makes the code cleaner. Right, I went with main() as that is already used on a couple of architectures. >> On loongarch, there are many functions in this file, so the trick does >> not work, adding explicit declarations works around it in a slightly >> more ugly way but is the best I could come up with here. > > I do not like repeating the function names. > > Could you try "static + __used" as in > arch/x86/kernel/asm-offsets.c ? Sure, that should work, I had not noticed x86 doing it like this and I agree it's slightly nicer. In this case, Thomas Bogendoerfer already merged my patch for MIPS in 6.5. The loongarch file I change here is a copy of the same file, so we probably want them to stay consistent, either keeping my change for now, or reworking mips along the same lines. Arnd
diff --git a/arch/alpha/kernel/asm-offsets.c b/arch/alpha/kernel/asm-offsets.c index b121294bee266..b87487e70488d 100644 --- a/arch/alpha/kernel/asm-offsets.c +++ b/arch/alpha/kernel/asm-offsets.c @@ -12,7 +12,7 @@ #include <linux/kbuild.h> #include <asm/io.h> -void foo(void) +int main(void) { DEFINE(TI_TASK, offsetof(struct thread_info, task)); DEFINE(TI_FLAGS, offsetof(struct thread_info, flags)); diff --git a/arch/ia64/kernel/asm-offsets.c b/arch/ia64/kernel/asm-offsets.c index be3b90fef2e92..62b9aaf10b3c0 100644 --- a/arch/ia64/kernel/asm-offsets.c +++ b/arch/ia64/kernel/asm-offsets.c @@ -20,7 +20,7 @@ #include "../kernel/sigframe.h" #include "../kernel/fsyscall_gtod_data.h" -void foo(void) +int main(void) { DEFINE(IA64_TASK_SIZE, sizeof (struct task_struct)); DEFINE(IA64_THREAD_INFO_SIZE, sizeof (struct thread_info)); diff --git a/arch/loongarch/kernel/asm-offsets.c b/arch/loongarch/kernel/asm-offsets.c index 8da0726777edb..735115f8341c9 100644 --- a/arch/loongarch/kernel/asm-offsets.c +++ b/arch/loongarch/kernel/asm-offsets.c @@ -14,6 +14,7 @@ #include <asm/processor.h> #include <asm/ftrace.h> +void output_ptreg_defines(void); void output_ptreg_defines(void) { COMMENT("LoongArch pt_regs offsets."); @@ -61,6 +62,7 @@ void output_ptreg_defines(void) BLANK(); } +void output_task_defines(void); void output_task_defines(void) { COMMENT("LoongArch task_struct offsets."); @@ -76,6 +78,7 @@ void output_task_defines(void) BLANK(); } +void output_thread_info_defines(void); void output_thread_info_defines(void) { COMMENT("LoongArch thread_info offsets."); @@ -92,6 +95,7 @@ void output_thread_info_defines(void) BLANK(); } +void output_thread_defines(void); void output_thread_defines(void) { COMMENT("LoongArch specific thread_struct offsets."); @@ -128,6 +132,7 @@ void output_thread_defines(void) BLANK(); } +void output_thread_fpu_defines(void); void output_thread_fpu_defines(void) { OFFSET(THREAD_FPR0, loongarch_fpu, fpr[0]); @@ -169,6 +174,7 @@ void output_thread_fpu_defines(void) BLANK(); } +void output_thread_lbt_defines(void); void output_thread_lbt_defines(void) { OFFSET(THREAD_SCR0, loongarch_lbt, scr0); @@ -179,6 +185,7 @@ void output_thread_lbt_defines(void) BLANK(); } +void output_mm_defines(void); void output_mm_defines(void) { COMMENT("Size of struct page"); @@ -211,6 +218,7 @@ void output_mm_defines(void) BLANK(); } +void output_sc_defines(void); void output_sc_defines(void) { COMMENT("Linux sigcontext offsets."); @@ -219,6 +227,7 @@ void output_sc_defines(void) BLANK(); } +void output_signal_defines(void); void output_signal_defines(void) { COMMENT("Linux signal numbers."); @@ -257,6 +266,7 @@ void output_signal_defines(void) } #ifdef CONFIG_SMP +void output_smpboot_defines(void); void output_smpboot_defines(void) { COMMENT("Linux smp cpu boot offsets."); @@ -267,6 +277,7 @@ void output_smpboot_defines(void) #endif #ifdef CONFIG_HIBERNATION +void output_pbe_defines(void); void output_pbe_defines(void) { COMMENT("Linux struct pbe offsets."); @@ -279,6 +290,7 @@ void output_pbe_defines(void) #endif #ifdef CONFIG_FUNCTION_GRAPH_TRACER +void output_fgraph_ret_regs_defines(void); void output_fgraph_ret_regs_defines(void) { COMMENT("LoongArch fgraph_ret_regs offsets."); diff --git a/arch/sparc/kernel/asm-offsets.c b/arch/sparc/kernel/asm-offsets.c index 5784f2df489a4..4c8c9a6df2aa5 100644 --- a/arch/sparc/kernel/asm-offsets.c +++ b/arch/sparc/kernel/asm-offsets.c @@ -18,16 +18,12 @@ #include <asm/hibernate.h> -#ifdef CONFIG_SPARC32 -int sparc32_foo(void) +int main(void) { +#ifdef CONFIG_SPARC32 DEFINE(AOFF_thread_fork_kpsr, offsetof(struct thread_struct, fork_kpsr)); - return 0; -} #else -int sparc64_foo(void) -{ #ifdef CONFIG_HIBERNATION BLANK(); OFFSET(SC_REG_FP, saved_context, fp); @@ -41,12 +37,7 @@ int sparc64_foo(void) OFFSET(SC_REG_G5, saved_context, g5); OFFSET(SC_REG_G6, saved_context, g6); #endif - return 0; -} #endif - -int foo(void) -{ BLANK(); DEFINE(AOFF_task_thread, offsetof(struct task_struct, thread)); BLANK();