Commit a44abaca authored by Masahiro Yamada's avatar Masahiro Yamada

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.
Signed-off-by: default avatarMasahiro Yamada <masahiroy@kernel.org>
Reviewed-by: default avatarNicolas Schier <nicolas@fjasle.eu>
Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
parent 7fedac96
...@@ -2390,6 +2390,34 @@ static void write_if_changed(struct buffer *b, const char *fname) ...@@ -2390,6 +2390,34 @@ static void write_if_changed(struct buffer *b, const char *fname)
write_buf(b, fname); write_buf(b, fname);
} }
/* do sanity checks, and generate *.mod.c file */
static void write_mod_c_file(struct module *mod)
{
struct buffer buf = { };
char fname[PATH_MAX];
int ret;
check_modname_len(mod);
check_exports(mod);
add_header(&buf, mod);
add_versions(&buf, mod);
add_depends(&buf, mod);
add_moddevtable(&buf, mod);
add_srcversion(&buf, mod);
ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
if (ret >= sizeof(fname)) {
error("%s: too long path was truncated\n", fname);
goto free;
}
write_if_changed(&buf, fname);
free:
free(buf.p);
}
/* parse Module.symvers file. line format: /* parse Module.symvers file. line format:
* 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace * 0x12345678<tab>symbol<tab>module<tab>export<tab>namespace
**/ **/
...@@ -2494,7 +2522,6 @@ struct dump_list { ...@@ -2494,7 +2522,6 @@ struct dump_list {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct module *mod; struct module *mod;
struct buffer buf = { };
char *missing_namespace_deps = NULL; char *missing_namespace_deps = NULL;
char *dump_write = NULL, *files_source = NULL; char *dump_write = NULL, *files_source = NULL;
int opt; int opt;
...@@ -2557,30 +2584,11 @@ int main(int argc, char **argv) ...@@ -2557,30 +2584,11 @@ int main(int argc, char **argv)
read_symbols_from_files(files_source); read_symbols_from_files(files_source);
list_for_each_entry(mod, &modules, list) { list_for_each_entry(mod, &modules, list) {
char fname[PATH_MAX]; if (mod->from_dump)
int ret;
if (mod->is_vmlinux || mod->from_dump)
continue;
buf.pos = 0;
check_modname_len(mod);
check_exports(mod);
add_header(&buf, mod);
add_versions(&buf, mod);
add_depends(&buf, mod);
add_moddevtable(&buf, mod);
add_srcversion(&buf, mod);
ret = snprintf(fname, sizeof(fname), "%s.mod.c", mod->name);
if (ret >= sizeof(fname)) {
error("%s: too long path was truncated\n", fname);
continue; continue;
}
write_if_changed(&buf, fname); if (!mod->is_vmlinux)
write_mod_c_file(mod);
} }
if (missing_namespace_deps) if (missing_namespace_deps)
...@@ -2606,7 +2614,5 @@ int main(int argc, char **argv) ...@@ -2606,7 +2614,5 @@ int main(int argc, char **argv)
warn("suppressed %u unresolved symbol warnings because there were too many)\n", warn("suppressed %u unresolved symbol warnings because there were too many)\n",
nr_unresolved - MAX_UNRESOLVED_REPORTS); nr_unresolved - MAX_UNRESOLVED_REPORTS);
free(buf.p);
return error_occurred ? 1 : 0; return error_occurred ? 1 : 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment