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.

module: pass struct find_symbol_args to find_symbol

Simplify the calling convention by passing the find_symbol_args structure
to find_symbol instead of initializing it inside the function.

Reviewed-by: Miroslav Benes <mbenes@suse.cz>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jessica Yu <jeyu@kernel.org>

authored by

Christoph Hellwig and committed by
Jessica Yu
0b96615c 71e4b309

+52 -61
+52 -61
kernel/module.c
··· 531 531 * Find an exported symbol and return it, along with, (optional) crc and 532 532 * (optional) module which owns it. Needs preempt disabled or module_mutex. 533 533 */ 534 - static const struct kernel_symbol *find_symbol(const char *name, 535 - struct module **owner, 536 - const s32 **crc, 537 - enum mod_license *license, 538 - bool gplok, 539 - bool warn) 534 + static bool find_symbol(struct find_symbol_arg *fsa) 540 535 { 541 536 static const struct symsearch arr[] = { 542 537 { __start___ksymtab, __stop___ksymtab, __start___kcrctab, ··· 551 556 GPL_ONLY, true }, 552 557 #endif 553 558 }; 554 - struct find_symbol_arg fsa = { 555 - .name = name, 556 - .gplok = gplok, 557 - .warn = warn, 558 - }; 559 559 struct module *mod; 560 560 unsigned int i; 561 561 562 562 module_assert_mutex_or_preempt(); 563 563 564 564 for (i = 0; i < ARRAY_SIZE(arr); i++) 565 - if (find_exported_symbol_in_section(&arr[i], NULL, &fsa)) 566 - goto found; 565 + if (find_exported_symbol_in_section(&arr[i], NULL, fsa)) 566 + return true; 567 567 568 568 list_for_each_entry_rcu(mod, &modules, list, 569 569 lockdep_is_held(&module_mutex)) { ··· 588 598 continue; 589 599 590 600 for (i = 0; i < ARRAY_SIZE(arr); i++) 591 - if (find_exported_symbol_in_section(&arr[i], mod, &fsa)) 592 - goto found; 601 + if (find_exported_symbol_in_section(&arr[i], mod, fsa)) 602 + return true; 593 603 } 594 604 595 - pr_debug("Failed to find symbol %s\n", name); 596 - return NULL; 597 - 598 - found: 599 - if (owner) 600 - *owner = fsa.owner; 601 - if (crc) 602 - *crc = fsa.crc; 603 - if (license) 604 - *license = fsa.license; 605 - return fsa.sym; 605 + pr_debug("Failed to find symbol %s\n", fsa->name); 606 + return false; 606 607 } 607 608 608 609 /* ··· 1055 1074 1056 1075 void __symbol_put(const char *symbol) 1057 1076 { 1058 - struct module *owner; 1077 + struct find_symbol_arg fsa = { 1078 + .name = symbol, 1079 + .gplok = true, 1080 + }; 1059 1081 1060 1082 preempt_disable(); 1061 - if (!find_symbol(symbol, &owner, NULL, NULL, true, false)) 1083 + if (!find_symbol(&fsa)) 1062 1084 BUG(); 1063 - module_put(owner); 1085 + module_put(fsa.owner); 1064 1086 preempt_enable(); 1065 1087 } 1066 1088 EXPORT_SYMBOL(__symbol_put); ··· 1332 1348 static inline int check_modstruct_version(const struct load_info *info, 1333 1349 struct module *mod) 1334 1350 { 1335 - const s32 *crc; 1351 + struct find_symbol_arg fsa = { 1352 + .name = "module_layout", 1353 + .gplok = true, 1354 + }; 1336 1355 1337 1356 /* 1338 1357 * Since this should be found in kernel (which can't be removed), no 1339 1358 * locking is necessary -- use preempt_disable() to placate lockdep. 1340 1359 */ 1341 1360 preempt_disable(); 1342 - if (!find_symbol("module_layout", NULL, &crc, NULL, true, false)) { 1361 + if (!find_symbol(&fsa)) { 1343 1362 preempt_enable(); 1344 1363 BUG(); 1345 1364 } 1346 1365 preempt_enable(); 1347 - return check_version(info, "module_layout", mod, crc); 1366 + return check_version(info, "module_layout", mod, fsa.crc); 1348 1367 } 1349 1368 1350 1369 /* First part is kernel version, which we ignore if module has crcs. */ ··· 1441 1454 const char *name, 1442 1455 char ownername[]) 1443 1456 { 1444 - struct module *owner; 1445 - const struct kernel_symbol *sym; 1446 - const s32 *crc; 1447 - enum mod_license license; 1457 + struct find_symbol_arg fsa = { 1458 + .name = name, 1459 + .gplok = !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), 1460 + .warn = true, 1461 + }; 1448 1462 int err; 1449 1463 1450 1464 /* ··· 1455 1467 */ 1456 1468 sched_annotate_sleep(); 1457 1469 mutex_lock(&module_mutex); 1458 - sym = find_symbol(name, &owner, &crc, &license, 1459 - !(mod->taints & (1 << TAINT_PROPRIETARY_MODULE)), true); 1460 - if (!sym) 1470 + if (!find_symbol(&fsa)) 1461 1471 goto unlock; 1462 1472 1463 - if (license == GPL_ONLY) 1473 + if (fsa.license == GPL_ONLY) 1464 1474 mod->using_gplonly_symbols = true; 1465 1475 1466 - if (!inherit_taint(mod, owner)) { 1467 - sym = NULL; 1476 + if (!inherit_taint(mod, fsa.owner)) { 1477 + fsa.sym = NULL; 1468 1478 goto getname; 1469 1479 } 1470 1480 1471 - if (!check_version(info, name, mod, crc)) { 1472 - sym = ERR_PTR(-EINVAL); 1481 + if (!check_version(info, name, mod, fsa.crc)) { 1482 + fsa.sym = ERR_PTR(-EINVAL); 1473 1483 goto getname; 1474 1484 } 1475 1485 1476 - err = verify_namespace_is_imported(info, sym, mod); 1486 + err = verify_namespace_is_imported(info, fsa.sym, mod); 1477 1487 if (err) { 1478 - sym = ERR_PTR(err); 1488 + fsa.sym = ERR_PTR(err); 1479 1489 goto getname; 1480 1490 } 1481 1491 1482 - err = ref_module(mod, owner); 1492 + err = ref_module(mod, fsa.owner); 1483 1493 if (err) { 1484 - sym = ERR_PTR(err); 1494 + fsa.sym = ERR_PTR(err); 1485 1495 goto getname; 1486 1496 } 1487 1497 1488 1498 getname: 1489 1499 /* We must make copy under the lock if we failed to get ref. */ 1490 - strncpy(ownername, module_name(owner), MODULE_NAME_LEN); 1500 + strncpy(ownername, module_name(fsa.owner), MODULE_NAME_LEN); 1491 1501 unlock: 1492 1502 mutex_unlock(&module_mutex); 1493 - return sym; 1503 + return fsa.sym; 1494 1504 } 1495 1505 1496 1506 static const struct kernel_symbol * ··· 2249 2263 2250 2264 void *__symbol_get(const char *symbol) 2251 2265 { 2252 - struct module *owner; 2253 - const struct kernel_symbol *sym; 2266 + struct find_symbol_arg fsa = { 2267 + .name = symbol, 2268 + .gplok = true, 2269 + .warn = true, 2270 + }; 2254 2271 2255 2272 preempt_disable(); 2256 - sym = find_symbol(symbol, &owner, NULL, NULL, true, true); 2257 - if (sym && strong_try_module_get(owner)) 2258 - sym = NULL; 2273 + if (!find_symbol(&fsa) || strong_try_module_get(fsa.owner)) { 2274 + preempt_enable(); 2275 + return NULL; 2276 + } 2259 2277 preempt_enable(); 2260 - 2261 - return sym ? (void *)kernel_symbol_value(sym) : NULL; 2278 + return (void *)kernel_symbol_value(fsa.sym); 2262 2279 } 2263 2280 EXPORT_SYMBOL_GPL(__symbol_get); 2264 2281 ··· 2274 2285 static int verify_exported_symbols(struct module *mod) 2275 2286 { 2276 2287 unsigned int i; 2277 - struct module *owner; 2278 2288 const struct kernel_symbol *s; 2279 2289 struct { 2280 2290 const struct kernel_symbol *sym; ··· 2290 2302 2291 2303 for (i = 0; i < ARRAY_SIZE(arr); i++) { 2292 2304 for (s = arr[i].sym; s < arr[i].sym + arr[i].num; s++) { 2293 - if (find_symbol(kernel_symbol_name(s), &owner, NULL, 2294 - NULL, true, false)) { 2305 + struct find_symbol_arg fsa = { 2306 + .name = kernel_symbol_name(s), 2307 + .gplok = true, 2308 + }; 2309 + if (find_symbol(&fsa)) { 2295 2310 pr_err("%s: exports duplicate symbol %s" 2296 2311 " (owned by %s)\n", 2297 2312 mod->name, kernel_symbol_name(s), 2298 - module_name(owner)); 2313 + module_name(fsa.owner)); 2299 2314 return -ENOEXEC; 2300 2315 } 2301 2316 }