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

sysfs: make __sysfs_add_one() fail if the parent isn't a directory

Currently the kobject based interface guarantees that a parent
sysfs_dirent is always a directory; however, the planned kernfs
interface will be directly based on sysfs_dirents and the caller may
specify non-directory node as the parent. Add an explicit check in
__sysfs_add_one() so that such attempts fail with -EINVAL.

Signed-off-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Tejun Heo and committed by
Greg Kroah-Hartman
ae2108ad c84a3b27

+3
+3
fs/sysfs/dir.c
··· 429 429 return -EINVAL; 430 430 } 431 431 432 + if (sysfs_type(parent_sd) != SYSFS_DIR) 433 + return -EINVAL; 434 + 432 435 sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); 433 436 sd->s_parent = sysfs_get(parent_sd); 434 437