From oliver@neukum.name Mon Jan 1 23:49:05 2007 From: Oliver Neukum Date: Tue, 2 Jan 2007 08:48:08 +0100 (MET) Subject: sysfs: error handling in sysfs, fill_read_buffer() To: gregkh@suse.de, Alan Stern , , linux-kernel@vger.kernel.org Message-ID: <200701020850.28724.oliver@neukum.name> Content-Disposition: inline if a driver returns an error in fill_read_buffer(), the buffer will be marked as filled. Subsequent reads will return eof. But there is no data because of an error, not because it has been read. Not marking the buffer filled is the obvious fix. Signed-off-by: Oliver Neukum Signed-off-by: Greg Kroah-Hartman --- fs/sysfs/file.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- gregkh-2.6.orig/fs/sysfs/file.c +++ gregkh-2.6/fs/sysfs/file.c @@ -83,7 +83,8 @@ remove_from_collection(struct sysfs_buff * Allocate @buffer->page, if it hasn't been already, then call the * kobject's show() method to fill the buffer with this attribute's * data. - * This is called only once, on the file's first read. + * This is called only once, on the file's first read unless an error + * is returned. */ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer) { @@ -101,12 +102,13 @@ static int fill_read_buffer(struct dentr buffer->event = atomic_read(&sd->s_event); count = ops->show(kobj,attr,buffer->page); - buffer->needs_read_fill = 0; BUG_ON(count > (ssize_t)PAGE_SIZE); - if (count >= 0) + if (count >= 0) { + buffer->needs_read_fill = 0; buffer->count = count; - else + } else { ret = count; + } return ret; }