Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus

* git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux-2.6-for-linus:
module: fix bne2 "gave up waiting for init of module libcrc32c"
module: verify_export_symbols under the lock
module: move find_module check to end
module: make locking more fine-grained.
module: Make module sysfs functions private.
module: move sysfs exposure to end of load_module
module: fix kdb's illicit use of struct module_use.
module: Make the 'usage' lists be two-way

+223 -157
+10 -34
include/linux/module.h
··· 181 181 void *__symbol_get_gpl(const char *symbol); 182 182 #define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) 183 183 184 + /* modules using other modules: kdb wants to see this. */ 185 + struct module_use { 186 + struct list_head source_list; 187 + struct list_head target_list; 188 + struct module *source, *target; 189 + }; 190 + 184 191 #ifndef __GENKSYMS__ 185 192 #ifdef CONFIG_MODVERSIONS 186 193 /* Mark the CRC weak since genksyms apparently decides not to ··· 366 359 367 360 #ifdef CONFIG_MODULE_UNLOAD 368 361 /* What modules depend on me? */ 369 - struct list_head modules_which_use_me; 362 + struct list_head source_list; 363 + /* What modules do I depend on? */ 364 + struct list_head target_list; 370 365 371 366 /* Who is waiting for us to be unloaded */ 372 367 struct task_struct *waiter; ··· 672 663 673 664 #endif /* CONFIG_MODULES */ 674 665 675 - struct device_driver; 676 666 #ifdef CONFIG_SYSFS 677 - struct module; 678 - 679 667 extern struct kset *module_kset; 680 668 extern struct kobj_type module_ktype; 681 669 extern int module_sysfs_initialized; 682 - 683 - int mod_sysfs_init(struct module *mod); 684 - int mod_sysfs_setup(struct module *mod, 685 - struct kernel_param *kparam, 686 - unsigned int num_params); 687 - int module_add_modinfo_attrs(struct module *mod); 688 - void module_remove_modinfo_attrs(struct module *mod); 689 - 690 - #else /* !CONFIG_SYSFS */ 691 - 692 - static inline int mod_sysfs_init(struct module *mod) 693 - { 694 - return 0; 695 - } 696 - 697 - static inline int mod_sysfs_setup(struct module *mod, 698 - struct kernel_param *kparam, 699 - unsigned int num_params) 700 - { 701 - return 0; 702 - } 703 - 704 - static inline int module_add_modinfo_attrs(struct module *mod) 705 - { 706 - return 0; 707 - } 708 - 709 - static inline void module_remove_modinfo_attrs(struct module *mod) 710 - { } 711 - 712 670 #endif /* CONFIG_SYSFS */ 713 671 714 672 #define symbol_request(x) try_then_request_module(symbol_get(x), "symbol:" #x)
+3 -9
kernel/debug/kdb/kdb_main.c
··· 1857 1857 } 1858 1858 1859 1859 #if defined(CONFIG_MODULES) 1860 - /* modules using other modules */ 1861 - struct module_use { 1862 - struct list_head list; 1863 - struct module *module_which_uses; 1864 - }; 1865 - 1866 1860 /* 1867 1861 * kdb_lsmod - This function implements the 'lsmod' command. Lists 1868 1862 * currently loaded kernel modules. ··· 1888 1894 { 1889 1895 struct module_use *use; 1890 1896 kdb_printf(" [ "); 1891 - list_for_each_entry(use, &mod->modules_which_use_me, 1892 - list) 1893 - kdb_printf("%s ", use->module_which_uses->name); 1897 + list_for_each_entry(use, &mod->source_list, 1898 + source_list) 1899 + kdb_printf("%s ", use->target->name); 1894 1900 kdb_printf("]\n"); 1895 1901 } 1896 1902 #endif
+210 -114
kernel/module.c
··· 72 72 /* If this is set, the section belongs in the init part of the module */ 73 73 #define INIT_OFFSET_MASK (1UL << (BITS_PER_LONG-1)) 74 74 75 - /* List of modules, protected by module_mutex or preempt_disable 75 + /* 76 + * Mutex protects: 77 + * 1) List of modules (also safely readable with preempt_disable), 78 + * 2) module_use links, 79 + * 3) module_addr_min/module_addr_max. 76 80 * (delete uses stop_machine/add uses RCU list operations). */ 77 81 DEFINE_MUTEX(module_mutex); 78 82 EXPORT_SYMBOL_GPL(module_mutex); ··· 94 90 95 91 static BLOCKING_NOTIFIER_HEAD(module_notify_list); 96 92 97 - /* Bounds of module allocation, for speeding __module_address */ 93 + /* Bounds of module allocation, for speeding __module_address. 94 + * Protected by module_mutex. */ 98 95 static unsigned long module_addr_min = -1UL, module_addr_max = 0; 99 96 100 97 int register_module_notifier(struct notifier_block * nb) ··· 334 329 } 335 330 336 331 /* Find a symbol and return it, along with, (optional) crc and 337 - * (optional) module which owns it */ 332 + * (optional) module which owns it. Needs preempt disabled or module_mutex. */ 338 333 const struct kernel_symbol *find_symbol(const char *name, 339 334 struct module **owner, 340 335 const unsigned long **crc, ··· 528 523 { 529 524 int cpu; 530 525 531 - INIT_LIST_HEAD(&mod->modules_which_use_me); 526 + INIT_LIST_HEAD(&mod->source_list); 527 + INIT_LIST_HEAD(&mod->target_list); 532 528 for_each_possible_cpu(cpu) { 533 529 per_cpu_ptr(mod->refptr, cpu)->incs = 0; 534 530 per_cpu_ptr(mod->refptr, cpu)->decs = 0; ··· 541 535 mod->waiter = current; 542 536 } 543 537 544 - /* modules using other modules */ 545 - struct module_use 546 - { 547 - struct list_head list; 548 - struct module *module_which_uses; 549 - }; 550 - 551 538 /* Does a already use b? */ 552 539 static int already_uses(struct module *a, struct module *b) 553 540 { 554 541 struct module_use *use; 555 542 556 - list_for_each_entry(use, &b->modules_which_use_me, list) { 557 - if (use->module_which_uses == a) { 543 + list_for_each_entry(use, &b->source_list, source_list) { 544 + if (use->source == a) { 558 545 DEBUGP("%s uses %s!\n", a->name, b->name); 559 546 return 1; 560 547 } ··· 556 557 return 0; 557 558 } 558 559 559 - /* Module a uses b */ 560 - int use_module(struct module *a, struct module *b) 560 + /* 561 + * Module a uses b 562 + * - we add 'a' as a "source", 'b' as a "target" of module use 563 + * - the module_use is added to the list of 'b' sources (so 564 + * 'b' can walk the list to see who sourced them), and of 'a' 565 + * targets (so 'a' can see what modules it targets). 566 + */ 567 + static int add_module_usage(struct module *a, struct module *b) 561 568 { 562 569 struct module_use *use; 563 - int no_warn, err; 564 - 565 - if (b == NULL || already_uses(a, b)) return 1; 566 - 567 - /* If we're interrupted or time out, we fail. */ 568 - if (wait_event_interruptible_timeout( 569 - module_wq, (err = strong_try_module_get(b)) != -EBUSY, 570 - 30 * HZ) <= 0) { 571 - printk("%s: gave up waiting for init of module %s.\n", 572 - a->name, b->name); 573 - return 0; 574 - } 575 - 576 - /* If strong_try_module_get() returned a different error, we fail. */ 577 - if (err) 578 - return 0; 579 570 580 571 DEBUGP("Allocating new usage for %s.\n", a->name); 581 572 use = kmalloc(sizeof(*use), GFP_ATOMIC); 582 573 if (!use) { 583 - printk("%s: out of memory loading\n", a->name); 584 - module_put(b); 585 - return 0; 574 + printk(KERN_WARNING "%s: out of memory loading\n", a->name); 575 + return -ENOMEM; 586 576 } 587 577 588 - use->module_which_uses = a; 589 - list_add(&use->list, &b->modules_which_use_me); 590 - no_warn = sysfs_create_link(b->holders_dir, &a->mkobj.kobj, a->name); 591 - return 1; 578 + use->source = a; 579 + use->target = b; 580 + list_add(&use->source_list, &b->source_list); 581 + list_add(&use->target_list, &a->target_list); 582 + return 0; 592 583 } 593 - EXPORT_SYMBOL_GPL(use_module); 584 + 585 + /* Module a uses b: caller needs module_mutex() */ 586 + int ref_module(struct module *a, struct module *b) 587 + { 588 + int err; 589 + 590 + if (b == NULL || already_uses(a, b)) 591 + return 0; 592 + 593 + /* If module isn't available, we fail. */ 594 + err = strong_try_module_get(b); 595 + if (err) 596 + return err; 597 + 598 + err = add_module_usage(a, b); 599 + if (err) { 600 + module_put(b); 601 + return err; 602 + } 603 + return 0; 604 + } 605 + EXPORT_SYMBOL_GPL(ref_module); 594 606 595 607 /* Clear the unload stuff of the module. */ 596 608 static void module_unload_free(struct module *mod) 597 609 { 598 - struct module *i; 610 + struct module_use *use, *tmp; 599 611 600 - list_for_each_entry(i, &modules, list) { 601 - struct module_use *use; 602 - 603 - list_for_each_entry(use, &i->modules_which_use_me, list) { 604 - if (use->module_which_uses == mod) { 605 - DEBUGP("%s unusing %s\n", mod->name, i->name); 606 - module_put(i); 607 - list_del(&use->list); 608 - kfree(use); 609 - sysfs_remove_link(i->holders_dir, mod->name); 610 - /* There can be at most one match. */ 611 - break; 612 - } 613 - } 612 + mutex_lock(&module_mutex); 613 + list_for_each_entry_safe(use, tmp, &mod->target_list, target_list) { 614 + struct module *i = use->target; 615 + DEBUGP("%s unusing %s\n", mod->name, i->name); 616 + module_put(i); 617 + list_del(&use->source_list); 618 + list_del(&use->target_list); 619 + kfree(use); 614 620 } 621 + mutex_unlock(&module_mutex); 615 622 } 616 623 617 624 #ifdef CONFIG_MODULE_FORCE_UNLOAD ··· 740 735 goto out; 741 736 } 742 737 743 - if (!list_empty(&mod->modules_which_use_me)) { 738 + if (!list_empty(&mod->source_list)) { 744 739 /* Other modules depend on us: get rid of them first. */ 745 740 ret = -EWOULDBLOCK; 746 741 goto out; ··· 784 779 blocking_notifier_call_chain(&module_notify_list, 785 780 MODULE_STATE_GOING, mod); 786 781 async_synchronize_full(); 787 - mutex_lock(&module_mutex); 782 + 788 783 /* Store the name of the last unloaded module for diagnostic purposes */ 789 784 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); 790 785 ddebug_remove_module(mod->name); 791 - free_module(mod); 792 786 793 - out: 787 + free_module(mod); 788 + return 0; 789 + out: 794 790 mutex_unlock(&module_mutex); 795 791 return ret; 796 792 } ··· 805 799 806 800 /* Always include a trailing , so userspace can differentiate 807 801 between this and the old multi-field proc format. */ 808 - list_for_each_entry(use, &mod->modules_which_use_me, list) { 802 + list_for_each_entry(use, &mod->source_list, source_list) { 809 803 printed_something = 1; 810 - seq_printf(m, "%s,", use->module_which_uses->name); 804 + seq_printf(m, "%s,", use->source->name); 811 805 } 812 806 813 807 if (mod->init != NULL && mod->exit == NULL) { ··· 886 880 { 887 881 } 888 882 889 - int use_module(struct module *a, struct module *b) 883 + int ref_module(struct module *a, struct module *b) 890 884 { 891 - return strong_try_module_get(b) == 0; 885 + return strong_try_module_get(b); 892 886 } 893 - EXPORT_SYMBOL_GPL(use_module); 887 + EXPORT_SYMBOL_GPL(ref_module); 894 888 895 889 static inline void module_unload_init(struct module *mod) 896 890 { ··· 1007 1001 { 1008 1002 const unsigned long *crc; 1009 1003 1004 + /* Since this should be found in kernel (which can't be removed), 1005 + * no locking is necessary. */ 1010 1006 if (!find_symbol(MODULE_SYMBOL_PREFIX "module_layout", NULL, 1011 1007 &crc, true, false)) 1012 1008 BUG(); ··· 1051 1043 } 1052 1044 #endif /* CONFIG_MODVERSIONS */ 1053 1045 1054 - /* Resolve a symbol for this module. I.e. if we find one, record usage. 1055 - Must be holding module_mutex. */ 1046 + /* Resolve a symbol for this module. I.e. if we find one, record usage. */ 1056 1047 static const struct kernel_symbol *resolve_symbol(Elf_Shdr *sechdrs, 1057 1048 unsigned int versindex, 1058 1049 const char *name, 1059 - struct module *mod) 1050 + struct module *mod, 1051 + char ownername[]) 1060 1052 { 1061 1053 struct module *owner; 1062 1054 const struct kernel_symbol *sym; 1063 1055 const unsigned long *crc; 1056 + int err; 1064 1057 1058 + mutex_lock(&module_mutex); 1065 1059 sym = find_symbol(name, &owner, &crc, 1066 1060 !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); 1067 - /* use_module can fail due to OOM, 1068 - or module initialization or unloading */ 1069 - if (sym) { 1070 - if (!check_version(sechdrs, versindex, name, mod, crc, owner) 1071 - || !use_module(mod, owner)) 1072 - sym = NULL; 1061 + if (!sym) 1062 + goto unlock; 1063 + 1064 + if (!check_version(sechdrs, versindex, name, mod, crc, owner)) { 1065 + sym = ERR_PTR(-EINVAL); 1066 + goto getname; 1073 1067 } 1068 + 1069 + err = ref_module(mod, owner); 1070 + if (err) { 1071 + sym = ERR_PTR(err); 1072 + goto getname; 1073 + } 1074 + 1075 + getname: 1076 + /* We must make copy under the lock if we failed to get ref. */ 1077 + strncpy(ownername, module_name(owner), MODULE_NAME_LEN); 1078 + unlock: 1079 + mutex_unlock(&module_mutex); 1074 1080 return sym; 1081 + } 1082 + 1083 + static const struct kernel_symbol *resolve_symbol_wait(Elf_Shdr *sechdrs, 1084 + unsigned int versindex, 1085 + const char *name, 1086 + struct module *mod) 1087 + { 1088 + const struct kernel_symbol *ksym; 1089 + char ownername[MODULE_NAME_LEN]; 1090 + 1091 + if (wait_event_interruptible_timeout(module_wq, 1092 + !IS_ERR(ksym = resolve_symbol(sechdrs, versindex, name, 1093 + mod, ownername)) || 1094 + PTR_ERR(ksym) != -EBUSY, 1095 + 30 * HZ) <= 0) { 1096 + printk(KERN_WARNING "%s: gave up waiting for init of module %s.\n", 1097 + mod->name, ownername); 1098 + } 1099 + return ksym; 1075 1100 } 1076 1101 1077 1102 /* ··· 1336 1295 #endif 1337 1296 1338 1297 #ifdef CONFIG_SYSFS 1339 - int module_add_modinfo_attrs(struct module *mod) 1298 + static void add_usage_links(struct module *mod) 1299 + { 1300 + #ifdef CONFIG_MODULE_UNLOAD 1301 + struct module_use *use; 1302 + int nowarn; 1303 + 1304 + mutex_lock(&module_mutex); 1305 + list_for_each_entry(use, &mod->target_list, target_list) { 1306 + nowarn = sysfs_create_link(use->target->holders_dir, 1307 + &mod->mkobj.kobj, mod->name); 1308 + } 1309 + mutex_unlock(&module_mutex); 1310 + #endif 1311 + } 1312 + 1313 + static void del_usage_links(struct module *mod) 1314 + { 1315 + #ifdef CONFIG_MODULE_UNLOAD 1316 + struct module_use *use; 1317 + 1318 + mutex_lock(&module_mutex); 1319 + list_for_each_entry(use, &mod->target_list, target_list) 1320 + sysfs_remove_link(use->target->holders_dir, mod->name); 1321 + mutex_unlock(&module_mutex); 1322 + #endif 1323 + } 1324 + 1325 + static int module_add_modinfo_attrs(struct module *mod) 1340 1326 { 1341 1327 struct module_attribute *attr; 1342 1328 struct module_attribute *temp_attr; ··· 1389 1321 return error; 1390 1322 } 1391 1323 1392 - void module_remove_modinfo_attrs(struct module *mod) 1324 + static void module_remove_modinfo_attrs(struct module *mod) 1393 1325 { 1394 1326 struct module_attribute *attr; 1395 1327 int i; ··· 1405 1337 kfree(mod->modinfo_attrs); 1406 1338 } 1407 1339 1408 - int mod_sysfs_init(struct module *mod) 1340 + static int mod_sysfs_init(struct module *mod) 1409 1341 { 1410 1342 int err; 1411 1343 struct kobject *kobj; ··· 1439 1371 return err; 1440 1372 } 1441 1373 1442 - int mod_sysfs_setup(struct module *mod, 1374 + static int mod_sysfs_setup(struct module *mod, 1443 1375 struct kernel_param *kparam, 1444 1376 unsigned int num_params) 1445 1377 { 1446 1378 int err; 1379 + 1380 + err = mod_sysfs_init(mod); 1381 + if (err) 1382 + goto out; 1447 1383 1448 1384 mod->holders_dir = kobject_create_and_add("holders", &mod->mkobj.kobj); 1449 1385 if (!mod->holders_dir) { ··· 1463 1391 if (err) 1464 1392 goto out_unreg_param; 1465 1393 1394 + add_usage_links(mod); 1395 + 1466 1396 kobject_uevent(&mod->mkobj.kobj, KOBJ_ADD); 1467 1397 return 0; 1468 1398 ··· 1474 1400 kobject_put(mod->holders_dir); 1475 1401 out_unreg: 1476 1402 kobject_put(&mod->mkobj.kobj); 1403 + out: 1477 1404 return err; 1478 1405 } 1479 1406 ··· 1485 1410 1486 1411 #else /* CONFIG_SYSFS */ 1487 1412 1413 + static inline int mod_sysfs_init(struct module *mod) 1414 + { 1415 + return 0; 1416 + } 1417 + 1418 + static inline int mod_sysfs_setup(struct module *mod, 1419 + struct kernel_param *kparam, 1420 + unsigned int num_params) 1421 + { 1422 + return 0; 1423 + } 1424 + 1425 + static inline int module_add_modinfo_attrs(struct module *mod) 1426 + { 1427 + return 0; 1428 + } 1429 + 1430 + static inline void module_remove_modinfo_attrs(struct module *mod) 1431 + { 1432 + } 1433 + 1488 1434 static void mod_sysfs_fini(struct module *mod) 1435 + { 1436 + } 1437 + 1438 + static void del_usage_links(struct module *mod) 1489 1439 { 1490 1440 } 1491 1441 ··· 1518 1418 1519 1419 static void mod_kobject_remove(struct module *mod) 1520 1420 { 1421 + del_usage_links(mod); 1521 1422 module_remove_modinfo_attrs(mod); 1522 1423 module_param_sysfs_remove(mod); 1523 1424 kobject_put(mod->mkobj.drivers_dir); ··· 1537 1436 return 0; 1538 1437 } 1539 1438 1540 - /* Free a module, remove from lists, etc (must hold module_mutex). */ 1439 + /* Free a module, remove from lists, etc. */ 1541 1440 static void free_module(struct module *mod) 1542 1441 { 1543 1442 trace_module_free(mod); 1544 1443 1545 1444 /* Delete from various lists */ 1445 + mutex_lock(&module_mutex); 1546 1446 stop_machine(__unlink_module, mod, NULL); 1447 + mutex_unlock(&module_mutex); 1547 1448 remove_notes_attrs(mod); 1548 1449 remove_sect_attrs(mod); 1549 1450 mod_kobject_remove(mod); ··· 1596 1493 /* 1597 1494 * Ensure that an exported symbol [global namespace] does not already exist 1598 1495 * in the kernel or in some other module's exported symbol table. 1496 + * 1497 + * You must hold the module_mutex. 1599 1498 */ 1600 1499 static int verify_export_symbols(struct module *mod) 1601 1500 { ··· 1663 1558 break; 1664 1559 1665 1560 case SHN_UNDEF: 1666 - ksym = resolve_symbol(sechdrs, versindex, 1667 - strtab + sym[i].st_name, mod); 1561 + ksym = resolve_symbol_wait(sechdrs, versindex, 1562 + strtab + sym[i].st_name, 1563 + mod); 1668 1564 /* Ok if resolved. */ 1669 - if (ksym) { 1565 + if (ksym && !IS_ERR(ksym)) { 1670 1566 sym[i].st_value = ksym->value; 1671 1567 break; 1672 1568 } 1673 1569 1674 1570 /* Ok if weak. */ 1675 - if (ELF_ST_BIND(sym[i].st_info) == STB_WEAK) 1571 + if (!ksym && ELF_ST_BIND(sym[i].st_info) == STB_WEAK) 1676 1572 break; 1677 1573 1678 - printk(KERN_WARNING "%s: Unknown symbol %s\n", 1679 - mod->name, strtab + sym[i].st_name); 1680 - ret = -ENOENT; 1574 + printk(KERN_WARNING "%s: Unknown symbol %s (err %li)\n", 1575 + mod->name, strtab + sym[i].st_name, 1576 + PTR_ERR(ksym)); 1577 + ret = PTR_ERR(ksym) ?: -ENOENT; 1681 1578 break; 1682 1579 1683 1580 default: ··· 2067 1960 void *ret = module_alloc(size); 2068 1961 2069 1962 if (ret) { 1963 + mutex_lock(&module_mutex); 2070 1964 /* Update module bounds. */ 2071 1965 if ((unsigned long)ret < module_addr_min) 2072 1966 module_addr_min = (unsigned long)ret; 2073 1967 if ((unsigned long)ret + size > module_addr_max) 2074 1968 module_addr_max = (unsigned long)ret + size; 1969 + mutex_unlock(&module_mutex); 2075 1970 } 2076 1971 return ret; 2077 1972 } ··· 2248 2139 goto free_mod; 2249 2140 } 2250 2141 2251 - if (find_module(mod->name)) { 2252 - err = -EEXIST; 2253 - goto free_mod; 2254 - } 2255 - 2256 2142 mod->state = MODULE_STATE_COMING; 2257 2143 2258 2144 /* Allow arches to frob section contents and sizes. */ ··· 2337 2233 #endif 2338 2234 /* Now we've moved module, initialize linked lists, etc. */ 2339 2235 module_unload_init(mod); 2340 - 2341 - /* add kobject, so we can reference it. */ 2342 - err = mod_sysfs_init(mod); 2343 - if (err) 2344 - goto free_unload; 2345 2236 2346 2237 /* Set up license info based on the info section */ 2347 2238 set_license(mod, get_modinfo(sechdrs, infoindex, "license")); ··· 2462 2363 goto cleanup; 2463 2364 } 2464 2365 2465 - /* Find duplicate symbols */ 2466 - err = verify_export_symbols(mod); 2467 - if (err < 0) 2468 - goto cleanup; 2469 - 2470 2366 /* Set up and sort exception table */ 2471 2367 mod->extable = section_objs(hdr, sechdrs, secstrings, "__ex_table", 2472 2368 sizeof(*mod->extable), &mod->num_exentries); ··· 2520 2426 * function to insert in a way safe to concurrent readers. 2521 2427 * The mutex protects against concurrent writers. 2522 2428 */ 2429 + mutex_lock(&module_mutex); 2430 + if (find_module(mod->name)) { 2431 + err = -EEXIST; 2432 + goto unlock; 2433 + } 2434 + 2435 + /* Find duplicate symbols */ 2436 + err = verify_export_symbols(mod); 2437 + if (err < 0) 2438 + goto unlock; 2439 + 2523 2440 list_add_rcu(&mod->list, &modules); 2441 + mutex_unlock(&module_mutex); 2524 2442 2525 2443 err = parse_args(mod->name, mod->args, mod->kp, mod->num_kp, NULL); 2526 2444 if (err < 0) ··· 2541 2435 err = mod_sysfs_setup(mod, mod->kp, mod->num_kp); 2542 2436 if (err < 0) 2543 2437 goto unlink; 2438 + 2544 2439 add_sect_attrs(mod, hdr->e_shnum, secstrings, sechdrs); 2545 2440 add_notes_attrs(mod, hdr->e_shnum, secstrings, sechdrs); 2546 2441 ··· 2554 2447 return mod; 2555 2448 2556 2449 unlink: 2450 + mutex_lock(&module_mutex); 2557 2451 /* Unlink carefully: kallsyms could be walking list. */ 2558 2452 list_del_rcu(&mod->list); 2453 + unlock: 2454 + mutex_unlock(&module_mutex); 2559 2455 synchronize_sched(); 2560 2456 module_arch_cleanup(mod); 2561 2457 cleanup: 2562 2458 free_modinfo(mod); 2563 - kobject_del(&mod->mkobj.kobj); 2564 - kobject_put(&mod->mkobj.kobj); 2565 - free_unload: 2566 2459 module_unload_free(mod); 2567 2460 #if defined(CONFIG_MODULE_UNLOAD) 2568 2461 free_percpu(mod->refptr); ··· 2609 2502 if (!capable(CAP_SYS_MODULE) || modules_disabled) 2610 2503 return -EPERM; 2611 2504 2612 - /* Only one module load at a time, please */ 2613 - if (mutex_lock_interruptible(&module_mutex) != 0) 2614 - return -EINTR; 2615 - 2616 2505 /* Do all the hard work */ 2617 2506 mod = load_module(umod, len, uargs); 2618 - if (IS_ERR(mod)) { 2619 - mutex_unlock(&module_mutex); 2507 + if (IS_ERR(mod)) 2620 2508 return PTR_ERR(mod); 2621 - } 2622 - 2623 - /* Drop lock so they can recurse */ 2624 - mutex_unlock(&module_mutex); 2625 2509 2626 2510 blocking_notifier_call_chain(&module_notify_list, 2627 2511 MODULE_STATE_COMING, mod); ··· 2629 2531 module_put(mod); 2630 2532 blocking_notifier_call_chain(&module_notify_list, 2631 2533 MODULE_STATE_GOING, mod); 2632 - mutex_lock(&module_mutex); 2633 2534 free_module(mod); 2634 - mutex_unlock(&module_mutex); 2635 2535 wake_up(&module_wq); 2636 2536 return ret; 2637 2537 }