Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

panic: sys_info: rewrite a fix for a compilation error (`make W=1`)

Compiler was not happy about dead variable in use:

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";
| ^~~~~~~~~~~~~~

This was fixed by adding __maybe_unused attribute that just hides the
issue and didn't actually fix the root cause. Rewrite the fix by moving
the local variable from stack to a heap.

As a side effect this drops unneeded "synchronisation" of duplicative info
and also makes code ready for the further refactoring.

Link: https://lkml.kernel.org/r/20251030132007.3742368-5-andriy.shevchenko@linux.intel.com
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Cc: Feng Tang <feng.tang@linux.alibaba.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Andy Shevchenko and committed by
Andrew Morton
eb72c466 d13adc61

+16 -12
+16 -12
lib/sys_info.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 + #include <linux/array_size.h> 2 3 #include <linux/bitops.h> 4 + #include <linux/cleanup.h> 3 5 #include <linux/console.h> 4 6 #include <linux/log2.h> 5 7 #include <linux/kernel.h> ··· 13 11 14 12 #include <linux/sys_info.h> 15 13 16 - /* 17 - * When 'si_names' gets updated, please make sure the 'sys_info_avail' 18 - * below is updated accordingly. 19 - */ 20 14 static const char * const si_names[] = { 21 15 [ilog2(SYS_INFO_TASKS)] = "tasks", 22 16 [ilog2(SYS_INFO_MEM)] = "mem", ··· 43 45 44 46 #ifdef CONFIG_SYSCTL 45 47 46 - static const char sys_info_avail[] __maybe_unused = "tasks,mem,timers,locks,ftrace,all_bt,blocked_tasks"; 47 - 48 48 int sysctl_sys_info_handler(const struct ctl_table *ro_table, int write, 49 49 void *buffer, size_t *lenp, 50 50 loff_t *ppos) 51 51 { 52 - char names[sizeof(sys_info_avail)]; 53 52 struct ctl_table table; 54 53 unsigned long *si_bits_global; 55 54 unsigned long si_bits; 55 + unsigned int i; 56 + size_t maxlen; 56 57 57 58 si_bits_global = ro_table->data; 59 + 60 + maxlen = 0; 61 + for (i = 0; i < ARRAY_SIZE(si_names); i++) 62 + maxlen += strlen(si_names[i]) + 1; 63 + 64 + char *names __free(kfree) = kzalloc(maxlen, GFP_KERNEL); 65 + if (!names) 66 + return -ENOMEM; 58 67 59 68 if (write) { 60 69 int ret; 61 70 62 71 table = *ro_table; 63 72 table.data = names; 64 - table.maxlen = sizeof(names); 73 + table.maxlen = maxlen; 65 74 ret = proc_dostring(&table, write, buffer, lenp, ppos); 66 75 if (ret) 67 76 return ret; ··· 79 74 return 0; 80 75 } else { 81 76 /* for 'read' operation */ 77 + unsigned int len = 0; 82 78 char *delim = ""; 83 - int i, len = 0; 84 79 85 80 /* The access to the global value is not synchronized. */ 86 81 si_bits = READ_ONCE(*si_bits_global); 87 82 88 - names[0] = '\0'; 89 83 for_each_set_bit(i, &si_bits, ARRAY_SIZE(si_names)) { 90 84 if (*si_names[i]) { 91 - len += scnprintf(names + len, sizeof(names) - len, 85 + len += scnprintf(names + len, maxlen - len, 92 86 "%s%s", delim, si_names[i]); 93 87 delim = ","; 94 88 } ··· 95 91 96 92 table = *ro_table; 97 93 table.data = names; 98 - table.maxlen = sizeof(names); 94 + table.maxlen = maxlen; 99 95 return proc_dostring(&table, write, buffer, lenp, ppos); 100 96 } 101 97 }