Skip to contentSkip to conversation

error handling in sysfs, fill_read_buffer()

PATCH Oliver Neukum 3 participants 5 messages Jan 2, 2007 Driver core

lore
Share & tools
lore
#0 lore raw

Hi,

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.

Regards
Oliver

--

fs/sysfs/file.c +6 -4
@@ -70,7 +70,8 @@
  *	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)
 {
@@ -88,12 +89,13 @@
 
 	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;
 }
 
#1 lore raw
Quoted 16 lines · Oliver Neukum

Hi,

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.

Regards
Oliver

--

fs/sysfs/file.c line 75

Quoted 7 lines
fs/sysfs/file.c +2 -1
@@ -70,7 +70,8 @@
  *	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.
  */

I don't think this matches what people expect of sysfs. If a show method fails then the assumption is that the file cannot be read at all, so there's no point in trying to call the method again.

Alan Stern

#2 lore raw

Am Dienstag, 2. Januar 2007 16:26 schrieb Alan Stern:

Quoted 15 lines · Oliver Neukum
Quoted 14 lines

Hi,

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.

Regards
Oliver

--

Quoted 14 lines

fs/sysfs/file.c line 75

Quoted 10 lines
fs/sysfs/file.c +2 -1
@@ -70,7 +70,8 @@
  *	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.
  */

I don't think this matches what people expect of sysfs. If a show method fails then the assumption is that the file cannot be read at all, so there's no point in trying to call the method again.

This would make handling ENOMEM very hard.

Regards
Oliver

#3 lore raw
Quoted 31 lines · Oliver Neukum

Am Dienstag, 2. Januar 2007 16:26 schrieb Alan Stern:

Quoted 15 lines · Oliver Neukum
Quoted 14 lines

Hi,

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.

Regards
Oliver

--

Quoted 14 lines

fs/sysfs/file.c line 75

Quoted 10 lines
fs/sysfs/file.c +2 -1
@@ -70,7 +70,8 @@
  *	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.
  */

I don't think this matches what people expect of sysfs. If a show method fails then the assumption is that the file cannot be read at all, so there's no point in trying to call the method again.

Quoted 1 line

This would make handling ENOMEM very hard.

No harder than handling any other error: Close the sysfs file, then open it and try to read it again.

On the other hand, I agree there's nothing substantively wrong with the patch.

Alan Stern

#4 lore raw

Am Dienstag, 2. Januar 2007 16:47 schrieb Alan Stern:

Quoted 33 lines · Oliver Neukum
Quoted 32 lines

Am Dienstag, 2. Januar 2007 16:26 schrieb Alan Stern:

Quoted 29 lines · Oliver Neukum
Quoted 17 lines

Hi,

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.

Regards
Oliver

--

fs/sysfs/file.c line 75

Quoted 7 lines
fs/sysfs/file.c +2 -1
@@ -70,7 +70,8 @@
  *	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.
  */

I don't think this matches what people expect of sysfs. If a show method fails then the assumption is that the file cannot be read at all, so there's no point in trying to call the method again.

Quoted 4 lines
Quoted 1 line

This would make handling ENOMEM very hard.

No harder than handling any other error: Close the sysfs file, then open it and try to read it again.

If you close it, it doesn't matter. However if not, it does. Not all the world simply uses "cat".

Regards
Oliver