diff options
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r-- | fs/sysfs/file.c | 41 |
1 files changed, 9 insertions, 32 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index f5ea4680f15f..dc30d9e31683 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -579,46 +579,23 @@ EXPORT_SYMBOL_GPL(sysfs_add_file_to_group); | |||
579 | */ | 579 | */ |
580 | int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode) | 580 | int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode) |
581 | { | 581 | { |
582 | struct sysfs_dirent *victim_sd = NULL; | 582 | struct sysfs_dirent *sd; |
583 | struct dentry *victim = NULL; | ||
584 | struct inode * inode; | ||
585 | struct iattr newattrs; | 583 | struct iattr newattrs; |
586 | int rc; | 584 | int rc; |
587 | 585 | ||
588 | rc = -ENOENT; | 586 | mutex_lock(&sysfs_mutex); |
589 | victim_sd = sysfs_get_dirent(kobj->sd, attr->name); | ||
590 | if (!victim_sd) | ||
591 | goto out; | ||
592 | 587 | ||
593 | mutex_lock(&sysfs_rename_mutex); | 588 | rc = -ENOENT; |
594 | victim = sysfs_get_dentry(victim_sd); | 589 | sd = sysfs_find_dirent(kobj->sd, attr->name); |
595 | mutex_unlock(&sysfs_rename_mutex); | 590 | if (!sd) |
596 | if (IS_ERR(victim)) { | ||
597 | rc = PTR_ERR(victim); | ||
598 | victim = NULL; | ||
599 | goto out; | 591 | goto out; |
600 | } | ||
601 | |||
602 | inode = victim->d_inode; | ||
603 | |||
604 | mutex_lock(&inode->i_mutex); | ||
605 | 592 | ||
606 | newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); | 593 | newattrs.ia_mode = (mode & S_IALLUGO) | (sd->s_mode & ~S_IALLUGO); |
607 | newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; | 594 | newattrs.ia_valid = ATTR_MODE; |
608 | newattrs.ia_ctime = current_fs_time(inode->i_sb); | 595 | rc = sysfs_sd_setattr(sd, &newattrs); |
609 | rc = sysfs_setattr(victim, &newattrs); | ||
610 | 596 | ||
611 | if (rc == 0) { | ||
612 | fsnotify_change(victim, newattrs.ia_valid); | ||
613 | mutex_lock(&sysfs_mutex); | ||
614 | victim_sd->s_mode = newattrs.ia_mode; | ||
615 | mutex_unlock(&sysfs_mutex); | ||
616 | } | ||
617 | |||
618 | mutex_unlock(&inode->i_mutex); | ||
619 | out: | 597 | out: |
620 | dput(victim); | 598 | mutex_unlock(&sysfs_mutex); |
621 | sysfs_put(victim_sd); | ||
622 | return rc; | 599 | return rc; |
623 | } | 600 | } |
624 | EXPORT_SYMBOL_GPL(sysfs_chmod_file); | 601 | EXPORT_SYMBOL_GPL(sysfs_chmod_file); |