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
23902390 write_buf(b, fname);
23912391 }
23922392
2393+/* do sanity checks, and generate *.mod.c file */
2394+static 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+
2417+free:
2418+ free(buf.p);
2419+}
2420+
23932421 /* parse Module.symvers file. line format:
23942422 * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
23952423 **/
@@ -2494,7 +2522,6 @@ struct dump_list { · 98 unmodified lines
24942522 int main(int argc, char **argv)
24952523 {
24962524 struct module *mod;
2497− struct buffer buf = { };
24982525 char *missing_namespace_deps = NULL;
24992526 char *dump_write = NULL, *files_source = NULL;
25002527 int opt;
@@ -2557,30 +2584,11 @@ int main(int argc, char **argv) · 56 unmodified lines
25572584 read_symbols_from_files(files_source);
25582585
25592586 list_for_each_entry(mod, &modules, list) {
2560− char fname[PATH_MAX];
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);
2587+ if (mod->from_dump)
25802588 continue;
2581− }
25822589
2583− write_if_changed(&buf, fname);
2590+ if (!mod->is_vmlinux)
2591+ write_mod_c_file(mod);
25842592 }
25852593
25862594 if (missing_namespace_deps)
@@ -2606,7 +2614,5 @@ int main(int argc, char **argv) · 19 unmodified lines
26062614 warn("suppressed %u unresolved symbol warnings because there were too many)\n",
26072615 nr_unresolved - MAX_UNRESOLVED_REPORTS);
26082616
2609− free(buf.p);
2610−
26112617 return error_occurred ? 1 : 0;
26122618 }