diff options
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index 20703b9ee064..d0deed3e60b5 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -415,29 +415,28 @@ const struct file_operations sysfs_file_operations = { | |||
415 | int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, | 415 | int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, |
416 | int type) | 416 | int type) |
417 | { | 417 | { |
418 | struct dentry *dir = dir_sd->s_dentry; | ||
419 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; | 418 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; |
420 | struct sysfs_dirent *sd; | 419 | struct sysfs_dirent *sd; |
421 | int error = 0; | ||
422 | 420 | ||
423 | mutex_lock(&dir->d_inode->i_mutex); | 421 | sd = sysfs_new_dirent(attr->name, mode, type); |
422 | if (!sd) | ||
423 | return -ENOMEM; | ||
424 | sd->s_elem.attr.attr = (void *)attr; | ||
424 | 425 | ||
425 | if (sysfs_find_dirent(dir_sd, attr->name)) { | 426 | mutex_lock(&sysfs_mutex); |
426 | error = -EEXIST; | ||
427 | goto out_unlock; | ||
428 | } | ||
429 | 427 | ||
430 | sd = sysfs_new_dirent(attr->name, mode, type); | 428 | if (!sysfs_find_dirent(dir_sd, attr->name)) { |
431 | if (!sd) { | 429 | sysfs_attach_dirent(sd, dir_sd, NULL); |
432 | error = -ENOMEM; | 430 | sd = NULL; |
433 | goto out_unlock; | ||
434 | } | 431 | } |
435 | sd->s_elem.attr.attr = (void *)attr; | ||
436 | sysfs_attach_dirent(sd, dir_sd, NULL); | ||
437 | 432 | ||
438 | out_unlock: | 433 | mutex_unlock(&sysfs_mutex); |
439 | mutex_unlock(&dir->d_inode->i_mutex); | 434 | |
440 | return error; | 435 | if (sd) { |
436 | sysfs_put(sd); | ||
437 | return -EEXIST; | ||
438 | } | ||
439 | return 0; | ||
441 | } | 440 | } |
442 | 441 | ||
443 | 442 | ||