aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/file.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-10-01 17:41:56 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-05 14:02:04 -0400
commitaea585ef8fa6516395022e9d2fed6ec5014128bc (patch)
treebc048cbe87bf5ed3400bb62eccc28a76c8878914 /fs/sysfs/file.c
parent89e51dab7cb026193714f2858dbce203c98ecdec (diff)
sysfs: remove sysfs_buffer->needs_read_fill
->needs_read_fill is used to implement the following behaviors. 1. Ensure buffer filling on the first read. 2. Force buffer filling after a write. 3. Force buffer filling after a successful poll. However, #2 and #3 don't really work as sysfs doesn't reset file position. While the read buffer would be refilled, the next read would continue from the position after the last read or write, requiring an explicit seek to the start for it to be useful, which makes ->needs_read_fill superflous as read buffer is always refilled if f_pos == 0. Update sysfs_read_file() to test buffer->page for #1 instead and remove ->needs_read_fill. While this changes behavior in extreme corner cases - e.g. re-reading a sysfs file after seeking to non-zero position after a write or poll, it's highly unlikely to lead to actual breakage. This change is to prepare for using seq_file in the read path. While at it, reformat a comment in fill_write_buffer(). Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Kay Sievers <kay@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r--fs/sysfs/file.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 81e3f727833f..e2fafc0a9b36 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -47,7 +47,6 @@ struct sysfs_buffer {
47 char *page; 47 char *page;
48 const struct sysfs_ops *ops; 48 const struct sysfs_ops *ops;
49 struct mutex mutex; 49 struct mutex mutex;
50 int needs_read_fill;
51 int event; 50 int event;
52 struct list_head list; 51 struct list_head list;
53}; 52};
@@ -95,12 +94,10 @@ static int fill_read_buffer(struct dentry *dentry, struct sysfs_buffer *buffer)
95 /* Try to struggle along */ 94 /* Try to struggle along */
96 count = PAGE_SIZE - 1; 95 count = PAGE_SIZE - 1;
97 } 96 }
98 if (count >= 0) { 97 if (count >= 0)
99 buffer->needs_read_fill = 0;
100 buffer->count = count; 98 buffer->count = count;
101 } else { 99 else
102 ret = count; 100 ret = count;
103 }
104 return ret; 101 return ret;
105} 102}
106 103
@@ -130,7 +127,11 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
130 ssize_t retval = 0; 127 ssize_t retval = 0;
131 128
132 mutex_lock(&buffer->mutex); 129 mutex_lock(&buffer->mutex);
133 if (buffer->needs_read_fill || *ppos == 0) { 130 /*
131 * Fill on zero offset and the first read so that silly things like
132 * "dd bs=1 skip=N" can work on sysfs files.
133 */
134 if (*ppos == 0 || !buffer->page) {
134 retval = fill_read_buffer(file->f_path.dentry, buffer); 135 retval = fill_read_buffer(file->f_path.dentry, buffer);
135 if (retval) 136 if (retval)
136 goto out; 137 goto out;
@@ -166,14 +167,15 @@ static int fill_write_buffer(struct sysfs_buffer *buffer,
166 if (count >= PAGE_SIZE) 167 if (count >= PAGE_SIZE)
167 count = PAGE_SIZE - 1; 168 count = PAGE_SIZE - 1;
168 error = copy_from_user(buffer->page, buf, count); 169 error = copy_from_user(buffer->page, buf, count);
169 buffer->needs_read_fill = 1; 170
170 /* if buf is assumed to contain a string, terminate it by \0, 171 /*
171 so e.g. sscanf() can scan the string easily */ 172 * If buf is assumed to contain a string, terminate it by \0, so
173 * e.g. sscanf() can scan the string easily.
174 */
172 buffer->page[count] = 0; 175 buffer->page[count] = 0;
173 return error ? -EFAULT : count; 176 return error ? -EFAULT : count;
174} 177}
175 178
176
177/** 179/**
178 * flush_write_buffer - push buffer to kobject. 180 * flush_write_buffer - push buffer to kobject.
179 * @dentry: dentry to the attribute 181 * @dentry: dentry to the attribute
@@ -368,7 +370,6 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
368 goto err_out; 370 goto err_out;
369 371
370 mutex_init(&buffer->mutex); 372 mutex_init(&buffer->mutex);
371 buffer->needs_read_fill = 1;
372 buffer->ops = ops; 373 buffer->ops = ops;
373 file->private_data = buffer; 374 file->private_data = buffer;
374 375
@@ -435,7 +436,6 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
435 return DEFAULT_POLLMASK; 436 return DEFAULT_POLLMASK;
436 437
437 trigger: 438 trigger:
438 buffer->needs_read_fill = 1;
439 return DEFAULT_POLLMASK|POLLERR|POLLPRI; 439 return DEFAULT_POLLMASK|POLLERR|POLLPRI;
440} 440}
441 441