lkml.org 
[lkml]   [2004]   [Nov]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] Driver Core patches for 2.6.10-rc1
Date
From
ChangeSet 1.2446, 2004/11/01 13:04:46-08:00, akpm@osdl.org

[PATCH] Possible race in sysfs_read_file() and sysfs_write_file()

From: Simon Derr <Simon.Derr@bull.net>

Add a `needs_read_fill' field in sysfs_buffer so that reading after a write in
a sysfs file returns valid data.

(instead of the data that have been written, that may be invalid or at the
wrong offset)

Signed-off-by: Simon Derr <simon.derr@bull.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>


fs/sysfs/file.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletion(-)


diff -Nru a/fs/sysfs/file.c b/fs/sysfs/file.c
--- a/fs/sysfs/file.c 2004-11-01 13:36:42 -08:00
+++ b/fs/sysfs/file.c 2004-11-01 13:36:42 -08:00
@@ -55,6 +55,7 @@
char * page;
struct sysfs_ops * ops;
struct semaphore sem;
+ int needs_read_fill;
};


@@ -82,6 +83,7 @@
return -ENOMEM;

count = ops->show(kobj,attr,buffer->page);
+ buffer->needs_read_fill = 0;
BUG_ON(count > (ssize_t)PAGE_SIZE);
if (count >= 0)
buffer->count = count;
@@ -146,7 +148,7 @@
ssize_t retval = 0;

down(&buffer->sem);
- if ((!*ppos) || (!buffer->page)) {
+ if (buffer->needs_read_fill) {
if ((retval = fill_read_buffer(file->f_dentry,buffer)))
goto out;
}
@@ -182,6 +184,7 @@
if (count >= PAGE_SIZE)
count = PAGE_SIZE - 1;
error = copy_from_user(buffer->page,buf,count);
+ buffer->needs_read_fill = 1;
return error ? -EFAULT : count;
}

@@ -299,6 +302,7 @@
if (buffer) {
memset(buffer,0,sizeof(struct sysfs_buffer));
init_MUTEX(&buffer->sem);
+ buffer->needs_read_fill = 1;
buffer->ops = ops;
file->private_data = buffer;
} else
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:07    [W:0.338 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site