From: Martin Mares Date: Sun, 5 Mar 2023 13:56:52 +0000 (+0100) Subject: Parameters: Keep the list sorted and remove duplicates X-Git-Tag: v3.10.0~7 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=dc01e5b3429c88bcb1920af3f52d44b23b3fb0a9;p=pciutils.git 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. --- 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 + * Copyright (c) 2008--2023 Martin Mares * * 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;