public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jon Smirl <jonsmirl@gmail.com>
To: Benoit Boissinot <benoit.boissinot@ens-lyon.org>
Cc: linux-kernel@vger.kernel.org, Andrew Morton <akpm@osdl.org>,
	Greg KH <greg@kroah.com>
Subject: Re: 2.6.13-rc6-mm1
Date: Mon, 22 Aug 2005 12:44:01 -0400	[thread overview]
Message-ID: <9e473391050822094451d11b58@mail.gmail.com> (raw)
In-Reply-To: <20050822143713.GA12947@ens-lyon.fr>

[-- Attachment #1: Type: text/plain, Size: 1168 bytes --]

On 8/22/05, Benoit Boissinot <benoit.boissinot@ens-lyon.org> wrote:
> On Sun, Aug 21, 2005 at 06:34:48PM -0400, Jon Smirl wrote:
> > This should fix it, but I'm not on a machine where I can test it. Can
> > you give it a try and let me know?
> >
> 
> it works ok.
> But there is still at least one problem: if ops->store returns an error,
> then there will be a substraction and the write will loop (i could do it
> with a store wich returned EINVAL and a 22 length string).
> 
> I don't know if you can put a '\0' at buffer->page[count] if
> count == PAGE_SIZE.
> 
> Moreover, i think it is more correct to add only the leading
> whitespace from the count because if the ops->store doesn't read
> everything it will do something weird:
> 
> For example, if we have ' 123    ' and ops->store read only one char,
> then the function will return 7 (1 leading + 4 trailing + 1 read).  For
> the next call the buffer will be filled only by spaces which is
> incorrect (it should be '23    ').

The attached version tries to fix these issues. I am still not
somewhere where I can test, so please check it out.

-- 
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;
 }
 
 

  reply	other threads:[~2005-08-22 20:44 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-21 22:22 2.6.13-rc6-mm1 Benoit Boissinot
2005-08-21 22:34 ` 2.6.13-rc6-mm1 Jon Smirl
2005-08-22 14:37   ` 2.6.13-rc6-mm1 Benoit Boissinot
2005-08-22 16:44     ` Jon Smirl [this message]
2005-08-22 18:13       ` 2.6.13-rc6-mm1 Benoit Boissinot
     [not found] <fa.h617rae.h64dpq@ifi.uio.no>
2005-08-21  6:40 ` 2.6.13-rc6-mm1 Reuben Farrelly
2005-08-21  6:52   ` 2.6.13-rc6-mm1 Andrew Morton
2005-08-22 15:12     ` 2.6.13-rc6-mm1 John McCutchan
  -- strict thread matches above, loose matches on Subject: below --
2005-08-19 11:33 2.6.13-rc6-mm1 Andrew Morton
2005-08-19 13:12 ` 2.6.13-rc6-mm1 Brice Goglin
2005-08-19 13:18 ` 2.6.13-rc6-mm1 Brice Goglin
2005-08-19 13:22   ` 2.6.13-rc6-mm1 Brice Goglin
2005-08-19 13:21 ` 2.6.13-rc6-mm1 Reuben Farrelly
2005-08-19 17:34   ` 2.6.13-rc6-mm1 Andrew Morton
2005-08-20  1:27     ` 2.6.13-rc6-mm1 Reuben Farrelly
2005-08-20  1:34       ` 2.6.13-rc6-mm1 Andrew Morton
2005-08-20  1:36       ` 2.6.13-rc6-mm1 Andrew Morton
2005-08-20 13:40         ` 2.6.13-rc6-mm1 David Woodhouse
2005-08-21  6:25           ` 2.6.13-rc6-mm1 Reuben Farrelly
2005-08-19 13:25 ` 2.6.13-rc6-mm1 Brice Goglin
2005-08-19 13:27   ` 2.6.13-rc6-mm1 Russell King
2005-08-19 13:41     ` 2.6.13-rc6-mm1 Brice Goglin
2005-08-19 13:45       ` 2.6.13-rc6-mm1 Russell King
2005-08-19 14:05         ` 2.6.13-rc6-mm1 Brice Goglin
2005-08-19 15:45 ` 2.6.13-rc6-mm1 Ed Tomlinson
2005-08-19 16:04   ` 2.6.13-rc6-mm1 Benoit Boissinot
2005-08-19 21:01     ` 2.6.13-rc6-mm1 Ed Tomlinson
2005-08-19 21:24       ` 2.6.13-rc6-mm1 Benoit Boissinot
2005-08-19 16:11 ` 2.6.13-rc6-mm1 Dave Kleikamp
2005-08-19 19:21   ` 2.6.13-rc6-mm1 Andrew Morton
2005-08-19 16:42 ` 2.6.13-rc6-mm1 Avuton Olrich
2005-08-19 21:10   ` 2.6.13-rc6-mm1 Greg KH
2005-08-19 21:21     ` 2.6.13-rc6-mm1 Avuton Olrich
2005-08-19 18:03 ` 2.6.13-rc6-mm1 Jesper Juhl
2005-08-19 19:22 ` 2.6.13-rc6-mm1 hallyn
2005-08-20 14:49 ` 2.6.13-rc6-mm1 Martin J. Bligh
2005-08-21 15:08 ` 2.6.13-rc6-mm1 Martin J. Bligh
2005-08-21 16:30 ` 2.6.13-rc6-mm1 Benoit Boissinot
2005-08-21 17:40   ` 2.6.13-rc6-mm1 Jon Smirl
2005-08-21 21:44     ` 2.6.13-rc6-mm1 Benoit Boissinot
2005-08-21 22:11       ` 2.6.13-rc6-mm1 Jon Smirl
2005-08-22  1:36 ` 2.6.13-rc6-mm1 Rogério Brito
     [not found] ` <20050822011528.GA12602@ime.usp.br>
2005-08-22  3:48   ` 2.6.13-rc6-mm1 Andrew Morton
2005-08-22 13:30     ` 2.6.13-rc6-mm1 Rogério Brito

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=9e473391050822094451d11b58@mail.gmail.com \
    --to=jonsmirl@gmail.com \
    --cc=akpm@osdl.org \
    --cc=benoit.boissinot@ens-lyon.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