summaryrefslogtreecommitdiff
path: root/fs/sysfs/file.c
diff options
context:
space:
mode:
authorTejun Heo <htejun@gmail.com>2007-06-13 19:27:23 (GMT)
committerGreg Kroah-Hartman <gregkh@suse.de>2007-07-11 23:09:08 (GMT)
commit3007e997de91ec59af39a3f9c91595b31ae6e08b (patch)
tree4ed4df3ef3a249d2a4b562e36876fc8d4a3fabd9 /fs/sysfs/file.c
parent5f9953237f684ea1778adb9d26162da00b282225 (diff)
downloadlinux-3007e997de91ec59af39a3f9c91595b31ae6e08b.tar.xz
sysfs: use sysfs_mutex to protect the sysfs_dirent tree
As kobj sysfs dentries and inodes are gonna be made reclaimable, i_mutex can't be used to protect sysfs_dirent tree. Use sysfs_mutex globally instead. As the whole tree is protected with sysfs_mutex, there is no reason to keep sysfs_rename_sem. Drop it. While at it, add docbook comments to functions which require sysfs_mutex locking. 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.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 20703b9..d0deed3 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -415,29 +415,28 @@ const struct file_operations sysfs_file_operations = {
int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
int type)
{
- struct dentry *dir = dir_sd->s_dentry;
umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
struct sysfs_dirent *sd;
- int error = 0;
- mutex_lock(&dir->d_inode->i_mutex);
+ sd = sysfs_new_dirent(attr->name, mode, type);
+ if (!sd)
+ return -ENOMEM;
+ sd->s_elem.attr.attr = (void *)attr;
- if (sysfs_find_dirent(dir_sd, attr->name)) {
- error = -EEXIST;
- goto out_unlock;
- }
+ mutex_lock(&sysfs_mutex);
- sd = sysfs_new_dirent(attr->name, mode, type);
- if (!sd) {
- error = -ENOMEM;
- goto out_unlock;
+ if (!sysfs_find_dirent(dir_sd, attr->name)) {
+ sysfs_attach_dirent(sd, dir_sd, NULL);
+ sd = NULL;
}
- sd->s_elem.attr.attr = (void *)attr;
- sysfs_attach_dirent(sd, dir_sd, NULL);
- out_unlock:
- mutex_unlock(&dir->d_inode->i_mutex);
- return error;
+ mutex_unlock(&sysfs_mutex);
+
+ if (sd) {
+ sysfs_put(sd);
+ return -EEXIST;
+ }
+ return 0;
}