@@ -9778,21 +9778,20 @@ struct VM {
97789778
97799779 while ((ent = readdir (dir)) != nullptr ) {
97809780 std::string dev_name = ent->d_name ;
9781-
9782- if (dev_name == " ." || dev_name == " .." ) {
9781+ if (dev_name == " ." || dev_name == " .." )
97839782 continue ;
9784- }
9785-
97869783 std::string dev_path = pci_path + " /" + dev_name;
97879784#endif
97889785 PCI_Device dev;
97899786
97909787 std::ifstream vendor_file (dev_path + " /vendor" );
97919788 std::ifstream device_file (dev_path + " /device" );
9789+ if (!vendor_file || !device_file) {
9790+ continue ;
9791+ }
97929792
97939793 vendor_file >> std::hex >> dev.vendor_id ;
97949794 device_file >> std::hex >> dev.device_id ;
9795-
97969795 devices.push_back (dev);
97979796 }
97989797
@@ -9801,24 +9800,24 @@ struct VM {
98019800 debug (" -------------------------" );
98029801 debug (" Vendor ID | Device ID " );
98039802 debug (" -------------------------" );
9804-
9805- for (const auto & dev : devices) {
9803+ for (const auto & d : devices) {
98069804 debug (
9807- " 0x" , std::setw (4 ), std::setfill (' 0' ), std::hex, dev.vendor_id , " | "
9808- " 0x" , std::setw (4 ), std::setfill (' 0' ), dev.device_id , " | " , std::dec
9805+ " 0x" , std::setw (4 ), std::setfill (' 0' ), std::hex, d.vendor_id ,
9806+ " | 0x" , std::setw (4 ), std::setfill (' 0' ), std::hex, d.device_id ,
9807+ std::dec
98099808 );
98109809 }
98119810#endif
98129811
9813- auto found = [](const std::string& b) -> bool {
9812+ auto found = [](const std::string& b, const PCI_Device& d ) -> bool {
98149813 debug (
9815- " PCI_VM_DEVICE_ID: found " , b, " , vendor ID = " ,
9816- " 0x" , std::setw (4 ), std::setfill (' 0' ), std::hex, dev.vendor_id ,
9817- " device ID = 0x" , std::setw (4 ), std::setfill (' 0' ), std::hex, dev.device_id
9814+ " PCI_VM_DEVICE_ID: found " , b,
9815+ " , vendor ID = 0x" , std::setw (4 ), std::setfill (' 0' ), std::hex, d.vendor_id ,
9816+ " device ID = 0x" , std::setw (4 ), std::setfill (' 0' ), std::hex, d.device_id ,
9817+ std::dec
98189818 );
9819-
98209819 return true ;
9821- };
9820+ };
98229821
98239822 for (const auto & dev : devices) {
98249823 const u32 id = ((dev.vendor_id << 16 ) | dev.device_id );
0 commit comments