From: Tejun Heo Date: Sat, 23 Nov 2013 22:21:47 +0000 (-0500) Subject: sysfs: make __sysfs_add_one() fail if the parent isn't a directory X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=ae2108ad32f5ca55e9895d5597e6552be1607569;p=deliverable%2Flinux.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index b3cf61dc57c1..98701c00b9b0 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c @@ -429,6 +429,9 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd, return -EINVAL; } + if (sysfs_type(parent_sd) != SYSFS_DIR) + return -EINVAL; + sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); sd->s_parent = sysfs_get(parent_sd);