From 62bd0c5cfd69fe5678c4f106cd88fccfb9cd88b2 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 26 Jun 2018 12:14:18 +0200 Subject: [PATCH] Convert other string properties to the generic mechanism 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 | 8 +++----- lib/sysfs.c | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/access.c b/lib/access.c index 52f1432..fefedf6 100644 --- a/lib/access.c +++ b/lib/access.c @@ -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); } diff --git a/lib/sysfs.c b/lib/sysfs.c index b826e97..1adb50f 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -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)) -- 2.39.2