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: factor out read and write handlers

For the sake of the code readability and easier maintenance factor out
read and write sys_info handlers.

[akpm@linux-foundation.org: coding-style cleanups]
Link: https://lkml.kernel.org/r/20251030132007.3742368-7-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
91251632 f791dcc8

+46 -33
+46 -33
lib/sys_info.c
··· 43 43 44 44 #ifdef CONFIG_SYSCTL 45 45 46 + static int sys_info_write_handler(const struct ctl_table *table, 47 + void *buffer, size_t *lenp, loff_t *ppos, 48 + unsigned long *si_bits_global) 49 + { 50 + unsigned long si_bits; 51 + int ret; 52 + 53 + ret = proc_dostring(table, 1, buffer, lenp, ppos); 54 + if (ret) 55 + return ret; 56 + 57 + si_bits = sys_info_parse_param(table->data); 58 + 59 + /* The access to the global value is not synchronized. */ 60 + WRITE_ONCE(*si_bits_global, si_bits); 61 + 62 + return 0; 63 + } 64 + 65 + static int sys_info_read_handler(const struct ctl_table *table, 66 + void *buffer, size_t *lenp, loff_t *ppos, 67 + unsigned long *si_bits_global) 68 + { 69 + unsigned long si_bits; 70 + unsigned int len = 0; 71 + char *delim = ""; 72 + unsigned int i; 73 + 74 + /* The access to the global value is not synchronized. */ 75 + si_bits = READ_ONCE(*si_bits_global); 76 + 77 + for_each_set_bit(i, &si_bits, ARRAY_SIZE(si_names)) { 78 + if (*si_names[i]) { 79 + len += scnprintf(table->data + len, table->maxlen - len, 80 + "%s%s", delim, si_names[i]); 81 + delim = ","; 82 + } 83 + } 84 + 85 + return proc_dostring(table, 0, buffer, lenp, ppos); 86 + } 87 + 46 88 int sysctl_sys_info_handler(const struct ctl_table *ro_table, int write, 47 89 void *buffer, size_t *lenp, 48 90 loff_t *ppos) 49 91 { 50 92 struct ctl_table table; 51 - unsigned long *si_bits_global; 52 - unsigned long si_bits; 53 93 unsigned int i; 54 94 size_t maxlen; 55 - 56 - si_bits_global = ro_table->data; 57 95 58 96 maxlen = 0; 59 97 for (i = 0; i < ARRAY_SIZE(si_names); i++) ··· 105 67 table.data = names; 106 68 table.maxlen = maxlen; 107 69 108 - if (write) { 109 - int ret; 110 - 111 - ret = proc_dostring(&table, write, buffer, lenp, ppos); 112 - if (ret) 113 - return ret; 114 - 115 - si_bits = sys_info_parse_param(names); 116 - /* The access to the global value is not synchronized. */ 117 - WRITE_ONCE(*si_bits_global, si_bits); 118 - return 0; 119 - } else { 120 - /* for 'read' operation */ 121 - unsigned int len = 0; 122 - char *delim = ""; 123 - 124 - /* The access to the global value is not synchronized. */ 125 - si_bits = READ_ONCE(*si_bits_global); 126 - 127 - for_each_set_bit(i, &si_bits, ARRAY_SIZE(si_names)) { 128 - if (*si_names[i]) { 129 - len += scnprintf(names + len, maxlen - len, 130 - "%s%s", delim, si_names[i]); 131 - delim = ","; 132 - } 133 - } 134 - 135 - return proc_dostring(&table, write, buffer, lenp, ppos); 136 - } 70 + if (write) 71 + return sys_info_write_handler(&table, buffer, lenp, ppos, ro_table->data); 72 + else 73 + return sys_info_read_handler(&table, buffer, lenp, ppos, ro_table->data); 137 74 } 138 75 #endif 139 76