@@ -248,6 +248,10 @@ struct pci_device_match {
248
248
int16_t max_count ; // how often that device should exist at most
249
249
};
250
250
251
+ enum {
252
+ DEVICE_COUNT_MAX = 0x7fff // INT16_MAX - used for "no upper limit"
253
+ };
254
+
251
255
// ASUSTOR Platform.
252
256
struct asustor_driver_data {
253
257
const char * name ; // used for force_device and for some log messages
@@ -268,8 +272,8 @@ static struct asustor_driver_data asustor_fs6700_driver_data = {
268
272
.pci_matches = {
269
273
// PCI bridge: ASMedia Technology Inc. ASM2806 4-Port PCIe x2 Gen3 Packet Switch (rev 01)
270
274
// FS6712X seems to have 15 of these, no idea about FS6706T (so I keep min_count at 1)
271
- // currently the upper limit doesn't matter so I just use 10000
272
- { 0x1b21 , 0x2806 , 1 , 10000 },
275
+ // currently the upper limit doesn't matter so I just use DEVICE_COUNT_MAX
276
+ { 0x1b21 , 0x2806 , 1 , DEVICE_COUNT_MAX },
273
277
},
274
278
.leds = & asustor_fs6700_gpio_leds_lookup ,
275
279
.keys = & asustor_fs6700_gpio_keys_lookup ,
@@ -280,7 +284,8 @@ static struct asustor_driver_data asustor_6700_driver_data = {
280
284
// AS67xx needs to match PCI devices because it has the same DMI data as *F*S67xx
281
285
.pci_matches = {
282
286
// PCI bridge: ASMedia Technology Inc. ASM2806 4-Port PCIe x2 Gen3 Packet Switch (rev 01)
283
- // *F*S67xx seems to use these, I think *A*S67xx doesn't, so expect 0
287
+ // *F*S67xx seems to use these, *A*S67xx doesn't, so expect 0
288
+ // (BTW, AS6706T has 5x "ASM2812 6-Port PCIe x4 Gen3 Packet Switch" [1b21:2812], I hope *F*S6706T doesn't)
284
289
{ 0x1b21 , 0x2806 , 0 , 0 },
285
290
},
286
291
.leds = & asustor_6700_gpio_leds_lookup ,
@@ -319,7 +324,7 @@ static const struct dmi_system_id asustor_systems[] = {
319
324
// NOTE: each entry in this table must have its own unique asustor_driver_data
320
325
// (having a unique .name) set as .driver_data
321
326
{
322
- // Note : yes, this is the same DMI match as the next entry, because just by DMI,
327
+ // NOTE : yes, this is the same DMI match as the next entry, because just by DMI,
323
328
// FS67xx and AS67xx can't be told apart. But our custom matching logic
324
329
// in find_matching_asustor_system() also takes driver_data->pci_matches[]
325
330
// into account, so that should be ok.
@@ -330,7 +335,7 @@ static const struct dmi_system_id asustor_systems[] = {
330
335
.driver_data = & asustor_fs6700_driver_data ,
331
336
},
332
337
{
333
- // Note : This not only matches (and works with) AS670xT (Lockerstor Gen2),
338
+ // NOTE : This not only matches (and works with) AS670xT (Lockerstor Gen2),
334
339
// but also AS540xT (Nimbustor Gen2)
335
340
.matches = {
336
341
DMI_EXACT_MATCH (DMI_SYS_VENDOR , "Intel Corporation" ),
@@ -442,22 +447,28 @@ static bool dmi_matches(const struct dmi_system_id *dmi)
442
447
return true;
443
448
}
444
449
445
- // how often does the PCI(e) device with given vendor/device IDs exist in this system?
450
+ // How many PCI(e) devices with given vendor/device IDs exist in this system?
446
451
static int count_pci_device_instances (unsigned int vendor , unsigned int device )
447
452
{
448
- // start with -1 as the do-while loop runs at least once even if nothing is found
449
- int ret = -1 ;
450
- struct pci_dev * pd = NULL ;
451
- do {
453
+ int ret = 0 ;
454
+ struct pci_dev * pd , * last_pd = NULL ;
455
+
456
+ while ((pd = pci_get_device (vendor , device , last_pd )) != NULL ) {
457
+ if (last_pd ) {
458
+ pci_dev_put (last_pd );
459
+ }
460
+ last_pd = pd ;
452
461
++ ret ;
453
- pd = pci_get_device (vendor , device , pd );
454
- } while (pd != NULL );
462
+ }
463
+ if (last_pd ) {
464
+ pci_dev_put (last_pd );
465
+ }
455
466
return ret ;
456
467
}
457
468
458
469
// check if sys->pci_matches[] match with the PCI devices in the system
459
470
// NOTE: this only checks if the devices in sys->pci_matches[] exist in the system
460
- // with the expected count (or do *not* exist if the counts are 0),
471
+ // with the expected count (or the device does *not* exist if the counts are 0),
461
472
// PCI devices existing that aren't listed in sys->pci_matches[] is expected
462
473
// and does not make this function fail.
463
474
static bool pci_devices_match (const struct asustor_driver_data * sys )
0 commit comments