Re: [PATCH] panic: Add __maybe_unused to sys_info_avail
From: Feng Tang
Date: Tue Jul 08 2025 - 21:24:35 EST
On Tue, Jul 08, 2025 at 08:37:57AM -0700, Nathan Chancellor wrote:
> Clang warns (or errors with CONFIG_WERROR=y):
>
> lib/sys_info.c:52:19: error: variable 'sys_info_avail' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration]
> 52 | static const char sys_info_avail[] = "tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks";
> | ^~~~~~~~~~~~~~
>
> sys_info_avail is only used within sizeof(), meaning it is only used at
> compile time, which clang warns about in case the developer intended to
> use the variable elsewhere. This appears to be intentional in this case,
> so mark sys_info_avail with __maybe_unused to silence the warning.
>
> Signed-off-by: Nathan Chancellor <nathan@xxxxxxxxxx>
> ---
> This should be squashed into
> panic-add-panic_sys_info-sysctl-to-take-human-readable-string-parameter.patch
> so I did not bother with a fixes tag.
Looks good to me. Thanks for the fix!
- Feng
> ---
> lib/sys_info.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/sys_info.c b/lib/sys_info.c
> index 46d6f4f1ad2a..5bf503fd7ec1 100644
> --- a/lib/sys_info.c
> +++ b/lib/sys_info.c
> @@ -49,7 +49,7 @@ unsigned long sys_info_parse_param(char *str)
>
> #ifdef CONFIG_SYSCTL
>
> -static const char sys_info_avail[] = "tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks";
> +static const char sys_info_avail[] __maybe_unused = "tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks";
>
> int sysctl_sys_info_handler(const struct ctl_table *ro_table, int write,
> void *buffer, size_t *lenp,
>
> ---
> base-commit: 10f2351db2799f80af91da7aee4c60fd042bfcf3
> change-id: 20250708-fix-clang-sys_info_avail-warning-fa19cdd77b71
>
> Best regards,
> --
> Nathan Chancellor <nathan@xxxxxxxxxx>