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

sysfs: fix bugs in sysfs_rename/move_dir()

sysfs_rename/move_dir() have the following bugs.

- On dentry lookup failure, kfree() is called on ERR_PTR() value.
- sysfs_move_dir() has an extra dput() on success path.

Fix them.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Tejun Heo and committed by
Linus Torvalds
456ef155 e49452c6

+3 -1
+3 -1
fs/sysfs/dir.c
··· 783 783 old_dentry = sysfs_get_dentry(sd); 784 784 if (IS_ERR(old_dentry)) { 785 785 error = PTR_ERR(old_dentry); 786 + old_dentry = NULL; 786 787 goto out; 787 788 } 788 789 ··· 851 850 old_dentry = sysfs_get_dentry(sd); 852 851 if (IS_ERR(old_dentry)) { 853 852 error = PTR_ERR(old_dentry); 853 + old_dentry = NULL; 854 854 goto out; 855 855 } 856 856 old_parent = old_dentry->d_parent; ··· 859 857 new_parent = sysfs_get_dentry(new_parent_sd); 860 858 if (IS_ERR(new_parent)) { 861 859 error = PTR_ERR(new_parent); 860 + new_parent = NULL; 862 861 goto out; 863 862 } 864 863 ··· 883 880 error = 0; 884 881 d_add(new_dentry, NULL); 885 882 d_move(old_dentry, new_dentry); 886 - dput(new_dentry); 887 883 888 884 /* Remove from old parent's list and insert into new parent's list. */ 889 885 sysfs_unlink_sibling(sd);