History

modpost: use doubly linked list for dump_lists

This looks easier to understand (just because this is a pattern in the kernel code). No functional change is intended.

Masahiro Yamada committed 4 years ago

Commit 44840541 parent 8a691521 file · +10 −14Browse files

Showing the changes to scripts (1 of 1 file). Show all

Unified · Split

scripts/mod/modpost.c+10−14
@@ -2505,7 +2505,7 @@ static void write_namespace_deps_files(const char *fname) · 2504 unmodified lines
25052505 }
25062506
25072507 struct dump_list {
2508− struct dump_list *next;
2508+ struct list_head list;
25092509 const char *file;
25102510 };
25112511
@@ -2517,8 +2517,8 @@ int main(int argc, char **argv) · 5 unmodified lines
25172517 char *dump_write = NULL, *files_source = NULL;
25182518 int opt;
25192519 int n;
2520− struct dump_list *dump_read_start = NULL;
2521− struct dump_list **dump_read_iter = &dump_read_start;
2520+ LIST_HEAD(dump_lists);
2521+ struct dump_list *dl, *dl2;
25222522
25232523 while ((opt = getopt(argc, argv, "ei:mnT:o:awENd:")) != -1) {
25242524 switch (opt) {
@@ -2526,10 +2526,9 @@ int main(int argc, char **argv) · 1 unmodified line
25262526 external_module = true;
25272527 break;
25282528 case 'i':
2529− *dump_read_iter =
2530− NOFAIL(calloc(1, sizeof(**dump_read_iter)));
2531− (*dump_read_iter)->file = optarg;
2532− dump_read_iter = &(*dump_read_iter)->next;
2529+ dl = NOFAIL(malloc(sizeof(*dl)));
2530+ dl->file = optarg;
2531+ list_add_tail(&dl->list, &dump_lists);
25332532 break;
25342533 case 'm':
25352534 modversions = true;
@@ -2563,13 +2562,10 @@ int main(int argc, char **argv) · 27 unmodified lines
25632562 }
25642563 }
25652564
2566− while (dump_read_start) {
2567− struct dump_list *tmp;
2568−
2569− read_dump(dump_read_start->file);
2570− tmp = dump_read_start->next;
2571− free(dump_read_start);
2572− dump_read_start = tmp;
2565+ list_for_each_entry_safe(dl, dl2, &dump_lists, list) {
2566+ read_dump(dl->file);
2567+ list_del(&dl->list);
2568+ free(dl);
25732569 }
25742570
25752571 while (optind < argc)