diff options
author | Tejun Heo <tj@kernel.org> | 2013-11-23 17:21:47 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-11-27 16:14:43 -0500 |
commit | ae2108ad32f5ca55e9895d5597e6552be1607569 (patch) | |
tree | 29efed50ed5afcd4e2e49886ad281ba50b264fa8 | |
parent | c84a3b27798dfce928b867fa1c9f3c3fd66f0a31 (diff) |
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>
-rw-r--r-- | fs/sysfs/dir.c | 3 |
1 files changed, 3 insertions, 0 deletions
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, | |||
429 | return -EINVAL; | 429 | return -EINVAL; |
430 | } | 430 | } |
431 | 431 | ||
432 | if (sysfs_type(parent_sd) != SYSFS_DIR) | ||
433 | return -EINVAL; | ||
434 | |||
432 | sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); | 435 | sd->s_hash = sysfs_name_hash(sd->s_name, sd->s_ns); |
433 | sd->s_parent = sysfs_get(parent_sd); | 436 | sd->s_parent = sysfs_get(parent_sd); |
434 | 437 | ||