aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/bin.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sysfs/bin.c')
-rw-r--r--fs/sysfs/bin.c19
1 files changed, 5 insertions, 14 deletions
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index 618b8aea6a7b..3c5574a40b09 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -175,25 +175,20 @@ static int open(struct inode * inode, struct file * file)
175 if (!sysfs_get_active(attr_sd)) 175 if (!sysfs_get_active(attr_sd))
176 return -ENODEV; 176 return -ENODEV;
177 177
178 /* Grab the module reference for this attribute */
179 error = -ENODEV;
180 if (!try_module_get(attr->attr.owner))
181 goto err_sput;
182
183 error = -EACCES; 178 error = -EACCES;
184 if ((file->f_mode & FMODE_WRITE) && !(attr->write || attr->mmap)) 179 if ((file->f_mode & FMODE_WRITE) && !(attr->write || attr->mmap))
185 goto err_mput; 180 goto err_out;
186 if ((file->f_mode & FMODE_READ) && !(attr->read || attr->mmap)) 181 if ((file->f_mode & FMODE_READ) && !(attr->read || attr->mmap))
187 goto err_mput; 182 goto err_out;
188 183
189 error = -ENOMEM; 184 error = -ENOMEM;
190 bb = kzalloc(sizeof(*bb), GFP_KERNEL); 185 bb = kzalloc(sizeof(*bb), GFP_KERNEL);
191 if (!bb) 186 if (!bb)
192 goto err_mput; 187 goto err_out;
193 188
194 bb->buffer = kmalloc(PAGE_SIZE, GFP_KERNEL); 189 bb->buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);
195 if (!bb->buffer) 190 if (!bb->buffer)
196 goto err_mput; 191 goto err_out;
197 192
198 mutex_init(&bb->mutex); 193 mutex_init(&bb->mutex);
199 file->private_data = bb; 194 file->private_data = bb;
@@ -203,9 +198,7 @@ static int open(struct inode * inode, struct file * file)
203 sysfs_get(attr_sd); 198 sysfs_get(attr_sd);
204 return 0; 199 return 0;
205 200
206 err_mput: 201 err_out:
207 module_put(attr->attr.owner);
208 err_sput:
209 sysfs_put_active(attr_sd); 202 sysfs_put_active(attr_sd);
210 kfree(bb); 203 kfree(bb);
211 return error; 204 return error;
@@ -214,13 +207,11 @@ static int open(struct inode * inode, struct file * file)
214static int release(struct inode * inode, struct file * file) 207static int release(struct inode * inode, struct file * file)
215{ 208{
216 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; 209 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
217 struct bin_attribute *attr = attr_sd->s_elem.bin_attr.bin_attr;
218 struct bin_buffer *bb = file->private_data; 210 struct bin_buffer *bb = file->private_data;
219 211
220 if (bb->mmapped) 212 if (bb->mmapped)
221 sysfs_put_active_two(attr_sd); 213 sysfs_put_active_two(attr_sd);
222 sysfs_put(attr_sd); 214 sysfs_put(attr_sd);
223 module_put(attr->attr.owner);
224 kfree(bb->buffer); 215 kfree(bb->buffer);
225 kfree(bb); 216 kfree(bb);
226 return 0; 217 return 0;