diff options
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index b502c7197ec0..fd4b6dc03d2d 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -444,14 +444,25 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type) | |||
444 | { | 444 | { |
445 | struct sysfs_dirent * parent_sd = dir->d_fsdata; | 445 | struct sysfs_dirent * parent_sd = dir->d_fsdata; |
446 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; | 446 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; |
447 | int error = -EEXIST; | 447 | struct sysfs_dirent *sd; |
448 | int error = 0; | ||
448 | 449 | ||
449 | mutex_lock(&dir->d_inode->i_mutex); | 450 | mutex_lock(&dir->d_inode->i_mutex); |
450 | if (!sysfs_dirent_exist(parent_sd, attr->name)) | ||
451 | error = sysfs_make_dirent(parent_sd, NULL, (void *)attr, | ||
452 | mode, type); | ||
453 | mutex_unlock(&dir->d_inode->i_mutex); | ||
454 | 451 | ||
452 | if (sysfs_dirent_exist(parent_sd, attr->name)) { | ||
453 | error = -EEXIST; | ||
454 | goto out_unlock; | ||
455 | } | ||
456 | |||
457 | sd = sysfs_new_dirent((void *)attr, mode, type); | ||
458 | if (!sd) { | ||
459 | error = -ENOMEM; | ||
460 | goto out_unlock; | ||
461 | } | ||
462 | sysfs_attach_dirent(sd, parent_sd, NULL); | ||
463 | |||
464 | out_unlock: | ||
465 | mutex_unlock(&dir->d_inode->i_mutex); | ||
455 | return error; | 466 | return error; |
456 | } | 467 | } |
457 | 468 | ||