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:replace struct sys_info_name with plain array of strings

There is no need to keep a custom structure just for the need of a plain
array of strings. Replace struct sys_info_name with plain array of
strings.

With that done, simplify the code, in particular, naturally use
for_each_set_bit() when iterating over si_bits_global bitmap.

Link: https://lkml.kernel.org/r/20251030132007.3742368-4-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
d13adc61 760fc597

+20 -24
+20 -24
lib/sys_info.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0-only 2 - #include <linux/sched/debug.h> 2 + #include <linux/bitops.h> 3 3 #include <linux/console.h> 4 + #include <linux/log2.h> 4 5 #include <linux/kernel.h> 5 6 #include <linux/ftrace.h> 6 - #include <linux/sysctl.h> 7 7 #include <linux/nmi.h> 8 + #include <linux/sched/debug.h> 9 + #include <linux/string.h> 10 + #include <linux/sysctl.h> 8 11 9 12 #include <linux/sys_info.h> 10 - 11 - struct sys_info_name { 12 - unsigned long bit; 13 - const char *name; 14 - }; 15 13 16 14 /* 17 15 * When 'si_names' gets updated, please make sure the 'sys_info_avail' 18 16 * below is updated accordingly. 19 17 */ 20 - static const struct sys_info_name si_names[] = { 21 - { SYS_INFO_TASKS, "tasks" }, 22 - { SYS_INFO_MEM, "mem" }, 23 - { SYS_INFO_TIMERS, "timers" }, 24 - { SYS_INFO_LOCKS, "locks" }, 25 - { SYS_INFO_FTRACE, "ftrace" }, 26 - { SYS_INFO_ALL_BT, "all_bt" }, 27 - { SYS_INFO_BLOCKED_TASKS, "blocked_tasks" }, 18 + static const char * const si_names[] = { 19 + [ilog2(SYS_INFO_TASKS)] = "tasks", 20 + [ilog2(SYS_INFO_MEM)] = "mem", 21 + [ilog2(SYS_INFO_TIMERS)] = "timers", 22 + [ilog2(SYS_INFO_LOCKS)] = "locks", 23 + [ilog2(SYS_INFO_FTRACE)] = "ftrace", 24 + [ilog2(SYS_INFO_PANIC_CONSOLE_REPLAY)] = "", 25 + [ilog2(SYS_INFO_ALL_BT)] = "all_bt", 26 + [ilog2(SYS_INFO_BLOCKED_TASKS)] = "blocked_tasks", 28 27 }; 29 28 30 29 /* Expecting string like "xxx_sys_info=tasks,mem,timers,locks,ftrace,..." */ ··· 35 36 36 37 s = str; 37 38 while ((name = strsep(&s, ",")) && *name) { 38 - for (i = 0; i < ARRAY_SIZE(si_names); i++) { 39 - if (!strcmp(name, si_names[i].name)) { 40 - si_bits |= si_names[i].bit; 41 - break; 42 - } 43 - } 39 + i = match_string(si_names, ARRAY_SIZE(si_names), name); 40 + if (i >= 0) 41 + __set_bit(i, &si_bits); 44 42 } 45 43 46 44 return si_bits; ··· 81 85 si_bits = READ_ONCE(*si_bits_global); 82 86 83 87 names[0] = '\0'; 84 - for (i = 0; i < ARRAY_SIZE(si_names); i++) { 85 - if (si_bits & si_names[i].bit) { 88 + for_each_set_bit(i, &si_bits, ARRAY_SIZE(si_names)) { 89 + if (*si_names[i]) { 86 90 len += scnprintf(names + len, sizeof(names) - len, 87 - "%s%s", delim, si_names[i].name); 91 + "%s%s", delim, si_names[i]); 88 92 delim = ","; 89 93 } 90 94 }