From: Jon Smirl <jonsmirl@gmail.com>
To: Andrew Morton <akpm@osdl.org>
Cc: lkml <linux-kernel@vger.kernel.org>, Greg KH <greg@kroah.com>
Subject: [PATCH] fix whitespace handling on sysfs attributes
Date: Tue, 23 Aug 2005 09:44:12 -0400 [thread overview]
Message-ID: <9e473391050823064469eb78a2@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 430 bytes --]
The first version of this patch didn't allow for the request firmware
case which does multiple parsing passes on the parameter. This was
discussed in the thread '2.6.13-rc6-mm1'
gregkh-driver-sysfs-strip_leading_trailing_whitespace-3.patch
should replace in 2.6.13-rc6-mm1
gregkh-driver-sysfs-strip_leading_trailing_whitespace.patch
Signed-off-by: Jon Smirl <jonsmirl@gmail.com>
--
Jon Smirl
jonsmirl@gmail.com
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: gregkh-driver-sysfs-strip_leading_trailing_whitespace-3.patch --]
[-- Type: text/x-diff; name="gregkh-driver-sysfs-strip_leading_trailing_whitespace-3.patch", Size: 1354 bytes --]
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -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,41 @@ flush_write_buffer(struct dentry * dentr
struct attribute * attr = to_attr(dentry);
struct kobject * kobj = to_kobj(dentry->d_parent);
struct sysfs_ops * ops = buffer->ops;
+ size_t ws_count = count, leading = 0;
+ int ret = 0;
+ char *x;
- return ops->store(kobj,attr,buffer->page,count);
+ /* locate trailing white space */
+ while ((ws_count > 0) && isspace(buffer->page[ws_count - 1]))
+ ws_count--;
+ if (ws_count == 0)
+ return count;
+
+ /* locate leading white space */
+ x = buffer->page;
+ while (isspace(*x))
+ x++;
+ leading = x - buffer->page;
+ ws_count -= leading;
+
+ /* interface is still ambigous about this */
+ /* string is both passed by length and terminated */
+ if (ws_count != PAGE_SIZE)
+ x[ws_count] = '\0';
+
+ ret = ops->store(kobj, attr, x, ws_count);
+
+ /* is it an error? */
+ if (ret < 0)
+ return ret;
+
+ /* the whole string was consumed */
+ if (ret == ws_count)
+ return count;
+
+ /* only part of the string was consumed */
+ /* return count can not include trailing space */
+ return leading + ret;
}
next reply other threads:[~2005-08-23 13:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-08-23 13:44 Jon Smirl [this message]
2005-08-23 14:57 ` Pavel Machek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9e473391050823064469eb78a2@mail.gmail.com \
--to=jonsmirl@gmail.com \
--cc=akpm@osdl.org \
--cc=greg@kroah.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome