]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/params.c
libpci: ecam: Fix big address range mappings
[pciutils.git] / lib / params.c
index 4d48cab00b37f9e5946103fa33b7602d874174c5..ac756ad79a313661e13f3d67cf85ec5e3cd43bf6 100644 (file)
@@ -1,9 +1,11 @@
 /*
  *     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.
+ *     Can be freely distributed and used under the terms of the GNU GPL v2+.
+ *
+ *     SPDX-License-Identifier: GPL-2.0-or-later
  */
 
 #include <stdio.h>
@@ -26,10 +28,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;
+
+  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->next = acc->params;
-  acc->params = p;
+  p = pci_malloc(acc, sizeof(*p));
+  p->next = *pp;
+  *pp = p;
   p->param = param;
   p->value = value;
   p->value_malloced = 0;