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

From: Simon Derr
Date: Fri Sep 03 2004 - 04:18:28 EST


On Thu, 2 Sep 2004, Andrew Morton wrote:

> Simon Derr <Simon.Derr@xxxxxxxx> wrote:
> >
> > @@ -140,13 +145,17 @@
> > struct sysfs_buffer * buffer = file->private_data;
> > ssize_t retval = 0;
> >
> > - if (!*ppos) {
> > + down(&buffer->sem);
> > + if ((!*ppos) || (!buffer->page)) {
> > if ((retval = fill_read_buffer(file->f_dentry,buffer)))
> > - return retval;
> > + goto out;
>
> Why are we testing *ppos at all in here?

To keep the original behaviour, that is, after lseek() to offset zero,
ops->show() is called again and the contents of the file are refreshed.

Some applications maybe rely on it, or it may be completely useless, I
don't known.

And if we open a sysfs file with O_RDWR, and write() into it, then this is
needed if we want to read(), because else the buffer will have been
allocated, but ops->show() not called. I'm not too sure about this being
useful either.


PS: just in case my previous patch is of any interest, note that I made an
interesting typo in the 'Signed-off-by' email field.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/