panic: Fix compilation error (`make W=1`)
PATCH 1/1 panic: Fix compilation error (`make W=1`)
Compiler is not happy about the recently added code:
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";
| ^~~~~~~~~~~~~~Fix it in the same way how, for example, lib/vsprintf.c does in the similar cases, i.e. by using string literal directly as sizeof() parameter.
--- lib/sys_info.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
lib/sys_info.c +1 -3
@@ -49,13 +49,11 @@ 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" ; -int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write,void *buffer,size_t *lenp,loff_t *ppos) { -char names[sizeof (sys_info_avail) +1 ]; +char names[sizeof ("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks" ) +1 ];struct ctl_table table;unsigned long *si_bits_global;
Signature · 1 line
2.47.2
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 16 lines · Andy Shevchenko
I don't understand why this mail was sent with LKML being dropped...
Quoted 13 lines · Feng Tang
Quoted 11 lines · Andy Shevchenko
Compiler is not happy about the recently added code:
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"; | ^~~~~~~~~~~~~~Fix it in the same way how, for example,
lib/vsprintf.cdoes in the similar cases, i.e. by using string literal directly assizeof()parameter.Fixes 9b5072c04c46 ("panic: add 'panic_sys_info' sysctl to take human readable string parameter")Signed-off-by Andy Shevchenko <[email protected]>
Quoted 8 lines
Quoted 4 lines
Thanks for the fix! The issue has been reported, and the linux-mm tree already carried fix:
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git/commit/?h=mm-nonmm-unstable&id=0a080b90dc6fe0a1e7df954a0d8c7e486e83b189which doesn't hit linux-next tree yet.
With all the respect to Nathan's fix, I prefer mine for a couple of reasons:
1)__maybe_unusedis a linker time workaorund;
2) we still have unneeded variable dangling;
Should be...
"With my patch:"
Quoted 1 line
3) less code to maintain;
1) ...
Quoted 1 line
4)
vsprintf.chas many similar cases and there the approach is different.
2) ...
Quoted 3 lines
Note, the fix is still in unstable branch, hence can be pulled out.
Andrew, Nathan, what's your opinion?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Andrew Morton
maintainerQuoted 19 lines · On Thu, 10 Jul 2025 12:48:16 +0300 Andy Shevchenko…
Compiler is not happy about the recently added code:
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"; | ^~~~~~~~~~~~~~Fix it in the same way how, for example,
lib/vsprintf.cdoes in the similar cases, i.e. by using string literal directly assizeof()parameter....
lib/sys_info.c +0
-1@@ -49,13 +49,11 @@ 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" ;
lib/sys_info.c unsigned long sys_info_parse_param(char *str) · line 59
Quoted 10 lines
lib/sys_info.c +1
-2-int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write,void *buffer,size_t *lenp,loff_t *ppos) { -char names[sizeof (sys_info_avail) +1 ]; +char names[sizeof ("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks" ) +1 ];struct ctl_table table;unsigned long *si_bits_global;
Yes, that's neater than the fix we currently have. I'll grab, thanks.
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Thu, 10 Jul 2025 12:48:16 +0300 Andy Shevchenko…
Compiler is not happy about the recently added code:
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"; | ^~~~~~~~~~~~~~Fix it in the same way how, for example,
lib/vsprintf.cdoes in the similar cases, i.e. by using string literal directly assizeof()parameter....
lib/sys_info.c +0
-0@@ -49,13 +49,11 @@ unsigned long sys_info_parse_param(char *str)#ifdef CONFIG_SYSCTL
Quoted 13 lines
lib/sys_info.c unsigned long sys_info_parse_param(char *str) · line 59
Quoted 11 lines
lib/sys_info.c +1
-3-static const char sys_info_avail[] ="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,loff_t *ppos) { -char names[sizeof (sys_info_avail) +1 ]; +char names[sizeof ("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks" ) +1 ];struct ctl_table table;unsigned long *si_bits_global;Yes, that's neater than the fix we currently have. I'll grab, thanks.
Hi Andrew, Andy,
sys_info_avail[] has another purpose for being a counterpart of si_names[], which could be extended in future, so we make it obviously stand-alone. As for definition of si_names[], we explicitly added comment:
/*
* When 'si_names' gets updated, please make sure the 'sys_info_avail'
* below is updated accordingly.
*/
static const struct sys_info_name si_names[] = {
{ SYS_INFO_TASKS, "tasks" },
{ SYS_INFO_MEM, "mem" },which has also been discussed in another thread:
https://lore.kernel.org/lkml/[email protected]/
And I suggest to keep sys_info_avail[], and either Nathan or Sergey's patch works for me.
Sorry for the inconvenience, and I should upgrade my gcc :)
Thanks,
Feng
Quoted 49 lines · Feng Tang
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Thu, 10 Jul 2025 12:48:16 +0300 Andy Shevchenko…
Compiler is not happy about the recently added code:
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"; | ^~~~~~~~~~~~~~Fix it in the same way how, for example,
lib/vsprintf.cdoes in the similar cases, i.e. by using string literal directly assizeof()parameter....
lib/sys_info.c +0
-0@@ -49,13 +49,11 @@ unsigned long sys_info_parse_param(char *str)#ifdef CONFIG_SYSCTL Quoted 13 lines
lib/sys_info.c unsigned long sys_info_parse_param(char *str) · line 59
Quoted 11 lines
lib/sys_info.c +1
-3-static const char sys_info_avail[] ="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,loff_t *ppos) { -char names[sizeof (sys_info_avail) +1 ]; +char names[sizeof ("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks" ) +1 ];struct ctl_table table;unsigned long *si_bits_global;Yes, that's neater than the fix we currently have. I'll grab, thanks.
Hi Andrew, Andy,
sys_info_avail[] has another purpose for being a counterpart of si_names[], which could be extended in future, so we make it obviously stand-alone. As for definition of si_names[], we explicitly added comment:
/* * When 'si_names' gets updated, please make sure the 'sys_info_avail' * below is updated accordingly. */ static const struct sys_info_name si_names[] = { { SYS_INFO_TASKS, "tasks" }, { SYS_INFO_MEM, "mem" },
Quoted 5 lines
which has also been discussed in another thread:
https://lore.kernel.org/lkml/[email protected]/And I suggest to keep sys_info_avail[], and either Nathan or Sergey's patch works for me.
We could do something like this to keep the sizeof() obvious and separate, while still eliminating the variable? Happy to bike shed aspects of it like the macro name and such.
lib/sys_info.c +3 -3
@@ -14,7 +14,7 @@ struct sys_info_name { };/* -* When 'si_names' gets updated, please make sure the 'sys_info_avail' +* When 'si_names' gets updated, please make sure SYS_INFO_MAX_LEN * below is updated accordingly. */ static const struct sys_info_name si_names[] = {
@@ -49,13 +49,13 @@ 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" ; +#define SYS_INFO_MAX_LEN (sizeof("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks") + 1)int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write,void *buffer,size_t *lenp,loff_t *ppos) { -char names[sizeof (sys_info_avail) +1 ]; +char names[SYS_INFO_MAX_LEN ];struct ctl_table table;unsigned long *si_bits_global;
---
Quoted 1 line
Sorry for the inconvenience, and I should upgrade my gcc :)
I am not sure that GCC has this warning, I have only ever seen it with clang.
Cheers,
Nathan
Quoted 78 lines · Nathan Chancellor
Quoted 49 lines · Feng Tang
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Thu, 10 Jul 2025 12:48:16 +0300 Andy Shevchenko…
Compiler is not happy about the recently added code:
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"; | ^~~~~~~~~~~~~~Fix it in the same way how, for example,
lib/vsprintf.cdoes in the similar cases, i.e. by using string literal directly assizeof()parameter....
lib/sys_info.c +0
-0@@ -49,13 +49,11 @@ unsigned long sys_info_parse_param(char *str)#ifdef CONFIG_SYSCTL Quoted 13 lines
lib/sys_info.c unsigned long sys_info_parse_param(char *str) · line 61
Quoted 11 lines
lib/sys_info.c +1
-3-static const char sys_info_avail[] ="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,loff_t *ppos) { -char names[sizeof (sys_info_avail) +1 ]; +char names[sizeof ("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks" ) +1 ];struct ctl_table table;unsigned long *si_bits_global;Yes, that's neater than the fix we currently have. I'll grab, thanks.
Hi Andrew, Andy,
sys_info_avail[] has another purpose for being a counterpart of si_names[], which could be extended in future, so we make it obviously stand-alone. As for definition of si_names[], we explicitly added comment:
/* * When 'si_names' gets updated, please make sure the 'sys_info_avail' * below is updated accordingly. */ static const struct sys_info_name si_names[] = { { SYS_INFO_TASKS, "tasks" }, { SYS_INFO_MEM, "mem" },Quoted 5 lines
which has also been discussed in another thread:
https://lore.kernel.org/lkml/[email protected]/And I suggest to keep sys_info_avail[], and either Nathan or Sergey's patch works for me.
We could do something like this to keep the
sizeof()obvious and separate, while still eliminating the variable? Happy to bike shed aspects of it like the macro name and such.lib/sys_info.c +1
-2@@ -14,7 +14,7 @@ struct sys_info_name { };/* -* When 'si_names' gets updated, please make sure the 'sys_info_avail' +* When 'si_names' gets updated, please make sure SYS_INFO_MAX_LEN * below is updated accordingly. */ static const struct sys_info_name si_names[] = {@@ -49,13 +49,13 @@ 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" ;
lib/sys_info.c unsigned long sys_info_parse_param(char *str) · line 60
Quoted 10 lines
lib/sys_info.c +2
-1+#define SYS_INFO_MAX_LEN (sizeof("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks") + 1)int sysctl_sys_info_handler (const struct ctl_table *ro_table,int write,void *buffer,size_t *lenp,loff_t *ppos) { -char names[sizeof (sys_info_avail) +1 ]; +char names[SYS_INFO_MAX_LEN ];struct ctl_table table;unsigned long *si_bits_global;
Looks great to me, thanks!
We can even move the SYS_INFO_MAX_LEN definition close to si_names[], initially sys_info_avail[] was next to si_names[], and was moved inside "#ifdef CONFIG_SYSCTL" region for compiling CONFIG_SYSCTL=n case.
Quoted 6 lines
lib/sys_info.c +0
-1---Quoted 2 lines
Sorry for the inconvenience, and I should upgrade my gcc :)
I am not sure that GCC has this warning, I have only ever seen it with clang.
Got it.
Thanks,
Feng
Quoted 4 lines · Feng Tang
Quoted 3 lines · Nathan Chancellor
Quoted 2 lines · Feng Tang
Quoted 1 line · Andrew Morton
On Thu, 10 Jul 2025 12:48:16 +0300 Andy Shevchenko <[email protected]> wrote:
...
Quoted 21 lines
Quoted 21 lines
Quoted 12 lines
sys_info_avail[] has another purpose for being a counterpart of si_names[], which could be extended in future, so we make it obviously stand-alone. As for definition of si_names[], we explicitly added comment:
/* * When 'si_names' gets updated, please make sure the 'sys_info_avail' * below is updated accordingly. */ static const struct sys_info_name si_names[] = { { SYS_INFO_TASKS, "tasks" }, { SYS_INFO_MEM, "mem" },Quoted 5 lines
which has also been discussed in another thread:
https://lore.kernel.org/lkml/[email protected]/And I suggest to keep sys_info_avail[], and either Nathan or Sergey's patch works for me.
We could do something like this to keep the
sizeof()obvious and separate, while still eliminating the variable? Happy to bike shed aspects of it like the macro name and such.
...
Quoted 1 line
Quoted 1 line
+#define
SYS_INFO_MAX_LEN(sizeof("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks")+ 1)
The ' + 1' is batter to leave for the names below. Or at bare minimum it needs a semantic explanation. If it's for NUL, definitely shouldn't be part of the definition.
Quoted 11 lines
lib/sys_info.c unsigned long sys_info_parse_param(char *str) · line 60
Quoted 8 lines
int sysctl_sys_info_handler(const struct
ctl_table*ro_table, int write,lib/sys_info.c +1
-1void *buffer, size_t *lenp, loff_t *ppos) { - char names[sizeof(sys_info_avail) + 1]; + char names[SYS_INFO_MAX_LEN];struct ctl_table table;unsigned long *si_bits_global;Looks great to me, thanks!
Quoted 1 line
We can even move the
SYS_INFO_MAX_LENdefinition close to si_names[],
Agree.
Quoted 2 lines
initially sys_info_avail[] was next to si_names[], and was moved inside "#ifdef
CONFIG_SYSCTL" region for compilingCONFIG_SYSCTL=ncase.
But let me think a bit, perhaps we can come up with something even better.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Feng Tang
On Thu, Jul 10, 2025 at 06:49:47PM -0700, Nathan Chancellor wrote:
...
Quoted 8 lines
Quoted 1 line
We can even move the
SYS_INFO_MAX_LENdefinition close to si_names[],Agree.
Quoted 2 lines
initially sys_info_avail[] was next to si_names[], and was moved inside "#ifdef
CONFIG_SYSCTL" region for compilingCONFIG_SYSCTL=ncase.But let me think a bit, perhaps we can come up with something even better.
Okay, guys, I have a better approach found. Let me mock up a patch series for that (we need one prerequisite).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 2 lines · Feng Tang
Quoted 1 line · Andrew Morton
On Thu, 10 Jul 2025 12:48:16 +0300 Andy Shevchenko <[email protected]> wrote:
...
Quoted 17 lines
Quoted 4 lines
lib/sys_info.c unsigned long sys_info_parse_param(char *str) · line 56
Quoted 2 lines
lib/sys_info.c +1
-1-char names[sizeof (sys_info_avail) +1 ]; +char names[sizeof ("tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks" ) +1 ];Yes, that's neater than the fix we currently have. I'll grab, thanks.
sys_info_avail[] has another purpose for being a counterpart of si_names[], which could be extended in future, so we make it obviously stand-alone. As for definition of si_names[], we explicitly added comment:
/* * When 'si_names' gets updated, please make sure the 'sys_info_avail' * below is updated accordingly. */ static const struct sys_info_name si_names[] = { { SYS_INFO_TASKS, "tasks" }, { SYS_INFO_MEM, "mem" },
Quoted 2 lines
which has also been discussed in another thread:
https://lore.kernel.org/lkml/[email protected]/
Ah, this is interesting. Let's rethink about the solution.
Quoted 2 lines
And I suggest to keep sys_info_avail[], and either Nathan or Sergey's patch works for me.
I definitely not suggest to leave build broken
(try with CONFOG_WERROR=y, which is default).
Quoted 1 line
Sorry for the inconvenience, and I should upgrade my gcc :)
I have compiled with clang-19.
Signature · 2 lines
With Best Regards, Andy Shevchenko