Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2004-06-04 20:57:12 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-06-04 20:57:12 -0700
commitb431aa1834cf7a8b7df591f5f4710d534ea5a1e8 (patch)
tree93e3bdb1d397b36ba051a275d5d2e223ded32d4d
parentd4a006b914b7e4f5cf93a02fc6fdcedbccae5608 (diff)
[PATCH] fix sysfs node cpumap for large NR_CPUS
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>
-rw-r--r--drivers/base/node.c7
-rw-r--r--fs/sysfs/file.c1
2 files changed, 5 insertions, 3 deletions
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 7508df3731cc..b5aa9dc6cdb7 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -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;
}
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 47c98d0224ef..72cd7076cc50 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -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