2.6.13-rc6-mm1
----- Forwarded message from Benoit Boissinot <[email protected]> ----- sorry, i forgot to reply all...
From: Benoit Boissinot <[email protected]>
To: Jon Smirl <[email protected]>
Subject: Re: 2.6.13-rc6-mm1
User-Agent: Mutt/1.5.10i
Quoted 12 lines · Jon Smirl
Quoted 11 lines · Benoit Boissinot
Quoted 9 lines · Jon Smirl
On 8/21/05, Benoit Boissinot <[email protected]> wrote:
[snip]Somewhere there is a mistake in the white space processing code of the firmware driver. Before this patch we had inconsistent handling of whitespace and sysfs attributes. This patch forces it to be consistent and will shake out all of the places in the drivers where it is handled wrong. Sysfs attributes are now stripped of leading and trailing white space before being handed to the device driver.
Quoted 7 lines
Quoted 4 lines
ok, i found it. If i do echo 1, it will read '1\n', will remove the '\n' and send '1' to
ops->store. Then it will re-read '\n' and send '' toops->store. And it will loop...Look at the length being passed in, isn't it set to zero for the second case?
yes, it is set to zero, but the '\n' will be stripped and stay in the buffer. Since flush_write_buffer returns 0, ppos will not be incremented and we have an endless loop.
Signature · 6 lines
powered by bash/screen/(urxvt/fvwm|linux-console)/gentoo/gnu/linux OS ----- End forwarded message ----- -- powered by bash/screen/(urxvt/fvwm|linux-console)/gentoo/gnu/linux OS
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?
Quoted 45 lines · Benoit Boissinot
----- Forwarded message from Benoit Boissinot <[email protected]> ----- sorry, i forgot to reply all...
From: Benoit Boissinot <[email protected]>
To: Jon Smirl <[email protected]>
Subject: Re: 2.6.13-rc6-mm1
User-Agent: Mutt/1.5.10iQuoted 12 lines · Jon Smirl
Quoted 11 lines · Benoit Boissinot
Quoted 9 lines · Jon Smirl
On 8/21/05, Benoit Boissinot <[email protected]> wrote:
[snip]Somewhere there is a mistake in the white space processing code of the firmware driver. Before this patch we had inconsistent handling of whitespace and sysfs attributes. This patch forces it to be consistent and will shake out all of the places in the drivers where it is handled wrong. Sysfs attributes are now stripped of leading and trailing white space before being handed to the device driver.
Quoted 7 lines
Quoted 4 lines
ok, i found it. If i do echo 1, it will read '1\n', will remove the '\n' and send '1' to
ops->store. Then it will re-read '\n' and send '' toops->store. And it will loop...Look at the length being passed in, isn't it set to zero for the second case?
yes, it is set to zero, but the '\n' will be stripped and stay in the buffer. Since
flush_write_bufferreturns 0, ppos will not be incremented and we have an endless loop.--
powered by bash/screen/(urxvt/fvwm|linux-console)/gentoo/gnu/linux OS----- End forwarded message -----
--
powered by bash/screen/(urxvt/fvwm|linux-console)/gentoo/gnu/linux OS -
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Jon Smirl [email protected]
fs/sysfs/file.c +22 -1
@@ -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,28 @@ flush_write_buffer(struct dentry * dentrstruct attribute * attr =to_attr (dentry);struct kobject * kobj =to_kobj (dentry->d_parent);struct sysfs_ops * ops = buffer->ops; +int ws_count = count; +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' ; + ws_count -= count; + +if (count !=0 ) + count = ops->store (kobj, attr, x, count); + +return count + ws_count; }
Quoted 3 lines · Jon Smirl
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 ').
Quoted 22 lines
fs/sysfs/file.c +6
-1@@ -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,28 @@ flush_write_buffer(struct dentry * dentrstruct attribute * attr =to_attr (dentry);struct kobject * kobj =to_kobj (dentry->d_parent);struct sysfs_ops * ops = buffer->ops; +int ws_count = count; +char *x; -return ops->store (kobj,attr,buffer->page,count); +/* locate trailing white space */ +while ((count >0 ) &&isspace (buffer->page[count -1 ])) + count--;
fs/sysfs/file.c flush_write_buffer(struct dentry * dentr · line 226
Quoted 10 lines
fs/sysfs/file.c +10
-0+ +/* locate leading white space */ + x = buffer->page; +if (count >0 ) { +while (isspace (*x)) + x++; + count -= (x - buffer->page); + } +/* terminate the string */ + x[count] ='\0' ;
what if count == PAGE_SIZE ?
fs/sysfs/file.c flush_write_buffer(struct dentry * dentr · line 232
Quoted 6 lines
fs/sysfs/file.c +6
-0+ ws_count -= count; + +if (count !=0 ) + count = ops->store (kobj, attr, x, count); + +return count + ws_count;
return (count < 0) ? count : count + ws_count;
Quoted 3 lines
fs/sysfs/file.c +0
-0}
Signature · 1 line
powered by bash/screen/(urxvt/fvwm|linux-console)/gentoo/gnu/linux OS
Quoted 13 lines · Benoit Boissinot
Quoted 3 lines · Jon Smirl
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: ifops->storereturns 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.
Quoted 8 lines
Moreover, i think it is more correct to add only the leading whitespace from the count because if the
ops->storedoesn't read everything it will do something weird:For example, if we have ' 123 ' and
ops->storeread 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.
Signature · 2 lines
Jon Smirl [email protected]
fs/sysfs/file.c +35 -1
@@ -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 * dentrstruct 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; }
Quoted 18 lines · Jon Smirl
Quoted 17 lines · Benoit Boissinot
Quoted 3 lines · Jon Smirl
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: ifops->storereturns 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->storedoesn't read everything it will do something weird:
Quoted 8 lines
Quoted 4 lines
For example, if we have ' 123 ' and
ops->storeread 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.
Yes it works fine, thanks.
Benoit Boissinot
Signature · 1 line
powered by bash/screen/(urxvt/fvwm|linux-console)/gentoo/gnu/linux OS