Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sysfs: fix locking in sysfs_lookup() and sysfs_rename_dir()

sd children list walking in sysfs_lookup() and sd renaming in
sysfs_rename_dir() were left out during i_mutex -> sysfs_mutex
conversion. Fix them.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Acked-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Tejun Heo and committed by
Greg Kroah-Hartman
6cb52147 74e8f346

+12 -9
+12 -9
fs/sysfs/dir.c
··· 762 762 static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry, 763 763 struct nameidata *nd) 764 764 { 765 + struct dentry *ret = NULL; 765 766 struct sysfs_dirent * parent_sd = dentry->d_parent->d_fsdata; 766 767 struct sysfs_dirent * sd; 767 768 struct bin_attribute *bin_attr; 768 769 struct inode *inode; 769 770 int found = 0; 771 + 772 + mutex_lock(&sysfs_mutex); 770 773 771 774 for (sd = parent_sd->s_children; sd; sd = sd->s_sibling) { 772 775 if (sysfs_type(sd) && ··· 781 778 782 779 /* no such entry */ 783 780 if (!found) 784 - return NULL; 781 + goto out_unlock; 785 782 786 783 /* attach dentry and inode */ 787 784 inode = sysfs_get_inode(sd); 788 - if (!inode) 789 - return ERR_PTR(-ENOMEM); 790 - 791 - mutex_lock(&sysfs_mutex); 785 + if (!inode) { 786 + ret = ERR_PTR(-ENOMEM); 787 + goto out_unlock; 788 + } 792 789 793 790 if (inode->i_state & I_NEW) { 794 791 /* initialize inode according to type */ ··· 818 815 sysfs_instantiate(dentry, inode); 819 816 sysfs_attach_dentry(sd, dentry); 820 817 818 + out_unlock: 821 819 mutex_unlock(&sysfs_mutex); 822 - 823 - return NULL; 820 + return ret; 824 821 } 825 822 826 823 const struct inode_operations sysfs_dir_inode_operations = { ··· 945 942 if (error) 946 943 goto out_drop; 947 944 945 + mutex_lock(&sysfs_mutex); 946 + 948 947 dup_name = sd->s_name; 949 948 sd->s_name = new_name; 950 949 951 950 /* move under the new parent */ 952 951 d_add(new_dentry, NULL); 953 952 d_move(sd->s_dentry, new_dentry); 954 - 955 - mutex_lock(&sysfs_mutex); 956 953 957 954 sysfs_unlink_sibling(sd); 958 955 sysfs_get(new_parent_sd);