@@ -62,7 +62,7 @@ impl PciDevice {
62
62
}
63
63
}
64
64
65
- pub fn get_sub_device_name ( & self , db : & Database ) -> Option < String > {
65
+ pub fn get_device_name ( & self , db : & Database ) -> Option < String > {
66
66
let vendor_value = self . read_value ( PciDeviceReadableValues :: Vendor ) ;
67
67
let sub_vendor_value = self . read_value ( PciDeviceReadableValues :: SubVendor ) ;
68
68
let device_value = self . read_value ( PciDeviceReadableValues :: Device ) ;
@@ -75,6 +75,8 @@ impl PciDevice {
75
75
let Some ( device) = vendor. devices . get ( & device_value) else {
76
76
return None ;
77
77
} ;
78
+ // To return device name if no valid subdevice name is found
79
+ let device_name = device. name . to_owned ( ) ;
78
80
79
81
let sub_device_id = SubDeviceId {
80
82
subvendor : sub_vendor_value,
@@ -84,20 +86,16 @@ impl PciDevice {
84
86
if let Some ( sub_device) = device. subdevices . get ( & sub_device_id) {
85
87
let start = match sub_device. find ( '[' ) {
86
88
Some ( i) => i + 1 ,
87
- _ => panic ! (
88
- "Could not find opening square bracket for sub device: {}" ,
89
- sub_device
90
- ) ,
89
+ _ => return Some ( device_name) ,
91
90
} ;
92
91
let end = sub_device. len ( ) - 1 ;
93
92
94
93
Some ( sub_device. chars ( ) . take ( end) . skip ( start) . collect :: < String > ( ) )
95
94
} else {
96
- None
95
+ Some ( device_name )
97
96
}
98
97
}
99
98
}
100
-
101
99
pub fn get_pci_devices ( ) -> Result < Vec < PciDevice > , io:: Error > {
102
100
let devices_dir = read_dir ( "/sys/bus/pci/devices/" ) ?;
103
101
0 commit comments