From: Rusty Russell <rusty@rustcorp.com.au>

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
don't haven't overrun it, and for futureproofing, detect problem at
buildtime.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/drivers/base/node.c |    7 ++++---
 25-akpm/fs/sysfs/file.c     |    1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff -puN drivers/base/node.c~fix-sys-cpumap-for-352-nr_cpus drivers/base/node.c
--- 25/drivers/base/node.c~fix-sys-cpumap-for-352-nr_cpus	2004-06-03 00:49:30.773556112 -0700
+++ 25-akpm/drivers/base/node.c	2004-06-03 00:49:30.778555352 -0700
@@ -21,9 +21,10 @@ static ssize_t node_read_cpumap(struct s
 	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, -1UL, mask);
 	len += sprintf(buf + len, "\n");
 	return len;
 }
diff -puN fs/sysfs/file.c~fix-sys-cpumap-for-352-nr_cpus fs/sysfs/file.c
--- 25/fs/sysfs/file.c~fix-sys-cpumap-for-352-nr_cpus	2004-06-03 00:49:30.774555960 -0700
+++ 25-akpm/fs/sysfs/file.c	2004-06-03 00:49:30.779555200 -0700
@@ -83,6 +83,7 @@ static int fill_read_buffer(struct file 
 		return -ENOMEM;
 
 	count = ops->show(kobj,attr,buffer->page);
+	BUG_ON(count > PAGE_SIZE);
 	if (count >= 0)
 		buffer->count = count;
 	else
_