@@ -184,27 +184,21 @@ hwloc_calc_parse_level_filter(hwloc_topology_t topology __hwloc_attribute_unused
184
184
185
185
if (level -> type == HWLOC_OBJ_PCI_DEVICE ) {
186
186
/* try to match by [vendor:device] */
187
- char * endp ;
188
-
189
- level -> pci_vendor = strtoul (current , & endp , 16 );
190
- if (* endp != ':' ) {
191
- fprintf (stderr , "invalid PCI vendor:device filter specification %s\n" , filter );
192
- return -1 ;
193
- }
194
- if (endp == current )
195
- level -> pci_vendor = -1 ;
196
- current = endp + 1 ;
197
-
198
- level -> pci_device = strtoul (current , & endp , 16 );
199
- if (* endp != ']' ) {
200
- fprintf (stderr , "invalid PCI vendor:device filter specification %s\n" , filter );
201
- return -1 ;
202
- }
203
- if (endp == current )
204
- level -> pci_device = -1 ;
205
- current = endp + 1 ;
206
-
207
- if (* current != ':' && * current != '\0' ) {
187
+ unsigned vendor , device ;
188
+ if (sscanf (current , "%x:%x]" , & vendor , & device ) == 2 ) {
189
+ level -> pci_vendor = (int ) vendor ;
190
+ level -> pci_device = (int ) device ;
191
+ return 0 ;
192
+ } else if (sscanf (current , ":%x]" , & device ) == 1 ) {
193
+ level -> pci_device = (int ) device ;
194
+ return 0 ;
195
+ } else if (sscanf (current , "%x:]" , & vendor ) == 1 ) {
196
+ level -> pci_vendor = (int ) vendor ;
197
+ return 0 ;
198
+ } else if (!strncmp (current , ":]" , 2 )) {
199
+ /* nothing */
200
+ return 0 ;
201
+ } else if (strchr (current , ':' )) {
208
202
fprintf (stderr , "invalid PCI vendor:device filter specification %s\n" , filter );
209
203
return -1 ;
210
204
}
0 commit comments