From f69a2a3db061756a234c92b884e38dec20c3f679 Mon Sep 17 00:00:00 2001 From: Niklas Eiling Date: Tue, 20 Dec 2022 14:29:36 +0100 Subject: [PATCH] remove hardcoded pcie device id in pci.cpp Signed-off-by: Niklas Eiling --- common/lib/kernel/pci.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/lib/kernel/pci.cpp b/common/lib/kernel/pci.cpp index 78d5e8ddd..29a4e21a8 100644 --- a/common/lib/kernel/pci.cpp +++ b/common/lib/kernel/pci.cpp @@ -393,7 +393,14 @@ bool Device::attachDriver(const std::string &driver) const bool Device::readHostBar(uint32_t &bar) const { unsigned long long start, end, size, flags; - FILE *file = fopen("/sys/bus/pci/devices/0000:88:00.0/resource", "r"); + char *path = NULL; + if (asprintf(&path, "%s/bus/pci/devices/%04x:%02x:%02x.%x/resource", SYSFS_PATH, + slot.domain, slot.bus, slot.device, slot.function) == -1) + { + log->error("could not allocate memory for path"); + return false; + } + FILE *file = fopen(path, "r"); if (!file) { log->error("error opening resource file");