Skip to content

Commit 407fd14

Browse files
committed
net-sysctl: factor out cpumask parsing helper
jira LE-1907 Rebuild_History Non-Buildable kernel-rt-5.14.0-284.30.1.rt14.315.el9_2 commit-author Paolo Abeni <pabeni@redhat.com> commit 135746c 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> (cherry picked from commit 135746c) Signed-off-by: Jonathan Maple <jmaple@ciq.com>
1 parent 91b2eeb commit 407fd14

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

net/core/sysctl_net_core.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ EXPORT_SYMBOL(sysctl_fb_tunnels_only_for_init_net);
4949
int sysctl_devconf_inherit_init_net __read_mostly;
5050
EXPORT_SYMBOL(sysctl_devconf_inherit_init_net);
5151

52+
#if IS_ENABLED(CONFIG_NET_FLOW_LIMIT)
53+
static void dump_cpumask(void *buffer, size_t *lenp, loff_t *ppos,
54+
struct cpumask *mask)
55+
{
56+
char kbuf[128];
57+
int len;
58+
59+
if (*ppos || !*lenp) {
60+
*lenp = 0;
61+
return;
62+
}
63+
64+
len = min(sizeof(kbuf) - 1, *lenp);
65+
len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
66+
if (!len) {
67+
*lenp = 0;
68+
return;
69+
}
70+
71+
if (len < *lenp)
72+
kbuf[len++] = '\n';
73+
memcpy(buffer, kbuf, len);
74+
*lenp = len;
75+
*ppos += len;
76+
}
77+
#endif
78+
5279
#ifdef CONFIG_RPS
5380
static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
5481
void *buffer, size_t *lenp, loff_t *ppos)
@@ -161,13 +188,6 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
161188
write_unlock:
162189
mutex_unlock(&flow_limit_update_mutex);
163190
} else {
164-
char kbuf[128];
165-
166-
if (*ppos || !*lenp) {
167-
*lenp = 0;
168-
goto done;
169-
}
170-
171191
cpumask_clear(mask);
172192
rcu_read_lock();
173193
for_each_possible_cpu(i) {
@@ -177,17 +197,7 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
177197
}
178198
rcu_read_unlock();
179199

180-
len = min(sizeof(kbuf) - 1, *lenp);
181-
len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
182-
if (!len) {
183-
*lenp = 0;
184-
goto done;
185-
}
186-
if (len < *lenp)
187-
kbuf[len++] = '\n';
188-
memcpy(buffer, kbuf, len);
189-
*lenp = len;
190-
*ppos += len;
200+
dump_cpumask(buffer, lenp, ppos, mask);
191201
}
192202

193203
done:

0 commit comments

Comments
 (0)