From 23396180a9770df2c6a694bbb689c12bdf792f94 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Wed, 12 Oct 2011 22:01:34 +0000 Subject: sysfs: Remove support for tagged directories with untagged members. Now that /sys/class/net/bonding_masters is implemented as a tagged sysfs file we can remove support for untagged files in tagged directories. This change removes any ambiguity of what a NULL namespace value means. A NULL namespace parameter after this patch means that we are talking about an untagged sysfs dirent. This makes the sysfs code much less prone to mistakes when during maintenance. Signed-off-by: Eric W. Biederman Acked-by: Greg Kroah-Hartman Signed-off-by: David S. Miller --- fs/sysfs/dir.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'fs/sysfs/dir.c') diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index ea9120a830d..352d26d98c0 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c @@ -543,7 +543,7 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd, struct sysfs_dirent *sd; for (sd = parent_sd->s_dir.children; sd; sd = sd->s_sibling) { - if (ns && sd->s_ns && (sd->s_ns != ns)) + if (sd->s_ns != ns) continue; if (!strcmp(sd->s_name, name)) return sd; @@ -885,7 +885,7 @@ static struct sysfs_dirent *sysfs_dir_pos(const void *ns, while (pos && (ino > pos->s_ino)) pos = pos->s_sibling; } - while (pos && pos->s_ns && pos->s_ns != ns) + while (pos && pos->s_ns != ns) pos = pos->s_sibling; return pos; } @@ -896,7 +896,7 @@ static struct sysfs_dirent *sysfs_dir_next_pos(const void *ns, pos = sysfs_dir_pos(ns, parent_sd, ino, pos); if (pos) pos = pos->s_sibling; - while (pos && pos->s_ns && pos->s_ns != ns) + while (pos && pos->s_ns != ns) pos = pos->s_sibling; return pos; } -- cgit v1.2.3 From 903e21e2eea036f6947f523f732e28b33a63ed0f Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Wed, 12 Oct 2011 22:02:43 +0000 Subject: sysfs: Reject with a warning invalid uses of tagged directories. sysfs is a core piece of ifrastructure that many people use and few people have all of the rules in their head on how to use it correctly. Add warnings for people using tagged directories improperly to that any misuses can be caught and diagnosed quickly. A single inexpensive test in sysfs_find_dirent is almost sufficient to catch all possible misuses. An additional warning is needed in sysfs_add_dirent so that we actually fail when attempting to add an untagged dirent in a tagged directory. Signed-off-by: Eric W. Biederman Acked-by: Greg Kroah-Hartman Signed-off-by: David S. Miller --- fs/sysfs/dir.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'fs/sysfs/dir.c') diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 352d26d98c0..26f370a9b5c 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c @@ -384,6 +384,13 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) { struct sysfs_inode_attrs *ps_iattr; + if (!!sysfs_ns_type(acxt->parent_sd) != !!sd->s_ns) { + WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", + sysfs_ns_type(acxt->parent_sd)? "required": "invalid", + acxt->parent_sd->s_name, sd->s_name); + return -EINVAL; + } + if (sysfs_find_dirent(acxt->parent_sd, sd->s_ns, sd->s_name)) return -EEXIST; @@ -542,6 +549,13 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd, { struct sysfs_dirent *sd; + if (!!sysfs_ns_type(parent_sd) != !!ns) { + WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n", + sysfs_ns_type(parent_sd)? "required": "invalid", + parent_sd->s_name, name); + return NULL; + } + for (sd = parent_sd->s_dir.children; sd; sd = sd->s_sibling) { if (sd->s_ns != ns) continue; -- cgit v1.2.3