diff mbox

[v3] module: LLVMLinux: Remove unused function warning from __param_check macro

Message ID 1394573091-4705-1-git-send-email-behanw@converseincode.com
State New
Headers show

Commit Message

Behan Webster March 11, 2014, 9:24 p.m. UTC
From: Mark Charlebois <charlebm@gmail.com>

This code makes a compile time type check that is optimized away. Clang
complains that it generates an unused function:

linux/kernel/panic.c:471:1: warning: unused function '__check_panic'
      [-Wunused-function]
core_param(panic, panic_timeout, int, 0644);
^
linux/moduleparam.h:283:2: note: expanded from macro
      'core_param'
        param_check_##type(name, &(var));                               \
        ^
<scratch space>:87:1: note: expanded from here
param_check_int
^
linux/moduleparam.h:369:34: note: expanded from macro
      'param_check_int'
#define param_check_int(name, p) __param_check(name, p, int)
                                 ^
linux/moduleparam.h:349:22: note: expanded from macro
      '__param_check'
        static inline type *__check_##name(void) { return(p); }
                            ^
<scratch space>:88:1: note: expanded from here
__check_panic

GCC won't complain for a static inline function but would if it was just
a static function.

Adding the unused attribute to the function declaration removes the warning.
Per request from Rusty Russell it is marked as __always_unused as the code
is meant to be optimized away.

This code works for both GCC and clang.

Signed-off-by: Mark Charlebois <charlebm@gmail.com>
Signed-off-by: Behan Webster <behanw@converseincode.com>
---
 include/linux/moduleparam.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Rusty Russell March 17, 2014, 2:47 a.m. UTC | #1
behanw@converseincode.com writes:
> From: Mark Charlebois <charlebm@gmail.com>
>
> This code makes a compile time type check that is optimized away. Clang
> complains that it generates an unused function:

Thanks, applied.

Cheers,
Rusty.

>
> linux/kernel/panic.c:471:1: warning: unused function '__check_panic'
>       [-Wunused-function]
> core_param(panic, panic_timeout, int, 0644);
> ^
> linux/moduleparam.h:283:2: note: expanded from macro
>       'core_param'
>         param_check_##type(name, &(var));                               \
>         ^
> <scratch space>:87:1: note: expanded from here
> param_check_int
> ^
> linux/moduleparam.h:369:34: note: expanded from macro
>       'param_check_int'
> #define param_check_int(name, p) __param_check(name, p, int)
>                                  ^
> linux/moduleparam.h:349:22: note: expanded from macro
>       '__param_check'
>         static inline type *__check_##name(void) { return(p); }
>                             ^
> <scratch space>:88:1: note: expanded from here
> __check_panic
>
> GCC won't complain for a static inline function but would if it was just
> a static function.
>
> Adding the unused attribute to the function declaration removes the warning.
> Per request from Rusty Russell it is marked as __always_unused as the code
> is meant to be optimized away.
>
> This code works for both GCC and clang.
>
> Signed-off-by: Mark Charlebois <charlebm@gmail.com>
> Signed-off-by: Behan Webster <behanw@converseincode.com>
> ---
>  include/linux/moduleparam.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
> index c3eb102..175f699 100644
> --- a/include/linux/moduleparam.h
> +++ b/include/linux/moduleparam.h
> @@ -346,7 +346,7 @@ static inline void destroy_params(const struct kernel_param *params,
>  /* The macros to do compile-time type checking stolen from Jakub
>     Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
>  #define __param_check(name, p, type) \
> -	static inline type *__check_##name(void) { return(p); }
> +	static inline type __always_unused *__check_##name(void) { return(p); }
>  
>  extern struct kernel_param_ops param_ops_byte;
>  extern int param_set_byte(const char *val, const struct kernel_param *kp);
> -- 
> 1.8.3.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index c3eb102..175f699 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -346,7 +346,7 @@  static inline void destroy_params(const struct kernel_param *params,
 /* The macros to do compile-time type checking stolen from Jakub
    Jelinek, who IIRC came up with this idea for the 2.4 module init code. */
 #define __param_check(name, p, type) \
-	static inline type *__check_##name(void) { return(p); }
+	static inline type __always_unused *__check_##name(void) { return(p); }
 
 extern struct kernel_param_ops param_ops_byte;
 extern int param_set_byte(const char *val, const struct kernel_param *kp);