History

modpost: traverse the namespace_list in order

Use the doubly linked list to traverse the list in the added order. This makes the code more consistent.

Masahiro Yamada committed 4 years ago

Commit ab489d61 parent 44840542 files · +17 −20Browse files

Showing the changes to scripts (2 of 2 files). Show all

Unified · Split

2 files
  1. scripts/mod/modpost.c +15 −18
  2. scripts/mod/modpost.h +2 −2
scripts/mod/modpost.c+15−18
@@ -186,6 +186,8 @@ static struct module *new_module(const char *modname) · 185 unmodified lines
186186 memset(mod, 0, sizeof(*mod));
187187
188188 INIT_LIST_HEAD(&mod->unresolved_symbols);
189+ INIT_LIST_HEAD(&mod->missing_namespaces);
190+ INIT_LIST_HEAD(&mod->imported_namespaces);
189191
190192 strcpy(mod->name, modname);
191193 mod->is_vmlinux = (strcmp(modname, "vmlinux") == 0);
@@ -288,39 +290,34 @@ static struct symbol *find_symbol(const char *name) · 96 unmodified lines
288290 }
289291
290292 struct namespace_list {
291− struct namespace_list *next;
293+ struct list_head list;
292294 char namespace[];
293295 };
294296
295−static bool contains_namespace(struct namespace_list *list,
296− const char *namespace)
297+static bool contains_namespace(struct list_head *head, const char *namespace)
297298 {
298− for (; list; list = list->next)
299+ struct namespace_list *list;
300+
301+ list_for_each_entry(list, head, list) {
299302 if (!strcmp(list->namespace, namespace))
300303 return true;
304+ }
301305
302306 return false;
303307 }
304308
305−static void add_namespace(struct namespace_list **list, const char *namespace)
309+static void add_namespace(struct list_head *head, const char *namespace)
306310 {
307311 struct namespace_list *ns_entry;
308312
309− if (!contains_namespace(*list, namespace)) {
310− ns_entry = NOFAIL(malloc(sizeof(struct namespace_list) +
313+ if (!contains_namespace(head, namespace)) {
314+ ns_entry = NOFAIL(malloc(sizeof(*ns_entry) +
311315 strlen(namespace) + 1));
312316 strcpy(ns_entry->namespace, namespace);
313− ns_entry->next = *list;
314− *list = ns_entry;
317+ list_add_tail(&ns_entry->list, head);
315318 }
316319 }
317320
318−static bool module_imports_namespace(struct module *module,
319− const char *namespace)
320−{
321− return contains_namespace(module->imported_namespaces, namespace);
322−}
323−
324321 static const struct {
325322 const char *str;
326323 enum export export;
@@ -2190,7 +2187,7 @@ static void check_exports(struct module *mod) · 1863 unmodified lines
21902187 basename = mod->name;
21912188
21922189 if (exp->namespace &&
2193− !module_imports_namespace(mod, exp->namespace)) {
2190+ !contains_namespace(&mod->imported_namespaces, exp->namespace)) {
21942191 modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR,
21952192 "module %s uses symbol %s from namespace %s, but does not import it.\n",
21962193 basename, exp->name, exp->namespace);
@@ -2489,12 +2486,12 @@ static void write_namespace_deps_files(const char *fname) · 292 unmodified lines
24892486
24902487 list_for_each_entry(mod, &modules, list) {
24912488
2492− if (mod->from_dump || !mod->missing_namespaces)
2489+ if (mod->from_dump || list_empty(&mod->missing_namespaces))
24932490 continue;
24942491
24952492 buf_printf(&ns_deps_buf, "%s.ko:", mod->name);
24962493
2497− for (ns = mod->missing_namespaces; ns; ns = ns->next)
2494+ list_for_each_entry(ns, &mod->missing_namespaces, list)
24982495 buf_printf(&ns_deps_buf, " %s", ns->namespace);
24992496
25002497 buf_printf(&ns_deps_buf, "\n");
scripts/mod/modpost.h+2−2
@@ -123,9 +123,9 @@ struct module { · 122 unmodified lines
123123 struct buffer dev_table_buf;
124124 char srcversion[25];
125125 // Missing namespace dependencies
126− struct namespace_list *missing_namespaces;
126+ struct list_head missing_namespaces;
127127 // Actual imported namespaces
128− struct namespace_list *imported_namespaces;
128+ struct list_head imported_namespaces;
129129 char name[];
130130 };
131131

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t