]> err.no Git - linux-2.6/blobdiff - kernel/module.c
x86: change size of APICIDs from u8 to u16
[linux-2.6] / kernel / module.c
index 276abd7b7ff7cd5f978dffc91ae9f598b7d1ad4d..f6a4e721fd4907339dfbbca63d5081244697973f 100644 (file)
@@ -1230,6 +1230,7 @@ void module_remove_modinfo_attrs(struct module *mod)
 int mod_sysfs_init(struct module *mod)
 {
        int err;
+       struct kobject *kobj;
 
        if (!module_sysfs_initialized) {
                printk(KERN_ERR "%s: module sysfs not initialized\n",
@@ -1237,6 +1238,15 @@ int mod_sysfs_init(struct module *mod)
                err = -EINVAL;
                goto out;
        }
+
+       kobj = kset_find_obj(module_kset, mod->name);
+       if (kobj) {
+               printk(KERN_ERR "%s: module is already loaded\n", mod->name);
+               kobject_put(kobj);
+               err = -EINVAL;
+               goto out;
+       }
+
        mod->mkobj.mod = mod;
 
        memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj));
@@ -1293,6 +1303,17 @@ static void mod_kobject_remove(struct module *mod)
        kobject_put(&mod->mkobj.kobj);
 }
 
+/*
+ * link the module with the whole machine is stopped with interrupts off
+ * - this defends against kallsyms not taking locks
+ */
+static int __link_module(void *_mod)
+{
+       struct module *mod = _mod;
+       list_add(&mod->list, &modules);
+       return 0;
+}
+
 /*
  * unlink the module with the whole machine is stopped with interrupts off
  * - this defends against kallsyms not taking locks
@@ -1905,7 +1926,7 @@ static struct module *load_module(void __user *umod,
        set_license(mod, get_modinfo(sechdrs, infoindex, "license"));
 
        if (strcmp(mod->name, "ndiswrapper") == 0)
-               add_taint(TAINT_PROPRIETARY_MODULE);
+               add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
        if (strcmp(mod->name, "driverloader") == 0)
                add_taint_module(mod, TAINT_PROPRIETARY_MODULE);
 
@@ -2035,6 +2056,11 @@ static struct module *load_module(void __user *umod,
                printk(KERN_WARNING "%s: Ignoring obsolete parameters\n",
                       mod->name);
 
+       /* Now sew it into the lists so we can get lockdep and oops
+         * info during argument parsing.  Noone should access us, since
+         * strong_try_module_get() will fail. */
+       stop_machine_run(__link_module, mod, NR_CPUS);
+
        /* Size of section 0 is 0, so this works well if no params */
        err = parse_args(mod->name, mod->args,
                         (struct kernel_param *)
@@ -2043,7 +2069,7 @@ static struct module *load_module(void __user *umod,
                         / sizeof(struct kernel_param),
                         NULL);
        if (err < 0)
-               goto arch_cleanup;
+               goto unlink;
 
        err = mod_sysfs_setup(mod,
                              (struct kernel_param *)
@@ -2051,7 +2077,7 @@ static struct module *load_module(void __user *umod,
                              sechdrs[setupindex].sh_size
                              / sizeof(struct kernel_param));
        if (err < 0)
-               goto arch_cleanup;
+               goto unlink;
        add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
        add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs);
 
@@ -2066,7 +2092,8 @@ static struct module *load_module(void __user *umod,
        /* Done! */
        return mod;
 
- arch_cleanup:
+ unlink:
+       stop_machine_run(__unlink_module, mod, NR_CPUS);
        module_arch_cleanup(mod);
  cleanup:
        kobject_del(&mod->mkobj.kobj);
@@ -2091,17 +2118,6 @@ static struct module *load_module(void __user *umod,
        goto free_hdr;
 }
 
-/*
- * link the module with the whole machine is stopped with interrupts off
- * - this defends against kallsyms not taking locks
- */
-static int __link_module(void *_mod)
-{
-       struct module *mod = _mod;
-       list_add(&mod->list, &modules);
-       return 0;
-}
-
 /* This is where the real work happens */
 asmlinkage long
 sys_init_module(void __user *umod,
@@ -2126,10 +2142,6 @@ sys_init_module(void __user *umod,
                return PTR_ERR(mod);
        }
 
-       /* Now sew it into the lists.  They won't access us, since
-           strong_try_module_get() will fail. */
-       stop_machine_run(__link_module, mod, NR_CPUS);
-
        /* Drop lock so they can recurse */
        mutex_unlock(&module_mutex);
 
@@ -2228,14 +2240,13 @@ static const char *get_ksymbol(struct module *mod,
        return mod->strtab + mod->symtab[best].st_name;
 }
 
-/* For kallsyms to ask for address resolution.  NULL means not found.
-   We don't lock, as this is used for oops resolution and races are a
-   lesser concern. */
-/* FIXME: Risky: returns a pointer into a module w/o lock */
-const char *module_address_lookup(unsigned long addr,
-                                 unsigned long *size,
-                                 unsigned long *offset,
-                                 char **modname)
+/* For kallsyms to ask for address resolution.  NULL means not found.  Careful
+ * not to lock to avoid deadlock on oopses, simply disable preemption. */
+char *module_address_lookup(unsigned long addr,
+                           unsigned long *size,
+                           unsigned long *offset,
+                           char **modname,
+                           char *namebuf)
 {
        struct module *mod;
        const char *ret = NULL;
@@ -2250,8 +2261,13 @@ const char *module_address_lookup(unsigned long addr,
                        break;
                }
        }
+       /* Make a copy in here where it's safe */
+       if (ret) {
+               strncpy(namebuf, ret, KSYM_NAME_LEN - 1);
+               ret = namebuf;
+       }
        preempt_enable();
-       return ret;
+       return (char *)ret;
 }
 
 int lookup_module_symbol_name(unsigned long addr, char *symname)