summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2013-04-19 13:33:52 +0200
committerMartin Mares <mj@ucw.cz>2013-04-19 13:33:52 +0200
commitb069b79a29feb278ff3314579f33878d184d5509 (patch)
tree7198e65b9418ee97f00ea22d273c7fa2ca3994fb
parent4baec529d0e7ce233b62e1f4ac2f77e739b81b10 (diff)
downloadpciutils-b069b79a29feb278ff3314579f33878d184d5509.tar.gz
lspci: Better filtering of duplicate kernel module names
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.
-rw-r--r--ls-kernel.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/ls-kernel.c b/ls-kernel.c
index 15aa46a..78b70f1 100644
--- a/ls-kernel.c
+++ b/ls-kernel.c
@@ -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);
}