]> git.ipfire.org Git - thirdparty/pciutils.git/commitdiff
Convert other string properties to the generic mechanism
authorMartin Mares <mj@ucw.cz>
Tue, 26 Jun 2018 10:14:18 +0000 (12:14 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 26 Jun 2018 10:14:18 +0000 (12:14 +0200)
This removes the need of explicit memory management and fixes
PCI_FILL_RESCAN.

To keep backward compatibility, I am keeping the raw pointers
in struct pci_dev, but they point inside the pci_property instead
of separately allocated memory.

lib/access.c
lib/sysfs.c

index 52f1432915a798899108b54e5e55bb3bb511152a..fefedf60d46d6b67d0dfd3932ca535eb346bac08 100644 (file)
@@ -86,11 +86,6 @@ void pci_free_dev(struct pci_dev *d)
 
   pci_free_caps(d);
   pci_free_properties(d);
-
-  pci_mfree(d->module_alias);
-  pci_mfree(d->label);
-  pci_mfree(d->phy_slot);
-
   pci_mfree(d);
 }
 
@@ -186,6 +181,9 @@ static void
 pci_reset_properties(struct pci_dev *d)
 {
   d->known_fields = 0;
+  d->phy_slot = NULL;
+  d->module_alias = NULL;
+  d->label = NULL;
   pci_free_caps(d);
   pci_free_properties(d);
 }
index b826e97ccf8fbbd87695ea12f1e883e002b33780..1adb50f1c4072e429cde63d9b127eefd9ec05c7c 100644 (file)
@@ -293,7 +293,7 @@ sysfs_fill_slots(struct pci_access *a)
        {
          for (d = a->devices; d; d = d->next)
            if (dom == (unsigned)d->domain && bus == d->bus && dev == d->dev && !d->phy_slot)
-             d->phy_slot = pci_strdup(a, entry->d_name);
+             d->phy_slot = pci_set_property(d, PCI_FILL_PHYS_SLOT, entry->d_name);
        }
       fclose(file);
     }
@@ -315,14 +315,14 @@ sysfs_fill_info(struct pci_dev *d, int flags)
     {
       char buf[OBJBUFSIZE];
       if (sysfs_get_string(d, "modalias", buf, 0))
-       d->module_alias = pci_strdup(d->access, buf);
+       d->module_alias = pci_set_property(d, PCI_FILL_MODULE_ALIAS, buf);
     }
 
   if ((flags & PCI_FILL_LABEL) && !(d->known_fields & PCI_FILL_LABEL))
     {
       char buf[OBJBUFSIZE];
       if (sysfs_get_string(d, "label", buf, 0))
-       d->label = pci_strdup(d->access, buf);
+       d->label = pci_set_property(d, PCI_FILL_LABEL, buf);
     }
 
   if ((flags & PCI_FILL_NUMA_NODE) && !(d->known_fields & PCI_FILL_NUMA_NODE))