]> git.hungrycats.org Git - linux/commitdiff
[PATCH] fix sysfs node cpumap for large NR_CPUS
authorRusty Russell <rusty@rustcorp.com.au>
Sat, 5 Jun 2004 03:57:12 +0000 (20:57 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Sat, 5 Jun 2004 03:57:12 +0000 (20:57 -0700)
As pointed out by Paul Jackson <pj@sgi.com>, sometimes 99 chars is not enough.
We currently get a page from sysfs: that code should check we haven't overrun
it.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Paul Jackson <pj@sgi.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/base/node.c
fs/sysfs/file.c

index 7508df3731ccfe6b83804548a45aefbd6c0746cf..b5aa9dc6cdb7dd97774ce3bd392ce35241e9a837 100644 (file)
@@ -21,9 +21,10 @@ static ssize_t node_read_cpumap(struct sys_device * dev, char * buf)
        cpumask_t mask = node_dev->cpumap;
        int len;
 
-       /* FIXME - someone should pass us a buffer size (count) or
-        * use seq_file or something to avoid buffer overrun risk. */
-       len = cpumask_scnprintf(buf, 99 /* XXX FIXME */, mask);
+       /* 2004/06/03: buf currently PAGE_SIZE, need > 1 char per 4 bits. */
+       BUILD_BUG_ON(NR_CPUS/4 > PAGE_SIZE/2);
+
+       len = cpumask_scnprintf(buf, PAGE_SIZE-1, mask);
        len += sprintf(buf + len, "\n");
        return len;
 }
index 47c98d0224ef5f64ec320a57923c01ac6ddfab8d..72cd7076cc50b7e243f8c6732cbd43c177f60e79 100644 (file)
@@ -89,6 +89,7 @@ static int fill_read_buffer(struct file * file, struct sysfs_buffer * buffer)
                return -ENOMEM;
 
        count = ops->show(kobj,attr,buffer->page);
+       BUG_ON(count > PAGE_SIZE);
        if (count >= 0)
                buffer->count = count;
        else