aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2018-06-26 12:14:18 +0200
committerMartin Mares <mj@ucw.cz>2018-06-26 12:14:18 +0200
commit62bd0c5cfd69fe5678c4f106cd88fccfb9cd88b2 (patch)
treec630eefc6a1c825dcd2849757f019ae1a2fc9282
parentc02d903c2a8971718c7dea482075f4ddb8e3c1fe (diff)
downloadpciutils-62bd0c5cfd69fe5678c4f106cd88fccfb9cd88b2.tar.gz
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.
-rw-r--r--lib/access.c8
-rw-r--r--lib/sysfs.c6
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))