aboutsummaryrefslogtreecommitdiff
path: root/scripts/mod/modpost.c
diff options
context:
space:
mode:
authorMasahiro Yamada2022-05-01 17:40:10 +0900
committerMasahiro Yamada2022-05-08 03:17:00 +0900
commit325eba05e8ab53a9182a2734f0986c15e5f87349 (patch)
treeb89301cee58214b36383f0d813dda02ab24dec57 /scripts/mod/modpost.c
parent97aa4aef532aed6885e887ad6979e5ffb2667c84 (diff)
modpost: traverse modules in order
Currently, modpost manages modules in a singly linked list; it adds a new node to the head, and traverses the list from new to old. It works, but the error messages are shown in the reverse order. If you have a Makefile like this: obj-m += foo.o bar.o then, modpost shows error messages in bar.o, foo.o, in this order. Use a doubly linked list to keep the order in modules.order; use list_add_tail() for the node addition and list_for_each_entry() for the list traverse. Now that the kernel's list macros have been imported to modpost, I will use them actively going forward. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Diffstat (limited to 'scripts/mod/modpost.c')
-rw-r--r--scripts/mod/modpost.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 25066dc25790..1b9dcb44621c 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -165,16 +165,17 @@ char *get_line(char **stringp)
}
/* A list of all modules we processed */
-static struct module *modules;
+LIST_HEAD(modules);
static struct module *find_module(const char *modname)
{
struct module *mod;
- for (mod = modules; mod; mod = mod->next)
+ list_for_each_entry(mod, &modules, list) {
if (strcmp(mod->name, modname) == 0)
- break;
- return mod;
+ return mod;
+ }
+ return NULL;
}
static struct module *new_module(const char *modname)
@@ -184,7 +185,6 @@ static struct module *new_module(const char *modname)
mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1));
memset(mod, 0, sizeof(*mod));
- /* add to list */
strcpy(mod->name, modname);
mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0);
@@ -195,8 +195,7 @@ static struct module *new_module(const char *modname)
*/
mod->is_gpl_compatible = true;
- mod->next = modules;
- modules = mod;
+ list_add_tail(&mod->list, &modules);
return mod;
}
@@ -2477,7 +2476,7 @@ static void write_namespace_deps_files(const char *fname)
struct namespace_list *ns;
struct buffer ns_deps_buf = {};
- for (mod = modules; mod; mod = mod->next) {
+ list_for_each_entry(mod, &modules, list) {
if (mod->from_dump || !mod->missing_namespaces)
continue;
@@ -2568,7 +2567,7 @@ int main(int argc, char **argv)
if (files_source)
read_symbols_from_files(files_source);
- for (mod = modules; mod; mod = mod->next) {
+ list_for_each_entry(mod, &modules, list) {
char fname[PATH_MAX];
int ret;