summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2023-03-05 14:56:52 +0100
committerMartin Mares <mj@ucw.cz>2023-03-05 14:56:52 +0100
commitdc01e5b3429c88bcb1920af3f52d44b23b3fb0a9 (patch)
tree8ae5dcc1646c9d23ae8511222c50e2d45cc13c15
parent2ba0f6f434abbad44888e9ad372d7b562570cd1f (diff)
downloadpciutils-dc01e5b3429c88bcb1920af3f52d44b23b3fb0a9.tar.gz
Parameters: Keep the list sorted and remove duplicates
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.
-rw-r--r--lib/params.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/params.c b/lib/params.c
index 4d48cab..979fb16 100644
--- a/lib/params.c
+++ b/lib/params.c
@@ -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;