Merge branch 'for-davem' of git://git.kernel.org/pub/scm/linux/kernel/git/linville...
[pandora-kernel.git] / kernel / module.c
index 14b8e82..2c93276 100644 (file)
 #define CREATE_TRACE_POINTS
 #include <trace/events/module.h>
 
-#if 0
-#define DEBUGP printk
-#else
-#define DEBUGP(fmt , a...)
-#endif
-
 #ifndef ARCH_SHF_SMALL
 #define ARCH_SHF_SMALL 0
 #endif
@@ -409,7 +403,7 @@ const struct kernel_symbol *find_symbol(const char *name,
                return fsa.sym;
        }
 
-       DEBUGP("Failed to find symbol %s\n", name);
+       pr_debug("Failed to find symbol %s\n", name);
        return NULL;
 }
 EXPORT_SYMBOL_GPL(find_symbol);
@@ -599,11 +593,11 @@ static int already_uses(struct module *a, struct module *b)
 
        list_for_each_entry(use, &b->source_list, source_list) {
                if (use->source == a) {
-                       DEBUGP("%s uses %s!\n", a->name, b->name);
+                       pr_debug("%s uses %s!\n", a->name, b->name);
                        return 1;
                }
        }
-       DEBUGP("%s does not use %s!\n", a->name, b->name);
+       pr_debug("%s does not use %s!\n", a->name, b->name);
        return 0;
 }
 
@@ -618,7 +612,7 @@ static int add_module_usage(struct module *a, struct module *b)
 {
        struct module_use *use;
 
-       DEBUGP("Allocating new usage for %s.\n", a->name);
+       pr_debug("Allocating new usage for %s.\n", a->name);
        use = kmalloc(sizeof(*use), GFP_ATOMIC);
        if (!use) {
                printk(KERN_WARNING "%s: out of memory loading\n", a->name);
@@ -662,7 +656,7 @@ static void module_unload_free(struct module *mod)
        mutex_lock(&module_mutex);
        list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) {
                struct module *i = use->target;
-               DEBUGP("%s unusing %s\n", mod->name, i->name);
+               pr_debug("%s unusing %s\n", mod->name, i->name);
                module_put(i);
                list_del(&use->source_list);
                list_del(&use->target_list);
@@ -760,7 +754,7 @@ static void wait_for_zero_refcount(struct module *mod)
        /* Since we might sleep for some time, release the mutex first */
        mutex_unlock(&module_mutex);
        for (;;) {
-               DEBUGP("Looking at refcount...\n");
+               pr_debug("Looking at refcount...\n");
                set_current_state(TASK_UNINTERRUPTIBLE);
                if (module_refcount(mod) == 0)
                        break;
@@ -803,7 +797,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
        if (mod->state != MODULE_STATE_LIVE) {
                /* FIXME: if (force), slam module count and wake up
                    waiter --RR */
-               DEBUGP("%s already dying\n", mod->name);
+               pr_debug("%s already dying\n", mod->name);
                ret = -EBUSY;
                goto out;
        }
@@ -906,10 +900,8 @@ static ssize_t show_refcnt(struct module_attribute *mattr,
        return sprintf(buffer, "%lu\n", module_refcount(mk->mod));
 }
 
-static struct module_attribute refcnt = {
-       .attr = { .name = "refcnt", .mode = 0444 },
-       .show = show_refcnt,
-};
+static struct module_attribute modinfo_refcnt =
+       __ATTR(refcnt, 0444, show_refcnt, NULL);
 
 void module_put(struct module *module)
 {
@@ -950,6 +942,26 @@ static inline int module_unload_init(struct module *mod)
 }
 #endif /* CONFIG_MODULE_UNLOAD */
 
+static size_t module_flags_taint(struct module *mod, char *buf)
+{
+       size_t l = 0;
+
+       if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
+               buf[l++] = 'P';
+       if (mod->taints & (1 << TAINT_OOT_MODULE))
+               buf[l++] = 'O';
+       if (mod->taints & (1 << TAINT_FORCED_MODULE))
+               buf[l++] = 'F';
+       if (mod->taints & (1 << TAINT_CRAP))
+               buf[l++] = 'C';
+       /*
+        * TAINT_FORCED_RMMOD: could be added.
+        * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
+        * apply to modules.
+        */
+       return l;
+}
+
 static ssize_t show_initstate(struct module_attribute *mattr,
                              struct module_kobject *mk, char *buffer)
 {
@@ -969,10 +981,8 @@ static ssize_t show_initstate(struct module_attribute *mattr,
        return sprintf(buffer, "%s\n", state);
 }
 
-static struct module_attribute initstate = {
-       .attr = { .name = "initstate", .mode = 0444 },
-       .show = show_initstate,
-};
+static struct module_attribute modinfo_initstate =
+       __ATTR(initstate, 0444, show_initstate, NULL);
 
 static ssize_t store_uevent(struct module_attribute *mattr,
                            struct module_kobject *mk,
@@ -985,18 +995,50 @@ static ssize_t store_uevent(struct module_attribute *mattr,
        return count;
 }
 
-struct module_attribute module_uevent = {
-       .attr = { .name = "uevent", .mode = 0200 },
-       .store = store_uevent,
-};
+struct module_attribute module_uevent =
+       __ATTR(uevent, 0200, NULL, store_uevent);
+
+static ssize_t show_coresize(struct module_attribute *mattr,
+                            struct module_kobject *mk, char *buffer)
+{
+       return sprintf(buffer, "%u\n", mk->mod->core_size);
+}
+
+static struct module_attribute modinfo_coresize =
+       __ATTR(coresize, 0444, show_coresize, NULL);
+
+static ssize_t show_initsize(struct module_attribute *mattr,
+                            struct module_kobject *mk, char *buffer)
+{
+       return sprintf(buffer, "%u\n", mk->mod->init_size);
+}
+
+static struct module_attribute modinfo_initsize =
+       __ATTR(initsize, 0444, show_initsize, NULL);
+
+static ssize_t show_taint(struct module_attribute *mattr,
+                         struct module_kobject *mk, char *buffer)
+{
+       size_t l;
+
+       l = module_flags_taint(mk->mod, buffer);
+       buffer[l++] = '\n';
+       return l;
+}
+
+static struct module_attribute modinfo_taint =
+       __ATTR(taint, 0444, show_taint, NULL);
 
 static struct module_attribute *modinfo_attrs[] = {
+       &module_uevent,
        &modinfo_version,
        &modinfo_srcversion,
-       &initstate,
-       &module_uevent,
+       &modinfo_initstate,
+       &modinfo_coresize,
+       &modinfo_initsize,
+       &modinfo_taint,
 #ifdef CONFIG_MODULE_UNLOAD
-       &refcnt,
+       &modinfo_refcnt,
 #endif
        NULL,
 };
@@ -1056,7 +1098,7 @@ static int check_version(Elf_Shdr *sechdrs,
 
                if (versions[i].crc == maybe_relocated(*crc, crc_owner))
                        return 1;
-               DEBUGP("Found checksum %lX vs module %lX\n",
+               pr_debug("Found checksum %lX vs module %lX\n",
                       maybe_relocated(*crc, crc_owner), versions[i].crc);
                goto bad_version;
        }
@@ -1833,7 +1875,7 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
                case SHN_COMMON:
                        /* We compiled with -fno-common.  These are not
                           supposed to happen.  */
-                       DEBUGP("Common symbol: %s\n", name);
+                       pr_debug("Common symbol: %s\n", name);
                        printk("%s: please compile with -fno-common\n",
                               mod->name);
                        ret = -ENOEXEC;
@@ -1841,7 +1883,7 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
 
                case SHN_ABS:
                        /* Don't need to do anything */
-                       DEBUGP("Absolute symbol: 0x%08lx\n",
+                       pr_debug("Absolute symbol: 0x%08lx\n",
                               (long)sym[i].st_value);
                        break;
 
@@ -1965,7 +2007,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
        for (i = 0; i < info->hdr->e_shnum; i++)
                info->sechdrs[i].sh_entsize = ~0UL;
 
-       DEBUGP("Core section allocation order:\n");
+       pr_debug("Core section allocation order:\n");
        for (m = 0; m < ARRAY_SIZE(masks); ++m) {
                for (i = 0; i < info->hdr->e_shnum; ++i) {
                        Elf_Shdr *s = &info->sechdrs[i];
@@ -1977,7 +2019,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
                            || strstarts(sname, ".init"))
                                continue;
                        s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
-                       DEBUGP("\t%s\n", name);
+                       pr_debug("\t%s\n", sname);
                }
                switch (m) {
                case 0: /* executable */
@@ -1994,7 +2036,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
                }
        }
 
-       DEBUGP("Init section allocation order:\n");
+       pr_debug("Init section allocation order:\n");
        for (m = 0; m < ARRAY_SIZE(masks); ++m) {
                for (i = 0; i < info->hdr->e_shnum; ++i) {
                        Elf_Shdr *s = &info->sechdrs[i];
@@ -2007,7 +2049,7 @@ static void layout_sections(struct module *mod, struct load_info *info)
                                continue;
                        s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
                                         | INIT_OFFSET_MASK);
-                       DEBUGP("\t%s\n", sname);
+                       pr_debug("\t%s\n", sname);
                }
                switch (m) {
                case 0: /* executable */
@@ -2195,7 +2237,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
        symsect->sh_flags |= SHF_ALLOC;
        symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
                                         info->index.sym) | INIT_OFFSET_MASK;
-       DEBUGP("\t%s\n", info->secstrings + symsect->sh_name);
+       pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
 
        src = (void *)info->hdr + symsect->sh_offset;
        nsrc = symsect->sh_size / sizeof(*src);
@@ -2216,7 +2258,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
        strsect->sh_flags |= SHF_ALLOC;
        strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
                                         info->index.str) | INIT_OFFSET_MASK;
-       DEBUGP("\t%s\n", info->secstrings + strsect->sh_name);
+       pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
 }
 
 static void add_kallsyms(struct module *mod, const struct load_info *info)
@@ -2618,7 +2660,7 @@ static int move_module(struct module *mod, struct load_info *info)
        mod->module_init = ptr;
 
        /* Transfer each section which specifies SHF_ALLOC */
-       DEBUGP("final section addresses:\n");
+       pr_debug("final section addresses:\n");
        for (i = 0; i < info->hdr->e_shnum; i++) {
                void *dest;
                Elf_Shdr *shdr = &info->sechdrs[i];
@@ -2636,8 +2678,8 @@ static int move_module(struct module *mod, struct load_info *info)
                        memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
                /* Update sh_addr to point to copy in image. */
                shdr->sh_addr = (unsigned long)dest;
-               DEBUGP("\t0x%lx %s\n",
-                      shdr->sh_addr, info->secstrings + shdr->sh_name);
+               pr_debug("\t0x%lx %s\n",
+                        (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
        }
 
        return 0;
@@ -2798,7 +2840,7 @@ static struct module *load_module(void __user *umod,
        struct module *mod;
        long err;
 
-       DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
+       pr_debug("load_module: umod=%p, len=%lu, uargs=%p\n",
               umod, len, uargs);
 
        /* Copy in the blobs from userspace, check they are vaguely sane. */
@@ -3242,20 +3284,7 @@ static char *module_flags(struct module *mod, char *buf)
            mod->state == MODULE_STATE_GOING ||
            mod->state == MODULE_STATE_COMING) {
                buf[bx++] = '(';
-               if (mod->taints & (1 << TAINT_PROPRIETARY_MODULE))
-                       buf[bx++] = 'P';
-               else if (mod->taints & (1 << TAINT_OOT_MODULE))
-                       buf[bx++] = 'O';
-               if (mod->taints & (1 << TAINT_FORCED_MODULE))
-                       buf[bx++] = 'F';
-               if (mod->taints & (1 << TAINT_CRAP))
-                       buf[bx++] = 'C';
-               /*
-                * TAINT_FORCED_RMMOD: could be added.
-                * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't
-                * apply to modules.
-                */
-
+               bx += module_flags_taint(mod, buf + bx);
                /* Show a - for module-is-being-unloaded */
                if (mod->state == MODULE_STATE_GOING)
                        buf[bx++] = '-';