Skip to contentSkip to conversation

modules: mark __inittest/__exittest as __maybe_unused

PATCH Applied Arnd Bergmann 4 participants 6 messages Feb 1, 2017 – Feb 7, 2017 Module support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 modules: mark __inittest/__exittest as __maybe_unused

clang warns about unused inline functions by default:

arch/arm/crypto/aes-cipher-glue.c:68:1: warning: unused function '__inittest' [-Wunused-function] arch/arm/crypto/aes-cipher-glue.c:69:1: warning: unused function '__exittest' [-Wunused-function]

As these appear in every single module, let's just disable the warnings by marking the two functions as __maybe_unused.

---
 include/linux/module.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/module.h +2 -2
index 38b4b2c754c8..48a5c57c858e 100644
@@ -126,13 +126,13 @@ extern void cleanup_module(void);
 
 /* Each module must use one module_init(). */
 #define module_init(initfn)					\
-	static inline initcall_t __inittest(void)		\
+	static inline initcall_t __maybe_unused __inittest(void)		\
 	{ return initfn; }					\
 	int init_module(void) __attribute__((alias(#initfn)));
 
 /* This is only required if you want to be unloadable. */
 #define module_exit(exitfn)					\
-	static inline exitcall_t __exittest(void)		\
+	static inline exitcall_t __maybe_unused __exittest(void)		\
 	{ return exitfn; }					\
 	void cleanup_module(void) __attribute__((alias(#exitfn)));
 
Signature · 1 line
2.9.0
#1 lore raw
Quoted 7 lines · Arnd Bergmann

clang warns about unused inline functions by default:

arch/arm/crypto/aes-cipher-glue.c:68:1: warning: unused function '__inittest' [-Wunused-function] arch/arm/crypto/aes-cipher-glue.c:69:1: warning: unused function '__exittest' [-Wunused-function]

As these appear in every single module, let's just disable the warnings by marking the two functions as __maybe_unused.

Um, won't you have to do that to hundreds of kernel headers? Why module.h?

Confused,
Rusty.

Quoted 27 lines
---
 include/linux/module.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/module.h +2 -2
index 38b4b2c754c8..48a5c57c858e 100644
@@ -126,13 +126,13 @@ extern void cleanup_module(void);
 
 /* Each module must use one module_init(). */
 #define module_init(initfn)					\
-	static inline initcall_t __inittest(void)		\
+	static inline initcall_t __maybe_unused __inittest(void)		\
 	{ return initfn; }					\
 	int init_module(void) __attribute__((alias(#initfn)));
 
 /* This is only required if you want to be unloadable. */
 #define module_exit(exitfn)					\
-	static inline exitcall_t __exittest(void)		\
+	static inline exitcall_t __maybe_unused __exittest(void)		\
 	{ return exitfn; }					\
 	void cleanup_module(void) __attribute__((alias(#exitfn)));
 
Signature · 1 line
2.9.0
#2 lore raw
Quoted 11 lines · Rusty Russell
Quoted 7 lines · Arnd Bergmann

clang warns about unused inline functions by default:

arch/arm/crypto/aes-cipher-glue.c:68:1: warning: unused function '__inittest' [-Wunused-function] arch/arm/crypto/aes-cipher-glue.c:69:1: warning: unused function '__exittest' [-Wunused-function]

As these appear in every single module, let's just disable the warnings by marking the two functions as __maybe_unused.

Um, won't you have to do that to hundreds of kernel headers? Why module.h?

clang specifically warns about inline functions that are defined in a .c file but not used
there, but it is sensible enough to not warn about unused inline functions that are defined
in a header.

In an ARM allmodconfig build, I currently see 178 .c files[1] that have unused inline functions.
The proper way to deal with them is probably to move the warning into the "make W=1"
level to hide it by default and then do one driver at a time.

The module.h definitions are special because the inline function is defined through a
macro that gets evaluated by almost every loadable module, and we get a warning for
every one of them, which the subsystem maintainers cannot deal with by changing their
code locally.

Arnd

[1] http://pastebin.com/pnHvbHQ3

Acked-by
#3 lore raw
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Rusty Russell
Quoted 7 lines · Arnd Bergmann

clang warns about unused inline functions by default:

arch/arm/crypto/aes-cipher-glue.c:68:1: warning: unused function '__inittest' [-Wunused-function] arch/arm/crypto/aes-cipher-glue.c:69:1: warning: unused function '__exittest' [-Wunused-function]

As these appear in every single module, let's just disable the warnings by marking the two functions as __maybe_unused.

Quoted 8 lines
Quoted 2 lines

Um, won't you have to do that to hundreds of kernel headers? Why module.h?

clang specifically warns about inline functions that are defined in a .c file but not used
there, but it is sensible enough to not warn about unused inline functions that are defined
in a header.

Ah, I was confused because you patched the header :)

Quoted 7 lines

The module.h definitions are special because the inline function is defined through a
macro that gets evaluated by almost every loadable module, and we get a warning for
every one of them, which the subsystem maintainers cannot deal with by changing their
code locally.

Thanks,
Rusty.

Reviewed-by on v1 1/1
#4 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

clang warns about unused inline functions by default:

arch/arm/crypto/aes-cipher-glue.c:68:1: warning: unused function '__inittest' [-Wunused-function] arch/arm/crypto/aes-cipher-glue.c:69:1: warning: unused function '__exittest' [-Wunused-function]

As these appear in every single module, let's just disable the warnings by marking the two functions as __maybe_unused.

Makes sense.

Regards,
Miroslav

Applied
#5 lore raw
In reply to Arnd Bergmann

+++ Arnd Bergmann [01/02/17 18:00 +0100]:

Quoted 9 lines

clang warns about unused inline functions by default:

arch/arm/crypto/aes-cipher-glue.c:68:1: warning: unused function '__inittest' [-Wunused-function] arch/arm/crypto/aes-cipher-glue.c:69:1: warning: unused function '__exittest' [-Wunused-function]

As these appear in every single module, let's just disable the warnings by marking the two functions as __maybe_unused.

Applied, thanks.

Jessica