Skip to content

Commit

Permalink
sysfs: make sysfs_lookup() return ERR_PTR(-ENOENT) on failed lookup
Browse files Browse the repository at this point in the history
sysfs tries to keep dcache a strict subset of sysfs_dirent tree by
shooting down dentries when a node is removed, that is, no negative
dentry for sysfs.  However, the lookup function returned NULL and thus
created negative dentries when the target node didn't exist.

Make sysfs_lookup() return ERR_PTR(-ENOENT) on lookup failure.  This
fixes the NULL dereference bug in sysfs_get_dentry() discovered by
bluetooth rfcomm device moving around.

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Tejun Heo authored and Linus Torvalds committed Jan 16, 2008
1 parent cbd9c88 commit e49452c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/sysfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,10 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
sd = sysfs_find_dirent(parent_sd, dentry->d_name.name);

/* no such entry */
if (!sd)
if (!sd) {
ret = ERR_PTR(-ENOENT);
goto out_unlock;
}

/* attach dentry and inode */
inode = sysfs_get_inode(sd);
Expand Down

0 comments on commit e49452c

Please sign in to comment.