]> git.ipfire.org Git - thirdparty/pciutils.git/commitdiff
lspci: Better filtering of duplicate kernel module names
authorMartin Mares <mj@ucw.cz>
Fri, 19 Apr 2013 11:33:52 +0000 (13:33 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 19 Apr 2013 11:33:52 +0000 (13:33 +0200)
It was implemented only for reading modules.pcimap, but it turned out
that it is necessary for libkmod, too, so we have switched to a common
implementation.

ls-kernel.c

index 15aa46ac083da890f5572998b2d9c989b411b546..78b70f19e1f5eeef68a901b5f59476d2bae3f5c0 100644 (file)
@@ -196,19 +196,16 @@ match_pcimap(struct device *d, struct pcimap_entry *e)
 
 static const char *next_module(struct device *d)
 {
-  static struct pcimap_entry *current, *last_printed;
+  static struct pcimap_entry *current;
 
   if (!current)
-    {
-      current = pcimap_head;
-      last_printed = NULL;
-    }
+    current = pcimap_head;
   else
     current = current->next;
 
   while (current)
     {
-      if (match_pcimap(d, current) && (!last_printed || strcmp(last_printed->module, current->module)))
+      if (match_pcimap(d, current))
        return current->module;
       current = current->next;
     }
@@ -257,6 +254,25 @@ find_driver(struct device *d, char *buf)
     return buf;
 }
 
+static const char *
+next_module_filtered(struct device *d)
+{
+  static char prev_module[256];
+  const char *module;
+
+  while (module = next_module(d))
+    {
+      if (strcmp(module, prev_module))
+       {
+         strncpy(prev_module, module, sizeof(prev_module));
+         prev_module[sizeof(prev_module) - 1] = 0;
+         return module;
+       }
+    }
+  prev_module[0] = 0;
+  return NULL;
+}
+
 void
 show_kernel(struct device *d)
 {
@@ -270,7 +286,7 @@ show_kernel(struct device *d)
     return;
 
   int cnt = 0;
-  while (module = next_module(d))
+  while (module = next_module_filtered(d))
     printf("%s %s", (cnt++ ? "," : "\tKernel modules:"), module);
   if (cnt)
     putchar('\n');
@@ -288,7 +304,7 @@ show_kernel_machine(struct device *d)
   if (!show_kernel_init())
     return;
 
-  while (module = next_module(d))
+  while (module = next_module_filtered(d))
     printf("Module:\t%s\n", module);
 }