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: capture si_bits_global before iterating over it

Patch series "panic: sys_info: Refactor and fix a potential issue", v3.

While targeting the compilation issue due to dangling variable, I have
noticed more opportunities for refactoring that helps to avoid above
mentioned compilation issue in a cleaner way and also fixes a potential
problem with global variable access.


This patch (of 6):

The for-loop might re-read the content of the memory the si_bits_global
points to on each iteration. Instead, just capture it for the sake of
consistency and use that instead.

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

authored by

Andy Shevchenko and committed by
Andrew Morton
d79a3aeb 3e4b89e9

+5 -2
+5 -2
lib/sys_info.c
··· 58 58 char names[sizeof(sys_info_avail)]; 59 59 struct ctl_table table; 60 60 unsigned long *si_bits_global; 61 + unsigned long si_bits; 61 62 62 63 si_bits_global = ro_table->data; 63 64 64 65 if (write) { 65 - unsigned long si_bits; 66 66 int ret; 67 67 68 68 table = *ro_table; ··· 81 81 char *delim = ""; 82 82 int i, len = 0; 83 83 84 + /* The access to the global value is not synchronized. */ 85 + si_bits = READ_ONCE(*si_bits_global); 86 + 84 87 names[0] = '\0'; 85 88 for (i = 0; i < ARRAY_SIZE(si_names); i++) { 86 - if (*si_bits_global & si_names[i].bit) { 89 + if (si_bits & si_names[i].bit) { 87 90 len += scnprintf(names + len, sizeof(names) - len, 88 91 "%s%s", delim, si_names[i].name); 89 92 delim = ",";