[lkml]   [2013]   [Oct]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH 06/34] 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 <>
fs/sysfs/dir.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index de47ed3..bec4466 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -432,6 +432,9 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd,
struct sysfs_inode_attrs *ps_iattr;
int ret;

+ 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);


 \ /
  Last update: 2013-10-24 18:21    [W:0.214 / U:5.868 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site