diff options
author | Tejun Heo <htejun@gmail.com> | 2007-06-13 15:27:23 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-11 19:09:08 -0400 |
commit | 3007e997de91ec59af39a3f9c91595b31ae6e08b (patch) | |
tree | 4ed4df3ef3a249d2a4b562e36876fc8d4a3fabd9 /fs/sysfs/file.c | |
parent | 5f9953237f684ea1778adb9d26162da00b282225 (diff) |
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.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 | ||