diff options
author | Tejun Heo <htejun@gmail.com> | 2007-06-13 14:45:14 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-11 19:09:04 -0400 |
commit | a26cd7226c24c3be5dd5f48a74832fe64beb8489 (patch) | |
tree | 0dfb4a15d800494a06a4ddf83c4d33812c404fac /fs/sysfs/file.c | |
parent | 996b73764e9bb9d5e751fd15b130ba38637d66a8 (diff) |
sysfs: consolidate sysfs_dirent creation functions
Currently there are four functions to create sysfs_dirent -
__sysfs_new_dirent(), sysfs_new_dirent(), __sysfs_make_dirent() and
sysfs_make_dirent(). Other than sysfs_make_dirent(), no function has
two users if calls to implement other functions are excluded.
This patch consolidates sysfs_dirent creation functions into the
following two.
* sysfs_new_dirent() : allocate and initialize
* sysfs_attach_dirent() : attach to sysfs_dirent hierarchy and/or
associate with dentry
This simplifies interface and gives callers more flexibility. This is
in preparation of object reference simplification.
Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
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 | ||