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>
This commit is contained in:
Tejun Heo
2007-06-14 03:45:14 +09:00
committed by Greg Kroah-Hartman
parent 996b73764e
commit a26cd7226c
4 changed files with 50 additions and 67 deletions

View File

@@ -444,14 +444,25 @@ int sysfs_add_file(struct dentry * dir, const struct attribute * attr, int type)
{
struct sysfs_dirent * parent_sd = dir->d_fsdata;
umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
int error = -EEXIST;
struct sysfs_dirent *sd;
int error = 0;
mutex_lock(&dir->d_inode->i_mutex);
if (!sysfs_dirent_exist(parent_sd, attr->name))
error = sysfs_make_dirent(parent_sd, NULL, (void *)attr,
mode, type);
mutex_unlock(&dir->d_inode->i_mutex);
if (sysfs_dirent_exist(parent_sd, attr->name)) {
error = -EEXIST;
goto out_unlock;
}
sd = sysfs_new_dirent((void *)attr, mode, type);
if (!sd) {
error = -ENOMEM;
goto out_unlock;
}
sysfs_attach_dirent(sd, parent_sd, NULL);
out_unlock:
mutex_unlock(&dir->d_inode->i_mutex);
return error;
}