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

PCI/VGA: Select VGA devices earlier

Select VGA devices in vga_arb_device_init() and pci_notify() instead of in
vga_arbiter_add_pci_device().

This is a trivial optimization for adding devices. It's a bigger
optimization for the removal case because pci_notify() won't call
vga_arbiter_del_pci_device() for non-VGA devices, so it won't have to
search the vga_list for them.

https://lore.kernel.org/r/20230830111532.444535-3-sui.jingfeng@linux.dev
Signed-off-by: Sui Jingfeng <suijingfeng@loongson.cn>
[bhelgaas: commit log, split from functional change]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

authored by

Sui Jingfeng and committed by
Bjorn Helgaas
300bac93 655e6fe1

+8 -6
+8 -6
drivers/pci/vgaarb.c
··· 764 764 struct pci_dev *bridge; 765 765 u16 cmd; 766 766 767 - /* Only deal with VGA class devices */ 768 - if (!pci_is_vga(pdev)) 769 - return false; 770 - 771 767 /* Allocate structure */ 772 768 vgadev = kzalloc(sizeof(struct vga_device), GFP_KERNEL); 773 769 if (vgadev == NULL) { ··· 1499 1503 1500 1504 vgaarb_dbg(dev, "%s\n", __func__); 1501 1505 1506 + /* Only deal with VGA class devices */ 1507 + if (!pci_is_vga(pdev)) 1508 + return 0; 1509 + 1502 1510 /* 1503 1511 * For now, we're only interested in devices added and removed. 1504 1512 * I didn't test this thing here, so someone needs to double check ··· 1550 1550 pdev = NULL; 1551 1551 while ((pdev = 1552 1552 pci_get_subsys(PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 1553 - PCI_ANY_ID, pdev)) != NULL) 1554 - vga_arbiter_add_pci_device(pdev); 1553 + PCI_ANY_ID, pdev)) != NULL) { 1554 + if (pci_is_vga(pdev)) 1555 + vga_arbiter_add_pci_device(pdev); 1556 + } 1555 1557 1556 1558 pr_info("loaded\n"); 1557 1559 return rc;