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

net-sysctl: factor out cpumask parsing helper

Will be used by the following patch to avoid code
duplication. No functional changes intended.

The only difference is that now flow_limit_cpu_sysctl() will
always compute the flow limit mask on each read operation,
even when read() will not return any byte to user-space.

Note that the new helper is placed under a new #ifdef at
the file start to better fit the usage in the later patch

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Paolo Abeni and committed by
Jakub Kicinski
135746c6 8697a258

+28 -18
+28 -18
net/core/sysctl_net_core.c
··· 45 45 int sysctl_devconf_inherit_init_net __read_mostly; 46 46 EXPORT_SYMBOL(sysctl_devconf_inherit_init_net); 47 47 48 + #if IS_ENABLED(CONFIG_NET_FLOW_LIMIT) 49 + static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos, 50 + struct cpumask *mask) 51 + { 52 + char kbuf[128]; 53 + int len; 54 + 55 + if (*ppos || !*lenp) { 56 + *lenp = 0; 57 + return; 58 + } 59 + 60 + len = min(sizeof(kbuf) - 1, *lenp); 61 + len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask)); 62 + if (!len) { 63 + *lenp = 0; 64 + return; 65 + } 66 + 67 + if (len < *lenp) 68 + kbuf[len++] = '\n'; 69 + memcpy(buffer, kbuf, len); 70 + *lenp = len; 71 + *ppos += len; 72 + } 73 + #endif 74 + 48 75 #ifdef CONFIG_RPS 49 76 static int rps_sock_flow_sysctl(struct ctl_table *table, int write, 50 77 void *buffer, size_t *lenp, loff_t *ppos) ··· 182 155 write_unlock: 183 156 mutex_unlock(&flow_limit_update_mutex); 184 157 } else { 185 - char kbuf[128]; 186 - 187 - if (*ppos || !*lenp) { 188 - *lenp = 0; 189 - goto done; 190 - } 191 - 192 158 cpumask_clear(mask); 193 159 rcu_read_lock(); 194 160 for_each_possible_cpu(i) { ··· 191 171 } 192 172 rcu_read_unlock(); 193 173 194 - len = min(sizeof(kbuf) - 1, *lenp); 195 - len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask)); 196 - if (!len) { 197 - *lenp = 0; 198 - goto done; 199 - } 200 - if (len < *lenp) 201 - kbuf[len++] = '\n'; 202 - memcpy(buffer, kbuf, len); 203 - *lenp = len; 204 - *ppos += len; 174 + dump_cpumask(buffer, lenp, ppos, mask); 205 175 } 206 176 207 177 done: