Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: Consolidate "next-function" functions

There are several next_fn functions (no_next_fn, next_trad_fn,
next_ari_fn); consolidate them in next_fn() to simplify the code.

[bhelgaas: make next_fn() static, rework control flow]
Signed-off-by: Yijing Wang <wangyijing@huawei.com>
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

authored by

Yijing Wang and committed by
Bjorn Helgaas
b1bd58e4 31ab2476

+21 -27
+21 -27
drivers/pci/probe.c
··· 1349 1349 } 1350 1350 EXPORT_SYMBOL(pci_scan_single_device); 1351 1351 1352 - static unsigned next_ari_fn(struct pci_dev *dev, unsigned fn) 1352 + static unsigned next_fn(struct pci_bus *bus, struct pci_dev *dev, unsigned fn) 1353 1353 { 1354 - u16 cap; 1355 - unsigned pos, next_fn; 1354 + int pos; 1355 + u16 cap = 0; 1356 + unsigned next_fn; 1356 1357 1357 - if (!dev) 1358 - return 0; 1358 + if (pci_ari_enabled(bus)) { 1359 + if (!dev) 1360 + return 0; 1361 + pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); 1362 + if (!pos) 1363 + return 0; 1359 1364 1360 - pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); 1361 - if (!pos) 1362 - return 0; 1363 - pci_read_config_word(dev, pos + 4, &cap); 1364 - next_fn = cap >> 8; 1365 - if (next_fn <= fn) 1366 - return 0; 1367 - return next_fn; 1368 - } 1365 + pci_read_config_word(dev, pos + PCI_ARI_CAP, &cap); 1366 + next_fn = PCI_ARI_CAP_NFN(cap); 1367 + if (next_fn <= fn) 1368 + return 0; /* protect against malformed list */ 1369 1369 1370 - static unsigned next_trad_fn(struct pci_dev *dev, unsigned fn) 1371 - { 1372 - return (fn + 1) % 8; 1373 - } 1370 + return next_fn; 1371 + } 1374 1372 1375 - static unsigned no_next_fn(struct pci_dev *dev, unsigned fn) 1376 - { 1373 + /* dev may be NULL for non-contiguous multifunction devices */ 1374 + if (!dev || dev->multifunction) 1375 + return (fn + 1) % 8; 1376 + 1377 1377 return 0; 1378 1378 } 1379 1379 ··· 1406 1406 { 1407 1407 unsigned fn, nr = 0; 1408 1408 struct pci_dev *dev; 1409 - unsigned (*next_fn)(struct pci_dev *, unsigned) = no_next_fn; 1410 1409 1411 1410 if (only_one_child(bus) && (devfn > 0)) 1412 1411 return 0; /* Already scanned the entire slot */ ··· 1416 1417 if (!dev->is_added) 1417 1418 nr++; 1418 1419 1419 - if (pci_ari_enabled(bus)) 1420 - next_fn = next_ari_fn; 1421 - else if (dev->multifunction) 1422 - next_fn = next_trad_fn; 1423 - 1424 - for (fn = next_fn(dev, 0); fn > 0; fn = next_fn(dev, fn)) { 1420 + for (fn = next_fn(bus, dev, 0); fn > 0; fn = next_fn(bus, dev, fn)) { 1425 1421 dev = pci_scan_single_device(bus, devfn + fn); 1426 1422 if (dev) { 1427 1423 if (!dev->is_added)