diff --git a/common/lib/kernel/pci.cpp b/common/lib/kernel/pci.cpp index 63cb4457e..53ebd1f77 100644 --- a/common/lib/kernel/pci.cpp +++ b/common/lib/kernel/pci.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -92,9 +93,11 @@ DeviceList::lookupDevice(const Id &i) DeviceList::value_type DeviceList::lookupDevice(const Device &d) { - return *std::find_if(begin(), end(), [d](const DeviceList::value_type &e) { + auto dev = std::find_if(begin(), end(), [d](const DeviceList::value_type &e) { return *e == d; }); + + return dev == end() ? value_type() : *dev; } Id::Id(const std::string &str) : @@ -327,6 +330,11 @@ Device::getDriver() const snprintf(sysfs, sizeof(sysfs), "%s/bus/pci/devices/%04x:%02x:%02x.%x/driver", SYSFS_PATH, slot.domain, slot.bus, slot.device, slot.function); + struct stat st; + ret = stat(sysfs, &st); + if (ret) + return ""; + ret = readlink(sysfs, syml, sizeof(syml)); if (ret < 0) throw SystemError("Failed to follow link: {}", sysfs); diff --git a/common/lib/memory_manager.cpp b/common/lib/memory_manager.cpp index 6d2d3e599..052ef5ba0 100644 --- a/common/lib/memory_manager.cpp +++ b/common/lib/memory_manager.cpp @@ -115,7 +115,7 @@ MemoryTranslation MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId, MemoryManager::AddressSpaceId toAddrSpaceId) { - /* Find a path through the memory graph */ + // Find a path through the memory graph MemoryGraph::Path path; if (not memoryGraph.getPath(fromAddrSpaceId, toAddrSpaceId, path, pathCheckFunc)) { @@ -127,10 +127,10 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId, throw std::out_of_range("no translation found"); } - /* Start with an identity mapping */ + // Start with an identity mapping MemoryTranslation translation(0, 0, SIZE_MAX); - /* Iterate through path and merge all mappings into a single translation */ + // Iterate through path and merge all mappings into a single translation for (auto &mappingId : path) { auto mapping = memoryGraph.getEdge(mappingId); translation += getTranslationFromMapping(*mapping); @@ -142,7 +142,7 @@ MemoryManager::getTranslation(MemoryManager::AddressSpaceId fromAddrSpaceId, bool MemoryManager::pathCheck(const MemoryGraph::Path &path) { - /* Start with an identity mapping */ + // Start with an identity mapping MemoryTranslation translation(0, 0, SIZE_MAX); /* Try to add all mappings together to a common translation. If this fails