aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/binfmt_misc.c13
-rw-r--r--fs/configfs/file.c33
-rw-r--r--fs/sysfs/file.c33
3 files changed, 5 insertions, 74 deletions
diff --git a/fs/binfmt_misc.c b/fs/binfmt_misc.c
index 18657f001b43..72d0b412c376 100644
--- a/fs/binfmt_misc.c
+++ b/fs/binfmt_misc.c
@@ -675,19 +675,8 @@ static ssize_t
675bm_status_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) 675bm_status_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
676{ 676{
677 char *s = enabled ? "enabled" : "disabled"; 677 char *s = enabled ? "enabled" : "disabled";
678 int len = strlen(s);
679 loff_t pos = *ppos;
680 678
681 if (pos < 0) 679 return simple_read_from_buffer(buf, nbytes, ppos, s, strlen(s));
682 return -EINVAL;
683 if (pos >= len)
684 return 0;
685 if (len < pos + nbytes)
686 nbytes = len - pos;
687 if (copy_to_user(buf, s + pos, nbytes))
688 return -EFAULT;
689 *ppos = pos + nbytes;
690 return nbytes;
691} 680}
692 681
693static ssize_t bm_status_write(struct file * file, const char __user * buffer, 682static ssize_t bm_status_write(struct file * file, const char __user * buffer,
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index d98be5e01328..3527c7c6def8 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -77,36 +77,6 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf
77 return ret; 77 return ret;
78} 78}
79 79
80
81/**
82 * flush_read_buffer - push buffer to userspace.
83 * @buffer: data buffer for file.
84 * @userbuf: user-passed buffer.
85 * @count: number of bytes requested.
86 * @ppos: file position.
87 *
88 * Copy the buffer we filled in fill_read_buffer() to userspace.
89 * This is done at the reader's leisure, copying and advancing
90 * the amount they specify each time.
91 * This may be called continuously until the buffer is empty.
92 */
93static int flush_read_buffer(struct configfs_buffer * buffer, char __user * buf,
94 size_t count, loff_t * ppos)
95{
96 int error;
97
98 if (*ppos > buffer->count)
99 return 0;
100
101 if (count > (buffer->count - *ppos))
102 count = buffer->count - *ppos;
103
104 error = copy_to_user(buf,buffer->page + *ppos,count);
105 if (!error)
106 *ppos += count;
107 return error ? -EFAULT : count;
108}
109
110/** 80/**
111 * configfs_read_file - read an attribute. 81 * configfs_read_file - read an attribute.
112 * @file: file pointer. 82 * @file: file pointer.
@@ -139,7 +109,8 @@ configfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *pp
139 } 109 }
140 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", 110 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
141 __FUNCTION__, count, *ppos, buffer->page); 111 __FUNCTION__, count, *ppos, buffer->page);
142 retval = flush_read_buffer(buffer,buf,count,ppos); 112 retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
113 buffer->count);
143out: 114out:
144 up(&buffer->sem); 115 up(&buffer->sem);
145 return retval; 116 return retval;
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 0e637adc2b87..b502c7197ec0 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -111,36 +111,6 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
111 return ret; 111 return ret;
112} 112}
113 113
114
115/**
116 * flush_read_buffer - push buffer to userspace.
117 * @buffer: data buffer for file.
118 * @buf: user-passed buffer.
119 * @count: number of bytes requested.
120 * @ppos: file position.
121 *
122 * Copy the buffer we filled in fill_read_buffer() to userspace.
123 * This is done at the reader's leisure, copying and advancing
124 * the amount they specify each time.
125 * This may be called continuously until the buffer is empty.
126 */
127static int flush_read_buffer(struct sysfs_buffer * buffer, char __user * buf,
128 size_t count, loff_t * ppos)
129{
130 int error;
131
132 if (*ppos > buffer->count)
133 return 0;
134
135 if (count > (buffer->count - *ppos))
136 count = buffer->count - *ppos;
137
138 error = copy_to_user(buf,buffer->page + *ppos,count);
139 if (!error)
140 *ppos += count;
141 return error ? -EFAULT : count;
142}
143
144/** 114/**
145 * sysfs_read_file - read an attribute. 115 * sysfs_read_file - read an attribute.
146 * @file: file pointer. 116 * @file: file pointer.
@@ -177,7 +147,8 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
177 } 147 }
178 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", 148 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
179 __FUNCTION__, count, *ppos, buffer->page); 149 __FUNCTION__, count, *ppos, buffer->page);
180 retval = flush_read_buffer(buffer,buf,count,ppos); 150 retval = simple_read_from_buffer(buf, count, ppos, buffer->page,
151 buffer->count);
181out: 152out:
182 up(&buffer->sem); 153 up(&buffer->sem);
183 return retval; 154 return retval;