]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mm: fix off-by-one bug in print_nodes_state()
authorRyota Ozaki <ozaki.ryota@gmail.com>
Thu, 3 May 2012 05:43:44 +0000 (15:43 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 3 May 2012 05:46:27 +0000 (15:46 +1000)
/sys/devices/system/node/{online,possible} outputs a garbage byte because
print_nodes_state() returns content size + 1.  To fix the bug, the patch
changes the use of cpuset_sprintf_cpulist to follow the use at other
places, which is clearer and safer.

This bug was introduced since v2.6.24 (bde631a51876f23e9).

Signed-off-by: Ryota Ozaki <ozaki.ryota@gmail.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/base/node.c

index 90aa2a11a933b448a536a353c5d932668c3f8e11..af1a177216f12573c7e481fea0a568c09b97ef12 100644 (file)
@@ -592,11 +592,9 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
 {
        int n;
 
-       n = nodelist_scnprintf(buf, PAGE_SIZE, node_states[state]);
-       if (n > 0 && PAGE_SIZE > n + 1) {
-               *(buf + n++) = '\n';
-               *(buf + n++) = '\0';
-       }
+       n = nodelist_scnprintf(buf, PAGE_SIZE-2, node_states[state]);
+       buf[n++] = '\n';
+       buf[n] = '\0';
        return n;
 }