diff options
author | Dave Hansen <haveblue@us.ibm.com> | 2006-03-16 17:30:16 -0800 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2008-12-03 09:14:37 +1100 |
commit | 19aef85cbaf1eb23bee7cd21db11c72bae25ba7e (patch) | |
tree | 63f1a14375cceb4009c028182a0087d4feb46cee /lib | |
parent | 9de757af0b494f2829b841c8fdb821069215696b (diff) |
warn when statically-allocated kobjects are used
One of the top ten sysfs problems is that users use statically
allocated kobjects. This patch reminds them that this is a
naughty thing.
One _really_ nice thing this patch does, is us the kallsyms
mechanism to print out exactly which symbol is being complained
about:
The kobject at, or inside 'statickobj.2'@(0xc040d020) is not dynamically allocated.
This patch replaces the previous implementation's use of a
_sdata symbol in favor of using kallsyms_lookup(). If a
kobject's address is a resolvable symbol, then it isn't
dynamically allocated.
The one exception to this is init symbols. The patch also
checks to see whether __init memory has been freed and if
it has will allow kobjects in those sections.
Signed-off-by: Dave Hansen <haveblue@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/kobject.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index 0487d1f64806..2fded6d8ca54 100644 --- a/lib/kobject.c +++ b/lib/kobject.c @@ -17,6 +17,55 @@ #include <linux/module.h> #include <linux/stat.h> #include <linux/slab.h> +#include <linux/kallsyms.h> +#include <asm-generic/sections.h> + +#ifdef CONFIG_X86_32 +static int ptr_in_range(void *ptr, void *start, void *end) +{ + /* + * This should hopefully get rid of causing warnings + * if the architecture did not set one of the section + * variables up. + */ + if (start >= end) + return 0; + + if ((ptr >= start) && (ptr < end)) + return 1; + return 0; +} + +static void verify_dynamic_kobject_allocation(struct kobject *kobj) +{ + char namebuf[KSYM_NAME_LEN]; + const char *ret; + + ret = kallsyms_lookup((unsigned long)kobj, NULL, NULL, NULL, namebuf); + /* + * This is the X86_32-only part of this function. + * This is here because it is valid to have a kobject + * in an __init section, but only after those + * sections have been freed back to the dynamic pool. + */ + if (!initmem_now_dynamic && + ptr_in_range(kobj, __init_begin, __init_end)) + goto out; + if (!ret || !strlen(ret)) + goto out; + pr_debug("---- begin silly warning ----\n"); + pr_debug("This is a janitorial warning, not a kernel bug.\n"); + pr_debug("The kobject '%s', at, or inside '%s'@(0x%p) is not " + "dynamically allocated.\n", kobject_name(kobj), namebuf, kobj); + pr_debug("kobjects must be dynamically allocated, not static\n"); + /* dump_stack(); */ + pr_debug("---- end silly warning ----\n"); +out: + return; +} +#else +static void verify_dynamic_kobject_allocation(struct kobject *kobj) { } +#endif /* * populate_dir - populate directory with attributes. @@ -282,6 +331,7 @@ void kobject_init(struct kobject *kobj, struct kobj_type *ktype) "object, something is seriously wrong.\n", kobj); dump_stack(); } + verify_dynamic_kobject_allocation(kobj); kobject_init_internal(kobj); kobj->ktype = ktype; |