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.

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>

+10 -10
+8 -9
scripts/mod/modpost.c
··· 165 165 } 166 166 167 167 /* A list of all modules we processed */ 168 - static struct module *modules; 168 + LIST_HEAD(modules); 169 169 170 170 static struct module *find_module(const char *modname) 171 171 { 172 172 struct module *mod; 173 173 174 - for (mod = modules; mod; mod = mod->next) 174 + list_for_each_entry(mod, &modules, list) { 175 175 if (strcmp(mod->name, modname) == 0) 176 - break; 177 - return mod; 176 + return mod; 177 + } 178 + return NULL; 178 179 } 179 180 180 181 static struct module *new_module(const char *modname) ··· 185 184 mod = NOFAIL(malloc(sizeof(*mod) + strlen(modname) + 1)); 186 185 memset(mod, 0, sizeof(*mod)); 187 186 188 - /* add to list */ 189 187 strcpy(mod->name, modname); 190 188 mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0); 191 189 ··· 195 195 */ 196 196 mod->is_gpl_compatible = true; 197 197 198 - mod->next = modules; 199 - modules = mod; 198 + list_add_tail(&mod->list, &modules); 200 199 201 200 return mod; 202 201 } ··· 2476 2477 struct namespace_list *ns; 2477 2478 struct buffer ns_deps_buf = {}; 2478 2479 2479 - for (mod = modules; mod; mod = mod->next) { 2480 + list_for_each_entry(mod, &modules, list) { 2480 2481 2481 2482 if (mod->from_dump || !mod->missing_namespaces) 2482 2483 continue; ··· 2567 2568 if (files_source) 2568 2569 read_symbols_from_files(files_source); 2569 2570 2570 - for (mod = modules; mod; mod = mod->next) { 2571 + list_for_each_entry(mod, &modules, list) { 2571 2572 char fname[PATH_MAX]; 2572 2573 int ret; 2573 2574
+2 -1
scripts/mod/modpost.h
··· 11 11 #include <unistd.h> 12 12 #include <elf.h> 13 13 14 + #include "list.h" 14 15 #include "elfconfig.h" 15 16 16 17 /* On BSD-alike OSes elf.h defines these according to host's word size */ ··· 112 111 buf_write(struct buffer *buf, const char *s, int len); 113 112 114 113 struct module { 115 - struct module *next; 114 + struct list_head list; 116 115 bool is_gpl_compatible; 117 116 struct symbol *unres; 118 117 bool from_dump; /* true if module was loaded from *.symvers */