aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r--fs/sysfs/file.c21
1 files changed, 5 insertions, 16 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index d673d9b5d33f..a84b734f7b29 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -241,7 +241,6 @@ sysfs_write_file(struct file *file, const char __user *buf, size_t count, loff_t
241static int sysfs_open_file(struct inode *inode, struct file *file) 241static int sysfs_open_file(struct inode *inode, struct file *file)
242{ 242{
243 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata; 243 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
244 struct attribute *attr = attr_sd->s_elem.attr.attr;
245 struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj; 244 struct kobject *kobj = attr_sd->s_parent->s_elem.dir.kobj;
246 struct sysfs_buffer * buffer; 245 struct sysfs_buffer * buffer;
247 struct sysfs_ops * ops = NULL; 246 struct sysfs_ops * ops = NULL;
@@ -251,11 +250,6 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
251 if (!sysfs_get_active_two(attr_sd)) 250 if (!sysfs_get_active_two(attr_sd))
252 return -ENODEV; 251 return -ENODEV;
253 252
254 /* Grab the module reference for this attribute */
255 error = -ENODEV;
256 if (!try_module_get(attr->owner))
257 goto err_sput;
258
259 /* if the kobject has no ktype, then we assume that it is a subsystem 253 /* if the kobject has no ktype, then we assume that it is a subsystem
260 * itself, and use ops for it. 254 * itself, and use ops for it.
261 */ 255 */
@@ -272,7 +266,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
272 * or the subsystem have no operations. 266 * or the subsystem have no operations.
273 */ 267 */
274 if (!ops) 268 if (!ops)
275 goto err_mput; 269 goto err_out;
276 270
277 /* File needs write support. 271 /* File needs write support.
278 * The inode's perms must say it's ok, 272 * The inode's perms must say it's ok,
@@ -280,7 +274,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
280 */ 274 */
281 if (file->f_mode & FMODE_WRITE) { 275 if (file->f_mode & FMODE_WRITE) {
282 if (!(inode->i_mode & S_IWUGO) || !ops->store) 276 if (!(inode->i_mode & S_IWUGO) || !ops->store)
283 goto err_mput; 277 goto err_out;
284 } 278 }
285 279
286 /* File needs read support. 280 /* File needs read support.
@@ -289,7 +283,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
289 */ 283 */
290 if (file->f_mode & FMODE_READ) { 284 if (file->f_mode & FMODE_READ) {
291 if (!(inode->i_mode & S_IRUGO) || !ops->show) 285 if (!(inode->i_mode & S_IRUGO) || !ops->show)
292 goto err_mput; 286 goto err_out;
293 } 287 }
294 288
295 /* No error? Great, allocate a buffer for the file, and store it 289 /* No error? Great, allocate a buffer for the file, and store it
@@ -298,7 +292,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
298 error = -ENOMEM; 292 error = -ENOMEM;
299 buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL); 293 buffer = kzalloc(sizeof(struct sysfs_buffer), GFP_KERNEL);
300 if (!buffer) 294 if (!buffer)
301 goto err_mput; 295 goto err_out;
302 296
303 init_MUTEX(&buffer->sem); 297 init_MUTEX(&buffer->sem);
304 buffer->needs_read_fill = 1; 298 buffer->needs_read_fill = 1;
@@ -310,9 +304,7 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
310 sysfs_get(attr_sd); 304 sysfs_get(attr_sd);
311 return 0; 305 return 0;
312 306
313 err_mput: 307 err_out:
314 module_put(attr->owner);
315 err_sput:
316 sysfs_put_active_two(attr_sd); 308 sysfs_put_active_two(attr_sd);
317 return error; 309 return error;
318} 310}
@@ -320,12 +312,9 @@ static int sysfs_open_file(struct inode *inode, struct file *file)
320static int sysfs_release(struct inode * inode, struct file * filp) 312static int sysfs_release(struct inode * inode, struct file * filp)
321{ 313{
322 struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata; 314 struct sysfs_dirent *attr_sd = filp->f_path.dentry->d_fsdata;
323 struct attribute *attr = attr_sd->s_elem.attr.attr;
324 struct sysfs_buffer *buffer = filp->private_data; 315 struct sysfs_buffer *buffer = filp->private_data;
325 316
326 sysfs_put(attr_sd); 317 sysfs_put(attr_sd);
327 /* After this point, attr should not be accessed. */
328 module_put(attr->owner);
329 318
330 if (buffer) { 319 if (buffer) {
331 if (buffer->page) 320 if (buffer->page)