Skip to content

Commit f090682

Browse files
htejuntorvalds
authored andcommitted
net: use %*pb[l] to print bitmaps including cpumasks and nodemasks
printk and friends can now format bitmaps using '%*pb[l]'. cpumask and nodemask also provide cpumask_pr_args() and nodemask_pr_args() respectively which can be used to generate the two printf arguments necessary to format the specified cpu/nodemask. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 1a40243 commit f090682

File tree

2 files changed

+8
-22
lines changed

2 files changed

+8
-22
lines changed

net/core/net-sysfs.c

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,7 @@ static ssize_t show_rps_map(struct netdev_rx_queue *queue,
614614
{
615615
struct rps_map *map;
616616
cpumask_var_t mask;
617-
size_t len = 0;
618-
int i;
617+
int i, len;
619618

620619
if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
621620
return -ENOMEM;
@@ -626,17 +625,11 @@ static ssize_t show_rps_map(struct netdev_rx_queue *queue,
626625
for (i = 0; i < map->len; i++)
627626
cpumask_set_cpu(map->cpus[i], mask);
628627

629-
len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
630-
if (PAGE_SIZE - len < 3) {
631-
rcu_read_unlock();
632-
free_cpumask_var(mask);
633-
return -EINVAL;
634-
}
628+
len = snprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask));
635629
rcu_read_unlock();
636-
637630
free_cpumask_var(mask);
638-
len += sprintf(buf + len, "\n");
639-
return len;
631+
632+
return len < PAGE_SIZE ? len : -EINVAL;
640633
}
641634

642635
static ssize_t store_rps_map(struct netdev_rx_queue *queue,
@@ -1090,8 +1083,7 @@ static ssize_t show_xps_map(struct netdev_queue *queue,
10901083
struct xps_dev_maps *dev_maps;
10911084
cpumask_var_t mask;
10921085
unsigned long index;
1093-
size_t len = 0;
1094-
int i;
1086+
int i, len;
10951087

10961088
if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
10971089
return -ENOMEM;
@@ -1117,15 +1109,9 @@ static ssize_t show_xps_map(struct netdev_queue *queue,
11171109
}
11181110
rcu_read_unlock();
11191111

1120-
len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
1121-
if (PAGE_SIZE - len < 3) {
1122-
free_cpumask_var(mask);
1123-
return -EINVAL;
1124-
}
1125-
1112+
len = snprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask));
11261113
free_cpumask_var(mask);
1127-
len += sprintf(buf + len, "\n");
1128-
return len;
1114+
return len < PAGE_SIZE ? len : -EINVAL;
11291115
}
11301116

11311117
static ssize_t store_xps_map(struct netdev_queue *queue,

net/core/sysctl_net_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static int flow_limit_cpu_sysctl(struct ctl_table *table, int write,
155155
rcu_read_unlock();
156156

157157
len = min(sizeof(kbuf) - 1, *lenp);
158-
len = cpumask_scnprintf(kbuf, len, mask);
158+
len = scnprintf(kbuf, len, "%*pb", cpumask_pr_args(mask));
159159
if (!len) {
160160
*lenp = 0;
161161
goto done;

0 commit comments

Comments
 (0)