]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/names.c
libpci: ecam: Fix detect sequence when addresses are not specified
[pciutils.git] / lib / names.c
index d5353a8084407b902c9d57695d4df0f9ff1739e5..a287cb0150d78f481a76c3202642acac2c95296e 100644 (file)
@@ -3,7 +3,9 @@
  *
  *     Copyright (c) 1997--2014 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>
@@ -31,6 +33,7 @@ static char *id_lookup(struct pci_access *a, int flags, int cat, int id1, int id
          if (name = pci_id_hwdb_lookup(a, cat, id1, id2, id3, id4))
            {
              pci_id_insert(a, cat, id1, id2, id3, id4, name, SRC_HWDB);
+             pci_mfree(name);
              continue;
            }
        }
@@ -140,7 +143,7 @@ pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...)
   if (flags & PCI_LOOKUP_MIXED)
     flags &= ~PCI_LOOKUP_NUMERIC;
 
-  if (!a->id_hash && !(flags & (PCI_LOOKUP_NUMERIC | PCI_LOOKUP_SKIP_LOCAL)) && !a->id_load_failed)
+  if (!a->id_load_attempted && !(flags & (PCI_LOOKUP_NUMERIC | PCI_LOOKUP_SKIP_LOCAL)))
     pci_load_name_list(a);
 
   switch (flags & 0xffff)
@@ -148,11 +151,13 @@ pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...)
     case PCI_LOOKUP_VENDOR:
       iv = va_arg(args, int);
       sprintf(numbuf, "%04x", iv);
+      va_end(args);
       return format_name(buf, size, flags, id_lookup(a, flags, ID_VENDOR, iv, 0, 0, 0), numbuf, "Vendor");
     case PCI_LOOKUP_DEVICE:
       iv = va_arg(args, int);
       id = va_arg(args, int);
       sprintf(numbuf, "%04x", id);
+      va_end(args);
       return format_name(buf, size, flags, id_lookup(a, flags, ID_DEVICE, iv, id, 0, 0), numbuf, "Device");
     case PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE:
       iv = va_arg(args, int);
@@ -160,11 +165,13 @@ pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...)
       sprintf(numbuf, "%04x:%04x", iv, id);
       v = id_lookup(a, flags, ID_VENDOR, iv, 0, 0, 0);
       d = id_lookup(a, flags, ID_DEVICE, iv, id, 0, 0);
+      va_end(args);
       return format_name_pair(buf, size, flags, v, d, numbuf);
     case PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_VENDOR:
       isv = va_arg(args, int);
       sprintf(numbuf, "%04x", isv);
       v = id_lookup(a, flags, ID_VENDOR, isv, 0, 0, 0);
+      va_end(args);
       return format_name(buf, size, flags, v, numbuf, "Unknown vendor");
     case PCI_LOOKUP_SUBSYSTEM | PCI_LOOKUP_DEVICE:
       iv = va_arg(args, int);
@@ -172,6 +179,7 @@ pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...)
       isv = va_arg(args, int);
       isd = va_arg(args, int);
       sprintf(numbuf, "%04x", isd);
+      va_end(args);
       return format_name(buf, size, flags, id_lookup_subsys(a, flags, iv, id, isv, isd), numbuf, "Device");
     case PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE | PCI_LOOKUP_SUBSYSTEM:
       iv = va_arg(args, int);
@@ -181,6 +189,7 @@ pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...)
       v = id_lookup(a, flags, ID_VENDOR, isv, 0, 0, 0);
       d = id_lookup_subsys(a, flags, iv, id, isv, isd);
       sprintf(numbuf, "%04x:%04x", isv, isd);
+      va_end(args);
       return format_name_pair(buf, size, flags, v, d, numbuf);
     case PCI_LOOKUP_CLASS:
       icls = va_arg(args, int);
@@ -191,6 +200,7 @@ pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...)
          if (!(flags & PCI_LOOKUP_NUMERIC)) /* Include full class number */
            flags |= PCI_LOOKUP_MIXED;
        }
+      va_end(args);
       return format_name(buf, size, flags, cls, numbuf, "Class");
     case PCI_LOOKUP_PROGIF:
       icls = va_arg(args, int);
@@ -210,8 +220,10 @@ pci_lookup_name(struct pci_access *a, char *buf, int size, int flags, ...)
          if (*pif)
            pif++;
        }
+      va_end(args);
       return format_name(buf, size, flags, pif, numbuf, "ProgIf");
     default:
+      va_end(args);
       return "<pci_lookup_name: invalid request>";
     }
 }