[Suggestion] net/core: cpumask_scnprintf, use (PAGE_SIZE - 1) instead of PAGE_SIZE

3 messages, 1 author, 2012-11-21 · open the first message on its own page

[Suggestion] net/core: cpumask_scnprintf, use (PAGE_SIZE - 1) instead of PAGE_SIZE

From: Chen Gang <hidden>
Date: 2012-11-21 07:54:26

Hi David Miller:

in net/core/net-sysfs.c:

  at line 496, we need use (PAGE_SIZE -1) instead of PAGE_SIZE.
  since at line 505, we append '\n'.

  regard

gchen


 479 static ssize_t show_rps_map(struct netdev_rx_queue *queue,
 480                             struct rx_queue_attribute *attribute, char *buf)
 481 {
 482         struct rps_map *map;
 483         cpumask_var_t mask;
 484         size_t len = 0;
 485         int i;
 486 
 487         if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
 488                 return -ENOMEM;
 489 
 490         rcu_read_lock();
 491         map = rcu_dereference(queue->rps_map);
 492         if (map)
 493                 for (i = 0; i < map->len; i++)
 494                         cpumask_set_cpu(map->cpus[i], mask);
 495 
 496         len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
 497         if (PAGE_SIZE - len < 3) {
 498                 rcu_read_unlock();
 499                 free_cpumask_var(mask);
 500                 return -EINVAL;
 501         }
 502         rcu_read_unlock();
 503 
 504         free_cpumask_var(mask);
 505         len += sprintf(buf + len, "\n");
 506         return len;
 507 }
 508 

Re: [Suggestion] net/core: cpumask_scnprintf, use (PAGE_SIZE - 1) instead of PAGE_SIZE

From: Chen Gang <hidden>
Date: 2012-11-21 08:01:06

Hi David

 also for show_xps_map in net/core/net-sysfs.c


Regard

gchen


 933 static ssize_t show_xps_map(struct netdev_queue *queue,
 934                             struct netdev_queue_attribute *attribute, char *buf)
 935 {
 936         struct net_device *dev = queue->dev;
 937         struct xps_dev_maps *dev_maps;
 938         cpumask_var_t mask;
 939         unsigned long index;
 940         size_t len = 0;
 941         int i;
 942 
 943         if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
 944                 return -ENOMEM;
 945 
 946         index = get_netdev_queue_index(queue);
 947 
 948         rcu_read_lock();
 949         dev_maps = rcu_dereference(dev->xps_maps);
 950         if (dev_maps) {
 951                 for_each_possible_cpu(i) {
 952                         struct xps_map *map =
 953                             rcu_dereference(dev_maps->cpu_map[i]);
 954                         if (map) {
 955                                 int j;
 956                                 for (j = 0; j < map->len; j++) {
 957                                         if (map->queues[j] == index) {
 958                                                 cpumask_set_cpu(i, mask);
 959                                                 break;
 960                                         }
 961                                 }
 962                         }
 963                 }
 964         }
 965         rcu_read_unlock();
 966 
 967         len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
 968         if (PAGE_SIZE - len < 3) {
 969                 free_cpumask_var(mask);
 970                 return -EINVAL;
 971         }
 972 
 973         free_cpumask_var(mask);
 974         len += sprintf(buf + len, "\n");
 975         return len;
 976 }




于 2012年11月21日 15:55, Chen Gang 写道:
Hi David Miller:

in net/core/net-sysfs.c:

  at line 496, we need use (PAGE_SIZE -1) instead of PAGE_SIZE.
  since at line 505, we append '\n'.

  regard

gchen


 479 static ssize_t show_rps_map(struct netdev_rx_queue *queue,
 480                             struct rx_queue_attribute *attribute, char *buf)
 481 {
 482         struct rps_map *map;
 483         cpumask_var_t mask;
 484         size_t len = 0;
 485         int i;
 486 
 487         if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
 488                 return -ENOMEM;
 489 
 490         rcu_read_lock();
 491         map = rcu_dereference(queue->rps_map);
 492         if (map)
 493                 for (i = 0; i < map->len; i++)
 494                         cpumask_set_cpu(map->cpus[i], mask);
 495 
 496         len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
 497         if (PAGE_SIZE - len < 3) {
 498                 rcu_read_unlock();
 499                 free_cpumask_var(mask);
 500                 return -EINVAL;
 501         }
 502         rcu_read_unlock();
 503 
 504         free_cpumask_var(mask);
 505         len += sprintf(buf + len, "\n");
 506         return len;
 507 }
 508 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Chen Gang

Asianux Corporation

Re: [Suggestion] net/core: cpumask_scnprintf, use (PAGE_SIZE - 1) instead of PAGE_SIZE

From: Chen Gang <hidden>
Date: 2012-11-21 08:06:12

Hi David:


sorry it is my fault.

next time, I should check it carefully.


gchen.


于 2012年11月21日 16:02, Chen Gang 写道:
Hi David

 also for show_xps_map in net/core/net-sysfs.c


Regard

gchen


 933 static ssize_t show_xps_map(struct netdev_queue *queue,
 934                             struct netdev_queue_attribute *attribute, char *buf)
 935 {
 936         struct net_device *dev = queue->dev;
 937         struct xps_dev_maps *dev_maps;
 938         cpumask_var_t mask;
 939         unsigned long index;
 940         size_t len = 0;
 941         int i;
 942 
 943         if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
 944                 return -ENOMEM;
 945 
 946         index = get_netdev_queue_index(queue);
 947 
 948         rcu_read_lock();
 949         dev_maps = rcu_dereference(dev->xps_maps);
 950         if (dev_maps) {
 951                 for_each_possible_cpu(i) {
 952                         struct xps_map *map =
 953                             rcu_dereference(dev_maps->cpu_map[i]);
 954                         if (map) {
 955                                 int j;
 956                                 for (j = 0; j < map->len; j++) {
 957                                         if (map->queues[j] == index) {
 958                                                 cpumask_set_cpu(i, mask);
 959                                                 break;
 960                                         }
 961                                 }
 962                         }
 963                 }
 964         }
 965         rcu_read_unlock();
 966 
 967         len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
 968         if (PAGE_SIZE - len < 3) {
 969                 free_cpumask_var(mask);
 970                 return -EINVAL;
 971         }
 972 
 973         free_cpumask_var(mask);
 974         len += sprintf(buf + len, "\n");
 975         return len;
 976 }




于 2012年11月21日 15:55, Chen Gang 写道:
quoted
Hi David Miller:

in net/core/net-sysfs.c:

  at line 496, we need use (PAGE_SIZE -1) instead of PAGE_SIZE.
  since at line 505, we append '\n'.

  regard

gchen


 479 static ssize_t show_rps_map(struct netdev_rx_queue *queue,
 480                             struct rx_queue_attribute *attribute, char *buf)
 481 {
 482         struct rps_map *map;
 483         cpumask_var_t mask;
 484         size_t len = 0;
 485         int i;
 486 
 487         if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
 488                 return -ENOMEM;
 489 
 490         rcu_read_lock();
 491         map = rcu_dereference(queue->rps_map);
 492         if (map)
 493                 for (i = 0; i < map->len; i++)
 494                         cpumask_set_cpu(map->cpus[i], mask);
 495 
 496         len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
 497         if (PAGE_SIZE - len < 3) {
 498                 rcu_read_unlock();
 499                 free_cpumask_var(mask);
 500                 return -EINVAL;
 501         }
 502         rcu_read_unlock();
 503 
 504         free_cpumask_var(mask);
 505         len += sprintf(buf + len, "\n");
 506         return len;
 507 }
 508 
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Chen Gang

Asianux Corporation
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help