aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>2018-07-12 13:59:52 +0200
committerMartin Mares <mj@ucw.cz>2018-07-12 13:59:52 +0200
commitf15db375b857d3a2663dd7e13da0500c4daec762 (patch)
treebbeab980bd71d2b89eaf8546f3a8ffed93c7659a
parentffdb5c2802f728a6ff8aea5140d081553522c45c (diff)
downloadpciutils-f15db375b857d3a2663dd7e13da0500c4daec762.tar.gz
Sysfs: fixed sysfs_deref_link()
The function canonicalize_file_name() is GLIBC-specific, use realpath() instead, which is available also on MUSL libc. Also, it leaked memory.
-rw-r--r--lib/sysfs.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 1adb50f..42c88c6 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -133,7 +133,8 @@ sysfs_deref_link(struct pci_dev *d, char *link_name)
sysfs_obj_name(d, "", path);
strcat(path, rel_path);
- return canonicalize_file_name(path);
+ // Returns a pointer to malloc'ed memory
+ return realpath(path, NULL);
}
static int
@@ -329,7 +330,14 @@ sysfs_fill_info(struct pci_dev *d, int flags)
d->numa_node = sysfs_get_value(d, "numa_node", 0);
if ((flags & PCI_FILL_DT_NODE) && !(d->known_fields & PCI_FILL_DT_NODE))
- pci_set_property(d, PCI_FILL_DT_NODE, sysfs_deref_link(d, "of_node"));
+ {
+ char *node = sysfs_deref_link(d, "of_node");
+ if (node)
+ {
+ pci_set_property(d, PCI_FILL_DT_NODE, node);
+ free(node);
+ }
+ }
return pci_generic_fill_info(d, flags);
}