From jonsmirl@gmail.com Thu Jul 28 13:27:51 2005 Message-ID: <9e473391050728132757a75d5f@mail.gmail.com> Date: Thu, 28 Jul 2005 16:27:32 -0400 From: Jon Smirl To: Mitchell Blank Jr Subject: sysfs: strip leading and trailing whitespace from sysfs buffer Cc: Greg KH , , Remove leading and trailing whitespace when text sysfs attribute is set Signed-off-by: Jon Smirl Signed-off-by: Greg Kroah-Hartman --- 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 #include #include +#include #include #include @@ -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); }