]> mj.ucw.cz Git - pciutils.git/commitdiff
Names: Fixed a rare bug in loading of pci.ids
authorMartin Mares <mj@ucw.cz>
Sun, 18 Feb 2024 00:37:49 +0000 (01:37 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 18 Feb 2024 00:37:49 +0000 (01:37 +0100)
If the pci.ids file was empty, it was never considered loaded,
so the loading function was called repeatedly and it always flushed
the name cache.

lib/names-parse.c
lib/names.c
lib/pci.h

index f50b8ecd3dacb157e8d31252704064f4318e11f8..1f8925a34f44856c161e0a0b89456518d2bf8ee0 100644 (file)
@@ -223,7 +223,7 @@ pci_load_name_list(struct pci_access *a)
   const char *err;
 
   pci_free_name_list(a);
-  a->id_load_failed = 1;
+  a->id_load_attempted = 1;
   if (!(f = pci_open(a)))
     return 0;
   err = id_parse_list(a, f, &lino);
@@ -231,7 +231,6 @@ pci_load_name_list(struct pci_access *a)
   pci_close(f);
   if (err)
     a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
-  a->id_load_failed = 0;
   return 1;
 }
 
@@ -241,7 +240,7 @@ pci_free_name_list(struct pci_access *a)
   pci_id_cache_flush(a);
   pci_id_hash_free(a);
   pci_id_hwdb_free(a);
-  a->id_load_failed = 0;
+  a->id_load_attempted = 0;
 }
 
 void
index f8d39971c84ffb1759d2daee87d7539e4868d554..a287cb0150d78f481a76c3202642acac2c95296e 100644 (file)
@@ -143,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)
index 03b4c41694ff03d4302f6564336d4e6757f43162..b3386d75c77f84ff7ec8cb483e231d9a0ec74b0b 100644 (file)
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -81,7 +81,7 @@ struct pci_access {
   struct pci_param *params;
   struct id_entry **id_hash;           /* names.c */
   struct id_bucket *current_id_bucket;
-  int id_load_failed;
+  int id_load_attempted;
   int id_cache_status;                 /* 0=not read, 1=read, 2=dirty */
   struct udev *id_udev;                        /* names-hwdb.c */
   struct udev_hwdb *id_udev_hwdb;