aboutsummaryrefslogtreecommitdiffstats
path: root/driver
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2006-05-10 14:11:51 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2006-05-10 14:11:51 -0700
commit406ba1fde26d6d9299d88db0e8412e5a44366d1c (patch)
treebbbc579042244c21d60c84a10084b057f04066d2 /driver
parentd4f086f6fe4a9d7921f8515c598446baad2b456a (diff)
downloadpatches-406ba1fde26d6d9299d88db0e8412e5a44366d1c.tar.gz
move kobject warn patch to driver dir
Diffstat (limited to 'driver')
-rw-r--r--driver/warn-when-statically-allocated-kobjects-are-used.patch108
1 files changed, 108 insertions, 0 deletions
diff --git a/driver/warn-when-statically-allocated-kobjects-are-used.patch b/driver/warn-when-statically-allocated-kobjects-are-used.patch
new file mode 100644
index 0000000000000..80424ad46b0a7
--- /dev/null
+++ b/driver/warn-when-statically-allocated-kobjects-are-used.patch
@@ -0,0 +1,108 @@
+From haveblue@us.ibm.com Thu Mar 16 17:30:46 2006
+From: Dave Hansen <haveblue@us.ibm.com>
+Subject: warn when statically-allocated kobjects are used
+Cc: gregkh@suse.de, Dave Hansen <haveblue@us.ibm.com>
+Date: Thu, 16 Mar 2006 17:30:16 -0800
+Message-Id: <20060317013016.5C643E69@localhost.localdomain>
+
+
+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 devices_subsys+0x14/0x60 is not dynamically allocated.
+
+There are not very many architectures that actually place a
+_sdata or _data symbol in their vmlinux.lds.S. This patch
+causes link errors in all these cases. Is there an
+alternative symbol that we can use, or can we use weak
+symbols and detect them, so that they are at least skipped?
+
+Does kernel/kallsyms.c:is_kernel() do the trick, so that we
+don't need to use the asm-generic/sections.h variables at all?
+
+
+Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
+
+
+---
+ arch/i386/kernel/vmlinux.lds.S | 2 ++
+ lib/kobject.c | 38 ++++++++++++++++++++++++++++++++++++++
+ 2 files changed, 40 insertions(+)
+
+--- gregkh-2.6.orig/arch/i386/kernel/vmlinux.lds.S
++++ gregkh-2.6/arch/i386/kernel/vmlinux.lds.S
+@@ -35,6 +35,8 @@ SECTIONS
+ __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { *(__ex_table) }
+ __stop___ex_table = .;
+
++ _sdata = .; /* End of text section */
++
+ RODATA
+
+ /* writeable */
+--- gregkh-2.6.orig/lib/kobject.c
++++ gregkh-2.6/lib/kobject.c
+@@ -15,6 +15,8 @@
+ #include <linux/module.h>
+ #include <linux/stat.h>
+ #include <linux/slab.h>
++#include <linux/kallsyms.h>
++#include <asm-generic/sections.h>
+
+ /**
+ * populate_dir - populate directory with attributes.
+@@ -120,6 +122,41 @@ char *kobject_get_path(struct kobject *k
+ return path;
+ }
+
++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)
++{
++ if (ptr_in_range(kobj, &_sdata[0], &_edata[0]))
++ goto warn;
++ if (ptr_in_range(kobj, &__bss_start[0], &__bss_stop[0]))
++ goto warn;
++ return;
++warn:
++ pr_debug("---- begin silly warning ----\n");
++ pr_debug("This is a janitorial warning, not a kernel bug.\n");
++#ifdef CONFIG_DEBUG_KOBJECT
++ print_symbol("The kobject at, or inside %s is not dynamically allocated.\n",
++ (unsigned long)kobj);
++#endif
++ pr_debug("kobjects must be dynamically allocated, not static\n");
++ /* dump_stack(); */
++ pr_debug("---- end silly warning ----\n");
++}
++
++
+ /**
+ * kobject_init - initialize object.
+ * @kobj: object in question.
+@@ -127,6 +164,7 @@ char *kobject_get_path(struct kobject *k
+ void kobject_init(struct kobject * kobj)
+ {
+ WARN_ON(atomic_read(&kobj->kref.refcount));
++ verify_dynamic_kobject_allocation(kobj);
+ kref_init(&kobj->kref);
+ INIT_LIST_HEAD(&kobj->entry);
+ init_waitqueue_head(&kobj->poll);