Subject: sysfs: strip leading and trailing whitespace from sysfs buffer

From: Jon Smirl <[email-masked]>
Date: Thu, 28 Jul 2005 16:27:32 -0400

Remove leading and trailing whitespace when text sysfs attribute is set

Signed-off-by: Jon Smirl <[email-masked]>
Signed-off-by: Greg Kroah-Hartman <[email-masked]>

---
 fs/sysfs/file.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletion(-)

--- gregkh-2.6.orig/fs/sysfs/file.c	2005-08-02 13:41:31.000000000 -0700
+++ gregkh-2.6/fs/sysfs/file.c	2005-08-08 14:21:35.000000000 -0700
@@ -6,6 +6,7 @@
 #include <linux/fsnotify.h>
 #include <linux/kobject.h>
 #include <linux/namei.h>
+#include <linux/ctype.h>
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 
@@ -207,8 +208,23 @@
 	struct attribute * attr = to_attr(dentry);
 	struct kobject * kobj = to_kobj(dentry->d_parent);
 	struct sysfs_ops * ops = buffer->ops;
+	char *x;
 
-	return ops->store(kobj,attr,buffer->page,count);
+	/* locate trailing white space */
+	while ((count > 0) && isspace(buffer->page[count - 1]))
+		count--;
+
+	/* locate leading white space */
+	x = buffer->page;
+	if (count > 0) {
+		while (isspace(*x))
+			x++;
+		count -= (x - buffer->page);
+	}
+	/* terminate the string */
+	x[count] = '\0';
+
+	return ops->store(kobj, attr, x, count);
 }