diff options
Diffstat (limited to 'kernel/module.c')
-rw-r--r-- | kernel/module.c | 261 |
1 files changed, 113 insertions, 148 deletions
diff --git a/kernel/module.c b/kernel/module.c index c2e3e2e98801..bd60278ee703 100644 --- a/kernel/module.c +++ b/kernel/module.c | |||
@@ -47,8 +47,6 @@ | |||
47 | #include <asm/cacheflush.h> | 47 | #include <asm/cacheflush.h> |
48 | #include <linux/license.h> | 48 | #include <linux/license.h> |
49 | 49 | ||
50 | extern int module_sysfs_initialized; | ||
51 | |||
52 | #if 0 | 50 | #if 0 |
53 | #define DEBUGP printk | 51 | #define DEBUGP printk |
54 | #else | 52 | #else |
@@ -67,6 +65,9 @@ extern int module_sysfs_initialized; | |||
67 | static DEFINE_MUTEX(module_mutex); | 65 | static DEFINE_MUTEX(module_mutex); |
68 | static LIST_HEAD(modules); | 66 | static LIST_HEAD(modules); |
69 | 67 | ||
68 | /* Waiting for a module to finish initializing? */ | ||
69 | static DECLARE_WAIT_QUEUE_HEAD(module_wq); | ||
70 | |||
70 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); | 71 | static BLOCKING_NOTIFIER_HEAD(module_notify_list); |
71 | 72 | ||
72 | int register_module_notifier(struct notifier_block * nb) | 73 | int register_module_notifier(struct notifier_block * nb) |
@@ -86,8 +87,11 @@ EXPORT_SYMBOL(unregister_module_notifier); | |||
86 | static inline int strong_try_module_get(struct module *mod) | 87 | static inline int strong_try_module_get(struct module *mod) |
87 | { | 88 | { |
88 | if (mod && mod->state == MODULE_STATE_COMING) | 89 | if (mod && mod->state == MODULE_STATE_COMING) |
90 | return -EBUSY; | ||
91 | if (try_module_get(mod)) | ||
89 | return 0; | 92 | return 0; |
90 | return try_module_get(mod); | 93 | else |
94 | return -ENOENT; | ||
91 | } | 95 | } |
92 | 96 | ||
93 | static inline void add_taint_module(struct module *mod, unsigned flag) | 97 | static inline void add_taint_module(struct module *mod, unsigned flag) |
@@ -426,6 +430,14 @@ static unsigned int find_pcpusec(Elf_Ehdr *hdr, | |||
426 | return find_sec(hdr, sechdrs, secstrings, ".data.percpu"); | 430 | return find_sec(hdr, sechdrs, secstrings, ".data.percpu"); |
427 | } | 431 | } |
428 | 432 | ||
433 | static void percpu_modcopy(void *pcpudest, const void *from, unsigned long size) | ||
434 | { | ||
435 | int cpu; | ||
436 | |||
437 | for_each_possible_cpu(cpu) | ||
438 | memcpy(pcpudest + per_cpu_offset(cpu), from, size); | ||
439 | } | ||
440 | |||
429 | static int percpu_modinit(void) | 441 | static int percpu_modinit(void) |
430 | { | 442 | { |
431 | pcpu_num_used = 2; | 443 | pcpu_num_used = 2; |
@@ -498,6 +510,8 @@ static struct module_attribute modinfo_##field = { \ | |||
498 | MODINFO_ATTR(version); | 510 | MODINFO_ATTR(version); |
499 | MODINFO_ATTR(srcversion); | 511 | MODINFO_ATTR(srcversion); |
500 | 512 | ||
513 | static char last_unloaded_module[MODULE_NAME_LEN+1]; | ||
514 | |||
501 | #ifdef CONFIG_MODULE_UNLOAD | 515 | #ifdef CONFIG_MODULE_UNLOAD |
502 | /* Init the unload section of the module. */ | 516 | /* Init the unload section of the module. */ |
503 | static void module_unload_init(struct module *mod) | 517 | static void module_unload_init(struct module *mod) |
@@ -539,11 +553,21 @@ static int already_uses(struct module *a, struct module *b) | |||
539 | static int use_module(struct module *a, struct module *b) | 553 | static int use_module(struct module *a, struct module *b) |
540 | { | 554 | { |
541 | struct module_use *use; | 555 | struct module_use *use; |
542 | int no_warn; | 556 | int no_warn, err; |
543 | 557 | ||
544 | if (b == NULL || already_uses(a, b)) return 1; | 558 | if (b == NULL || already_uses(a, b)) return 1; |
545 | 559 | ||
546 | if (!strong_try_module_get(b)) | 560 | /* If we're interrupted or time out, we fail. */ |
561 | if (wait_event_interruptible_timeout( | ||
562 | module_wq, (err = strong_try_module_get(b)) != -EBUSY, | ||
563 | 30 * HZ) <= 0) { | ||
564 | printk("%s: gave up waiting for init of module %s.\n", | ||
565 | a->name, b->name); | ||
566 | return 0; | ||
567 | } | ||
568 | |||
569 | /* If strong_try_module_get() returned a different error, we fail. */ | ||
570 | if (err) | ||
547 | return 0; | 571 | return 0; |
548 | 572 | ||
549 | DEBUGP("Allocating new usage for %s.\n", a->name); | 573 | DEBUGP("Allocating new usage for %s.\n", a->name); |
@@ -721,6 +745,8 @@ sys_delete_module(const char __user *name_user, unsigned int flags) | |||
721 | mod->exit(); | 745 | mod->exit(); |
722 | mutex_lock(&module_mutex); | 746 | mutex_lock(&module_mutex); |
723 | } | 747 | } |
748 | /* Store the name of the last unloaded module for diagnostic purposes */ | ||
749 | strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); | ||
724 | free_module(mod); | 750 | free_module(mod); |
725 | 751 | ||
726 | out: | 752 | out: |
@@ -814,7 +840,7 @@ static inline void module_unload_free(struct module *mod) | |||
814 | 840 | ||
815 | static inline int use_module(struct module *a, struct module *b) | 841 | static inline int use_module(struct module *a, struct module *b) |
816 | { | 842 | { |
817 | return strong_try_module_get(b); | 843 | return strong_try_module_get(b) == 0; |
818 | } | 844 | } |
819 | 845 | ||
820 | static inline void module_unload_init(struct module *mod) | 846 | static inline void module_unload_init(struct module *mod) |
@@ -1122,7 +1148,7 @@ static void add_notes_attrs(struct module *mod, unsigned int nsect, | |||
1122 | ++loaded; | 1148 | ++loaded; |
1123 | } | 1149 | } |
1124 | 1150 | ||
1125 | notes_attrs->dir = kobject_add_dir(&mod->mkobj.kobj, "notes"); | 1151 | notes_attrs->dir = kobject_create_and_add("notes", &mod->mkobj.kobj); |
1126 | if (!notes_attrs->dir) | 1152 | if (!notes_attrs->dir) |
1127 | goto out; | 1153 | goto out; |
1128 | 1154 | ||
@@ -1212,6 +1238,7 @@ void module_remove_modinfo_attrs(struct module *mod) | |||
1212 | int mod_sysfs_init(struct module *mod) | 1238 | int mod_sysfs_init(struct module *mod) |
1213 | { | 1239 | { |
1214 | int err; | 1240 | int err; |
1241 | struct kobject *kobj; | ||
1215 | 1242 | ||
1216 | if (!module_sysfs_initialized) { | 1243 | if (!module_sysfs_initialized) { |
1217 | printk(KERN_ERR "%s: module sysfs not initialized\n", | 1244 | printk(KERN_ERR "%s: module sysfs not initialized\n", |
@@ -1219,15 +1246,25 @@ int mod_sysfs_init(struct module *mod) | |||
1219 | err = -EINVAL; | 1246 | err = -EINVAL; |
1220 | goto out; | 1247 | goto out; |
1221 | } | 1248 | } |
1222 | memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj)); | 1249 | |
1223 | err = kobject_set_name(&mod->mkobj.kobj, "%s", mod->name); | 1250 | kobj = kset_find_obj(module_kset, mod->name); |
1224 | if (err) | 1251 | if (kobj) { |
1252 | printk(KERN_ERR "%s: module is already loaded\n", mod->name); | ||
1253 | kobject_put(kobj); | ||
1254 | err = -EINVAL; | ||
1225 | goto out; | 1255 | goto out; |
1226 | kobj_set_kset_s(&mod->mkobj, module_subsys); | 1256 | } |
1257 | |||
1227 | mod->mkobj.mod = mod; | 1258 | mod->mkobj.mod = mod; |
1228 | 1259 | ||
1229 | kobject_init(&mod->mkobj.kobj); | 1260 | memset(&mod->mkobj.kobj, 0, sizeof(mod->mkobj.kobj)); |
1261 | mod->mkobj.kobj.kset = module_kset; | ||
1262 | err = kobject_init_and_add(&mod->mkobj.kobj, &module_ktype, NULL, | ||
1263 | "%s", mod->name); | ||
1264 | if (err) | ||
1265 | kobject_put(&mod->mkobj.kobj); | ||
1230 | 1266 | ||
1267 | /* delay uevent until full sysfs population */ | ||
1231 | out: | 1268 | out: |
1232 | return err; | 1269 | return err; |
1233 | } | 1270 | } |
@@ -1238,12 +1275,7 @@ int mod_sysfs_setup(struct module *mod, | |||
1238 | { | 1275 | { |
1239 | int err; | 1276 | int err; |
1240 | 1277 | ||
1241 | /* delay uevent until full sysfs population */ | 1278 | mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj); |
1242 | err = kobject_add(&mod->mkobj.kobj); | ||
1243 | if (err) | ||
1244 | goto out; | ||
1245 | |||
1246 | mod->holders_dir = kobject_add_dir(&mod->mkobj.kobj, "holders"); | ||
1247 | if (!mod->holders_dir) { | 1279 | if (!mod->holders_dir) { |
1248 | err = -ENOMEM; | 1280 | err = -ENOMEM; |
1249 | goto out_unreg; | 1281 | goto out_unreg; |
@@ -1263,11 +1295,9 @@ int mod_sysfs_setup(struct module *mod, | |||
1263 | out_unreg_param: | 1295 | out_unreg_param: |
1264 | module_param_sysfs_remove(mod); | 1296 | module_param_sysfs_remove(mod); |
1265 | out_unreg_holders: | 1297 | out_unreg_holders: |
1266 | kobject_unregister(mod->holders_dir); | 1298 | kobject_put(mod->holders_dir); |
1267 | out_unreg: | 1299 | out_unreg: |
1268 | kobject_del(&mod->mkobj.kobj); | ||
1269 | kobject_put(&mod->mkobj.kobj); | 1300 | kobject_put(&mod->mkobj.kobj); |
1270 | out: | ||
1271 | return err; | 1301 | return err; |
1272 | } | 1302 | } |
1273 | #endif | 1303 | #endif |
@@ -1276,9 +1306,20 @@ static void mod_kobject_remove(struct module *mod) | |||
1276 | { | 1306 | { |
1277 | module_remove_modinfo_attrs(mod); | 1307 | module_remove_modinfo_attrs(mod); |
1278 | module_param_sysfs_remove(mod); | 1308 | module_param_sysfs_remove(mod); |
1279 | kobject_unregister(mod->mkobj.drivers_dir); | 1309 | kobject_put(mod->mkobj.drivers_dir); |
1280 | kobject_unregister(mod->holders_dir); | 1310 | kobject_put(mod->holders_dir); |
1281 | kobject_unregister(&mod->mkobj.kobj); | 1311 | kobject_put(&mod->mkobj.kobj); |
1312 | } | ||
1313 | |||
1314 | /* | ||
1315 | * link the module with the whole machine is stopped with interrupts off | ||
1316 | * - this defends against kallsyms not taking locks | ||
1317 | */ | ||
1318 | static int __link_module(void *_mod) | ||
1319 | { | ||
1320 | struct module *mod = _mod; | ||
1321 | list_add(&mod->list, &modules); | ||
1322 | return 0; | ||
1282 | } | 1323 | } |
1283 | 1324 | ||
1284 | /* | 1325 | /* |
@@ -1330,7 +1371,7 @@ void *__symbol_get(const char *symbol) | |||
1330 | 1371 | ||
1331 | preempt_disable(); | 1372 | preempt_disable(); |
1332 | value = __find_symbol(symbol, &owner, &crc, 1); | 1373 | value = __find_symbol(symbol, &owner, &crc, 1); |
1333 | if (value && !strong_try_module_get(owner)) | 1374 | if (value && strong_try_module_get(owner) != 0) |
1334 | value = 0; | 1375 | value = 0; |
1335 | preempt_enable(); | 1376 | preempt_enable(); |
1336 | 1377 | ||
@@ -1884,16 +1925,16 @@ static struct module *load_module(void __user *umod, | |||
1884 | /* Now we've moved module, initialize linked lists, etc. */ | 1925 | /* Now we've moved module, initialize linked lists, etc. */ |
1885 | module_unload_init(mod); | 1926 | module_unload_init(mod); |
1886 | 1927 | ||
1887 | /* Initialize kobject, so we can reference it. */ | 1928 | /* add kobject, so we can reference it. */ |
1888 | err = mod_sysfs_init(mod); | 1929 | err = mod_sysfs_init(mod); |
1889 | if (err) | 1930 | if (err) |
1890 | goto cleanup; | 1931 | goto free_unload; |
1891 | 1932 | ||
1892 | /* Set up license info based on the info section */ | 1933 | /* Set up license info based on the info section */ |
1893 | set_license(mod, get_modinfo(sechdrs, infoindex, "license")); | 1934 | set_license(mod, get_modinfo(sechdrs, infoindex, "license")); |
1894 | 1935 | ||
1895 | if (strcmp(mod->name, "ndiswrapper") == 0) | 1936 | if (strcmp(mod->name, "ndiswrapper") == 0) |
1896 | add_taint(TAINT_PROPRIETARY_MODULE); | 1937 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); |
1897 | if (strcmp(mod->name, "driverloader") == 0) | 1938 | if (strcmp(mod->name, "driverloader") == 0) |
1898 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); | 1939 | add_taint_module(mod, TAINT_PROPRIETARY_MODULE); |
1899 | 1940 | ||
@@ -2023,6 +2064,11 @@ static struct module *load_module(void __user *umod, | |||
2023 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", | 2064 | printk(KERN_WARNING "%s: Ignoring obsolete parameters\n", |
2024 | mod->name); | 2065 | mod->name); |
2025 | 2066 | ||
2067 | /* Now sew it into the lists so we can get lockdep and oops | ||
2068 | * info during argument parsing. Noone should access us, since | ||
2069 | * strong_try_module_get() will fail. */ | ||
2070 | stop_machine_run(__link_module, mod, NR_CPUS); | ||
2071 | |||
2026 | /* Size of section 0 is 0, so this works well if no params */ | 2072 | /* Size of section 0 is 0, so this works well if no params */ |
2027 | err = parse_args(mod->name, mod->args, | 2073 | err = parse_args(mod->name, mod->args, |
2028 | (struct kernel_param *) | 2074 | (struct kernel_param *) |
@@ -2031,7 +2077,7 @@ static struct module *load_module(void __user *umod, | |||
2031 | / sizeof(struct kernel_param), | 2077 | / sizeof(struct kernel_param), |
2032 | NULL); | 2078 | NULL); |
2033 | if (err < 0) | 2079 | if (err < 0) |
2034 | goto arch_cleanup; | 2080 | goto unlink; |
2035 | 2081 | ||
2036 | err = mod_sysfs_setup(mod, | 2082 | err = mod_sysfs_setup(mod, |
2037 | (struct kernel_param *) | 2083 | (struct kernel_param *) |
@@ -2039,7 +2085,7 @@ static struct module *load_module(void __user *umod, | |||
2039 | sechdrs[setupindex].sh_size | 2085 | sechdrs[setupindex].sh_size |
2040 | / sizeof(struct kernel_param)); | 2086 | / sizeof(struct kernel_param)); |
2041 | if (err < 0) | 2087 | if (err < 0) |
2042 | goto arch_cleanup; | 2088 | goto unlink; |
2043 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2089 | add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
2044 | add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs); | 2090 | add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs); |
2045 | 2091 | ||
@@ -2054,9 +2100,13 @@ static struct module *load_module(void __user *umod, | |||
2054 | /* Done! */ | 2100 | /* Done! */ |
2055 | return mod; | 2101 | return mod; |
2056 | 2102 | ||
2057 | arch_cleanup: | 2103 | unlink: |
2104 | stop_machine_run(__unlink_module, mod, NR_CPUS); | ||
2058 | module_arch_cleanup(mod); | 2105 | module_arch_cleanup(mod); |
2059 | cleanup: | 2106 | cleanup: |
2107 | kobject_del(&mod->mkobj.kobj); | ||
2108 | kobject_put(&mod->mkobj.kobj); | ||
2109 | free_unload: | ||
2060 | module_unload_free(mod); | 2110 | module_unload_free(mod); |
2061 | module_free(mod, mod->module_init); | 2111 | module_free(mod, mod->module_init); |
2062 | free_core: | 2112 | free_core: |
@@ -2076,17 +2126,6 @@ static struct module *load_module(void __user *umod, | |||
2076 | goto free_hdr; | 2126 | goto free_hdr; |
2077 | } | 2127 | } |
2078 | 2128 | ||
2079 | /* | ||
2080 | * link the module with the whole machine is stopped with interrupts off | ||
2081 | * - this defends against kallsyms not taking locks | ||
2082 | */ | ||
2083 | static int __link_module(void *_mod) | ||
2084 | { | ||
2085 | struct module *mod = _mod; | ||
2086 | list_add(&mod->list, &modules); | ||
2087 | return 0; | ||
2088 | } | ||
2089 | |||
2090 | /* This is where the real work happens */ | 2129 | /* This is where the real work happens */ |
2091 | asmlinkage long | 2130 | asmlinkage long |
2092 | sys_init_module(void __user *umod, | 2131 | sys_init_module(void __user *umod, |
@@ -2111,10 +2150,6 @@ sys_init_module(void __user *umod, | |||
2111 | return PTR_ERR(mod); | 2150 | return PTR_ERR(mod); |
2112 | } | 2151 | } |
2113 | 2152 | ||
2114 | /* Now sew it into the lists. They won't access us, since | ||
2115 | strong_try_module_get() will fail. */ | ||
2116 | stop_machine_run(__link_module, mod, NR_CPUS); | ||
2117 | |||
2118 | /* Drop lock so they can recurse */ | 2153 | /* Drop lock so they can recurse */ |
2119 | mutex_unlock(&module_mutex); | 2154 | mutex_unlock(&module_mutex); |
2120 | 2155 | ||
@@ -2133,6 +2168,7 @@ sys_init_module(void __user *umod, | |||
2133 | mutex_lock(&module_mutex); | 2168 | mutex_lock(&module_mutex); |
2134 | free_module(mod); | 2169 | free_module(mod); |
2135 | mutex_unlock(&module_mutex); | 2170 | mutex_unlock(&module_mutex); |
2171 | wake_up(&module_wq); | ||
2136 | return ret; | 2172 | return ret; |
2137 | } | 2173 | } |
2138 | 2174 | ||
@@ -2147,6 +2183,7 @@ sys_init_module(void __user *umod, | |||
2147 | mod->init_size = 0; | 2183 | mod->init_size = 0; |
2148 | mod->init_text_size = 0; | 2184 | mod->init_text_size = 0; |
2149 | mutex_unlock(&module_mutex); | 2185 | mutex_unlock(&module_mutex); |
2186 | wake_up(&module_wq); | ||
2150 | 2187 | ||
2151 | return 0; | 2188 | return 0; |
2152 | } | 2189 | } |
@@ -2211,14 +2248,13 @@ static const char *get_ksymbol(struct module *mod, | |||
2211 | return mod->strtab + mod->symtab[best].st_name; | 2248 | return mod->strtab + mod->symtab[best].st_name; |
2212 | } | 2249 | } |
2213 | 2250 | ||
2214 | /* For kallsyms to ask for address resolution. NULL means not found. | 2251 | /* For kallsyms to ask for address resolution. NULL means not found. Careful |
2215 | We don't lock, as this is used for oops resolution and races are a | 2252 | * not to lock to avoid deadlock on oopses, simply disable preemption. */ |
2216 | lesser concern. */ | 2253 | char *module_address_lookup(unsigned long addr, |
2217 | /* FIXME: Risky: returns a pointer into a module w/o lock */ | 2254 | unsigned long *size, |
2218 | const char *module_address_lookup(unsigned long addr, | 2255 | unsigned long *offset, |
2219 | unsigned long *size, | 2256 | char **modname, |
2220 | unsigned long *offset, | 2257 | char *namebuf) |
2221 | char **modname) | ||
2222 | { | 2258 | { |
2223 | struct module *mod; | 2259 | struct module *mod; |
2224 | const char *ret = NULL; | 2260 | const char *ret = NULL; |
@@ -2233,8 +2269,13 @@ const char *module_address_lookup(unsigned long addr, | |||
2233 | break; | 2269 | break; |
2234 | } | 2270 | } |
2235 | } | 2271 | } |
2272 | /* Make a copy in here where it's safe */ | ||
2273 | if (ret) { | ||
2274 | strncpy(namebuf, ret, KSYM_NAME_LEN - 1); | ||
2275 | ret = namebuf; | ||
2276 | } | ||
2236 | preempt_enable(); | 2277 | preempt_enable(); |
2237 | return ret; | 2278 | return (char *)ret; |
2238 | } | 2279 | } |
2239 | 2280 | ||
2240 | int lookup_module_symbol_name(unsigned long addr, char *symname) | 2281 | int lookup_module_symbol_name(unsigned long addr, char *symname) |
@@ -2362,21 +2403,30 @@ static void m_stop(struct seq_file *m, void *p) | |||
2362 | mutex_unlock(&module_mutex); | 2403 | mutex_unlock(&module_mutex); |
2363 | } | 2404 | } |
2364 | 2405 | ||
2365 | static char *taint_flags(unsigned int taints, char *buf) | 2406 | static char *module_flags(struct module *mod, char *buf) |
2366 | { | 2407 | { |
2367 | int bx = 0; | 2408 | int bx = 0; |
2368 | 2409 | ||
2369 | if (taints) { | 2410 | if (mod->taints || |
2411 | mod->state == MODULE_STATE_GOING || | ||
2412 | mod->state == MODULE_STATE_COMING) { | ||
2370 | buf[bx++] = '('; | 2413 | buf[bx++] = '('; |
2371 | if (taints & TAINT_PROPRIETARY_MODULE) | 2414 | if (mod->taints & TAINT_PROPRIETARY_MODULE) |
2372 | buf[bx++] = 'P'; | 2415 | buf[bx++] = 'P'; |
2373 | if (taints & TAINT_FORCED_MODULE) | 2416 | if (mod->taints & TAINT_FORCED_MODULE) |
2374 | buf[bx++] = 'F'; | 2417 | buf[bx++] = 'F'; |
2375 | /* | 2418 | /* |
2376 | * TAINT_FORCED_RMMOD: could be added. | 2419 | * TAINT_FORCED_RMMOD: could be added. |
2377 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't | 2420 | * TAINT_UNSAFE_SMP, TAINT_MACHINE_CHECK, TAINT_BAD_PAGE don't |
2378 | * apply to modules. | 2421 | * apply to modules. |
2379 | */ | 2422 | */ |
2423 | |||
2424 | /* Show a - for module-is-being-unloaded */ | ||
2425 | if (mod->state == MODULE_STATE_GOING) | ||
2426 | buf[bx++] = '-'; | ||
2427 | /* Show a + for module-is-being-loaded */ | ||
2428 | if (mod->state == MODULE_STATE_COMING) | ||
2429 | buf[bx++] = '+'; | ||
2380 | buf[bx++] = ')'; | 2430 | buf[bx++] = ')'; |
2381 | } | 2431 | } |
2382 | buf[bx] = '\0'; | 2432 | buf[bx] = '\0'; |
@@ -2403,7 +2453,7 @@ static int m_show(struct seq_file *m, void *p) | |||
2403 | 2453 | ||
2404 | /* Taints info */ | 2454 | /* Taints info */ |
2405 | if (mod->taints) | 2455 | if (mod->taints) |
2406 | seq_printf(m, " %s", taint_flags(mod->taints, buf)); | 2456 | seq_printf(m, " %s", module_flags(mod, buf)); |
2407 | 2457 | ||
2408 | seq_printf(m, "\n"); | 2458 | seq_printf(m, "\n"); |
2409 | return 0; | 2459 | return 0; |
@@ -2498,97 +2548,12 @@ void print_modules(void) | |||
2498 | 2548 | ||
2499 | printk("Modules linked in:"); | 2549 | printk("Modules linked in:"); |
2500 | list_for_each_entry(mod, &modules, list) | 2550 | list_for_each_entry(mod, &modules, list) |
2501 | printk(" %s%s", mod->name, taint_flags(mod->taints, buf)); | 2551 | printk(" %s%s", mod->name, module_flags(mod, buf)); |
2552 | if (last_unloaded_module[0]) | ||
2553 | printk(" [last unloaded: %s]", last_unloaded_module); | ||
2502 | printk("\n"); | 2554 | printk("\n"); |
2503 | } | 2555 | } |
2504 | 2556 | ||
2505 | #ifdef CONFIG_SYSFS | ||
2506 | static char *make_driver_name(struct device_driver *drv) | ||
2507 | { | ||
2508 | char *driver_name; | ||
2509 | |||
2510 | driver_name = kmalloc(strlen(drv->name) + strlen(drv->bus->name) + 2, | ||
2511 | GFP_KERNEL); | ||
2512 | if (!driver_name) | ||
2513 | return NULL; | ||
2514 | |||
2515 | sprintf(driver_name, "%s:%s", drv->bus->name, drv->name); | ||
2516 | return driver_name; | ||
2517 | } | ||
2518 | |||
2519 | static void module_create_drivers_dir(struct module_kobject *mk) | ||
2520 | { | ||
2521 | if (!mk || mk->drivers_dir) | ||
2522 | return; | ||
2523 | |||
2524 | mk->drivers_dir = kobject_add_dir(&mk->kobj, "drivers"); | ||
2525 | } | ||
2526 | |||
2527 | void module_add_driver(struct module *mod, struct device_driver *drv) | ||
2528 | { | ||
2529 | char *driver_name; | ||
2530 | int no_warn; | ||
2531 | struct module_kobject *mk = NULL; | ||
2532 | |||
2533 | if (!drv) | ||
2534 | return; | ||
2535 | |||
2536 | if (mod) | ||
2537 | mk = &mod->mkobj; | ||
2538 | else if (drv->mod_name) { | ||
2539 | struct kobject *mkobj; | ||
2540 | |||
2541 | /* Lookup built-in module entry in /sys/modules */ | ||
2542 | mkobj = kset_find_obj(&module_subsys, drv->mod_name); | ||
2543 | if (mkobj) { | ||
2544 | mk = container_of(mkobj, struct module_kobject, kobj); | ||
2545 | /* remember our module structure */ | ||
2546 | drv->mkobj = mk; | ||
2547 | /* kset_find_obj took a reference */ | ||
2548 | kobject_put(mkobj); | ||
2549 | } | ||
2550 | } | ||
2551 | |||
2552 | if (!mk) | ||
2553 | return; | ||
2554 | |||
2555 | /* Don't check return codes; these calls are idempotent */ | ||
2556 | no_warn = sysfs_create_link(&drv->kobj, &mk->kobj, "module"); | ||
2557 | driver_name = make_driver_name(drv); | ||
2558 | if (driver_name) { | ||
2559 | module_create_drivers_dir(mk); | ||
2560 | no_warn = sysfs_create_link(mk->drivers_dir, &drv->kobj, | ||
2561 | driver_name); | ||
2562 | kfree(driver_name); | ||
2563 | } | ||
2564 | } | ||
2565 | EXPORT_SYMBOL(module_add_driver); | ||
2566 | |||
2567 | void module_remove_driver(struct device_driver *drv) | ||
2568 | { | ||
2569 | struct module_kobject *mk = NULL; | ||
2570 | char *driver_name; | ||
2571 | |||
2572 | if (!drv) | ||
2573 | return; | ||
2574 | |||
2575 | sysfs_remove_link(&drv->kobj, "module"); | ||
2576 | |||
2577 | if (drv->owner) | ||
2578 | mk = &drv->owner->mkobj; | ||
2579 | else if (drv->mkobj) | ||
2580 | mk = drv->mkobj; | ||
2581 | if (mk && mk->drivers_dir) { | ||
2582 | driver_name = make_driver_name(drv); | ||
2583 | if (driver_name) { | ||
2584 | sysfs_remove_link(mk->drivers_dir, driver_name); | ||
2585 | kfree(driver_name); | ||
2586 | } | ||
2587 | } | ||
2588 | } | ||
2589 | EXPORT_SYMBOL(module_remove_driver); | ||
2590 | #endif | ||
2591 | |||
2592 | #ifdef CONFIG_MODVERSIONS | 2557 | #ifdef CONFIG_MODVERSIONS |
2593 | /* Generate the signature for struct module here, too, for modversions. */ | 2558 | /* Generate the signature for struct module here, too, for modversions. */ |
2594 | void struct_module(struct module *mod) { return; } | 2559 | void struct_module(struct module *mod) { return; } |