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.
Unified · Split
| @@ -762,12 +762,15 @@ static int sysfs_count_nlink(struct sysfs_dirent *sd) · 761 unmodified lines | ||
| 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; |
| 770 | 771 | |
| 772 | + mutex_lock(&sysfs_mutex); | |
| 773 | + | |
| 771 | 774 | for (sd = parent_sd->s_children; sd; sd = sd->s_sibling) { |
| 772 | 775 | if (sysfs_type(sd) && |
| 773 | 776 | !strcmp(sd->s_name, dentry->d_name.name)) { |
| @@ -778,14 +781,14 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry, · 4 unmodified lines | ||
| 778 | 781 | |
| 779 | 782 | /* no such entry */ |
| 780 | 783 | if (!found) |
| 781 | − return NULL; | |
| 784 | + goto out_unlock; | |
| 782 | 785 | |
| 783 | 786 | /* attach dentry and inode */ |
| 784 | 787 | inode = sysfs_get_inode(sd); |
| 785 | − if (!inode) | |
| 786 | − return ERR_PTR(-ENOMEM); | |
| 787 | − | |
| 788 | − mutex_lock(&sysfs_mutex); | |
| 788 | + if (!inode) { | |
| 789 | + ret = ERR_PTR(-ENOMEM); | |
| 790 | + goto out_unlock; | |
| 791 | + } | |
| 789 | 792 | |
| 790 | 793 | if (inode->i_state & I_NEW) { |
| 791 | 794 | /* initialize inode according to type */ |
| @@ -815,9 +818,9 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry, · 23 unmodified lines | ||
| 815 | 818 | sysfs_instantiate(dentry, inode); |
| 816 | 819 | sysfs_attach_dentry(sd, dentry); |
| 817 | 820 | |
| 821 | + out_unlock: | |
| 818 | 822 | mutex_unlock(&sysfs_mutex); |
| 819 | − | |
| 820 | − return NULL; | |
| 823 | + return ret; | |
| 821 | 824 | } |
| 822 | 825 | |
| 823 | 826 | const struct inode_operations sysfs_dir_inode_operations = { |
| @@ -942,6 +945,8 @@ int sysfs_rename_dir(struct kobject *kobj, struct sysfs_dirent *new_parent_sd, · 118 unmodified lines | ||
| 942 | 945 | if (error) |
| 943 | 946 | goto out_drop; |
| 944 | 947 | |
| 948 | + mutex_lock(&sysfs_mutex); | |
| 949 | + | |
| 945 | 950 | dup_name = sd->s_name; |
| 946 | 951 | sd->s_name = new_name; |
| 947 | 952 | |
| @@ -949,8 +954,6 @@ int sysfs_rename_dir(struct kobject *kobj, struct sysfs_dirent *new_parent_sd, · 1 unmodified line | ||
| 949 | 954 | d_add(new_dentry, NULL); |
| 950 | 955 | d_move(sd->s_dentry, new_dentry); |
| 951 | 956 | |
| 952 | − mutex_lock(&sysfs_mutex); | |
| 953 | − | |
| 954 | 957 | sysfs_unlink_sibling(sd); |
| 955 | 958 | sysfs_get(new_parent_sd); |
| 956 | 959 | sysfs_put(sd->s_parent); |