History

modpost: move *.mod.c generation to write_mod_c_files()

A later commit will add more code to this list_for_each_entry loop. Before that, move the loop body into a separate helper function.

Masahiro Yamada committed 4 years ago

Commit a44abac1 parent 7fedac91 file · +31 −25Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/mod/modpost.c+31−25
@@ -2390,6 +2390,34 @@ static void write_if_changed(struct buffer *b, const char *fname) · 2389 unmodified lines
2390 write_buf(b, fname);2390 write_buf(b, fname);
2391}2391}
2392 2392
2393/* do sanity checks, and generate *.mod.c file */
2394static void write_mod_c_file(struct module *mod)
2395{
2396 struct buffer buf = { };
2397 char fname[PATH_MAX];
2398 int ret;
2399
2400 check_modname_len(mod);
2401 check_exports(mod);
2402
2403 add_header(&buf, mod);
2404 add_versions(&buf, mod);
2405 add_depends(&buf, mod);
2406 add_moddevtable(&buf, mod);
2407 add_srcversion(&buf, mod);
2408
2409 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
2410 if (ret >= sizeof(fname)) {
2411 error("%s: too long path was truncated\n", fname);
2412 goto free;
2413 }
2414
2415 write_if_changed(&buf, fname);
2416
2417free:
2418 free(buf.p);
2419}
2420
2393/* parse Module.symvers file. line format:2421/* parse Module.symvers file. line format:
2394 * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace2422 * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
2395 **/2423 **/
@@ -2494,7 +2522,6 @@ struct dump_list { · 98 unmodified lines
2494int main(int argc, char **argv)2522int main(int argc, char **argv)
2495{2523{
2496 struct module *mod;2524 struct module *mod;
2497 struct buffer buf = { };
2498 char *missing_namespace_deps = NULL;2525 char *missing_namespace_deps = NULL;
2499 char *dump_write = NULL, *files_source = NULL;2526 char *dump_write = NULL, *files_source = NULL;
2500 int opt;2527 int opt;
@@ -2557,30 +2584,11 @@ int main(int argc, char **argv) · 56 unmodified lines
2557 read_symbols_from_files(files_source);2584 read_symbols_from_files(files_source);
2558 2585
2559 list_for_each_entry(mod, &modules, list) {2586 list_for_each_entry(mod, &modules, list) {
2560 char fname[PATH_MAX];2587 if (mod->from_dump)
2561 int ret;
2562
2563 if (mod->is_vmlinux || mod->from_dump)
2564 continue;
2565
2566 buf.pos = 0;
2567
2568 check_modname_len(mod);
2569 check_exports(mod);
2570
2571 add_header(&buf, mod);
2572 add_versions(&buf, mod);
2573 add_depends(&buf, mod);
2574 add_moddevtable(&buf, mod);
2575 add_srcversion(&buf, mod);
2576
2577 ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
2578 if (ret >= sizeof(fname)) {
2579 error("%s: too long path was truncated\n", fname);
2580 continue;2588 continue;
2581 }
2582 2589
2583 write_if_changed(&buf, fname);2590 if (!mod->is_vmlinux)
2591 write_mod_c_file(mod);
2584 }2592 }
2585 2593
2586 if (missing_namespace_deps)2594 if (missing_namespace_deps)
@@ -2606,7 +2614,5 @@ int main(int argc, char **argv) · 19 unmodified lines
2606 warn("suppressed %u unresolved symbol warnings because there were too many)\n",2614 warn("suppressed %u unresolved symbol warnings because there were too many)\n",
2607 nr_unresolved - MAX_UNRESOLVED_REPORTS);2615 nr_unresolved - MAX_UNRESOLVED_REPORTS);
2608 2616
2609 free(buf.p);
2610
2611 return error_occurred ? 1 : 0;2617 return error_occurred ? 1 : 0;
2612}2618}