]> mj.ucw.cz Git - pciutils.git/commitdiff
Parameters: Keep the list sorted and remove duplicates
authorMartin Mares <mj@ucw.cz>
Sun, 5 Mar 2023 13:56:52 +0000 (14:56 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 5 Mar 2023 13:56:52 +0000 (14:56 +0100)
When multiple back-ends use the same option (e.g., "devmem.path"),
they tend to define it each. This is not nice, but before we generalize
these options properly, let us at least remove the duplicate definitions.

lib/params.c

index 4d48cab00b37f9e5946103fa33b7602d874174c5..979fb16dcaa53b41dcf29ca1f22a173cf249c4be 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     The PCI Library -- Parameters
  *
- *     Copyright (c) 2008 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 2008--2023 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
@@ -26,10 +26,24 @@ pci_get_param(struct pci_access *acc, char *param)
 void
 pci_define_param(struct pci_access *acc, char *param, char *value, char *help)
 {
-  struct pci_param *p = pci_malloc(acc, sizeof(*p));
+  struct pci_param *p, **pp;
 
-  p->next = acc->params;
-  acc->params = p;
+  for (pp=&acc->params; p = *pp; pp=&p->next)
+    {
+      int cmp = strcmp(p->param, param);
+      if (!cmp)
+       {
+         if (strcmp(p->value, value) || strcmp(p->help, help))
+           acc->error("Parameter %s re-defined differently", param);
+         return;
+       }
+      if (cmp > 0)
+       break;
+    }
+
+  p = pci_malloc(acc, sizeof(*p));
+  p->next = *pp;
+  *pp = p;
   p->param = param;
   p->value = value;
   p->value_malloced = 0;