Skip to contentSkip to conversation

pci: update reset methods for first device

PATCH New Keith Busch 1 participant 1 message Nov 20, 2025 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: update reset methods for first device

From: Keith Busch <[email protected]>

The pci enumeration initializes the sysfs attributes as it scans devices. The first device on a bus will successfully probe the "bus" reset method, but if a second device is enumerated on that bus, that reset method is invalid. Make sure to refresh the attribute values after adding a second device to the bus's list.

---
 drivers/pci/probe.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
drivers/pci/probe.c +14 -0
index f41128f91ca76..2f461c37a87b3 100644
@@ -2687,6 +2687,7 @@ static void pci_set_msi_domain(struct pci_dev *dev)
 
 void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 {
+	struct pci_dev *sibling __free(pci_dev_put) = NULL;
 	int ret;
 
 	pci_configure_device(dev);
@@ -2718,9 +2719,22 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 	 * and the bus list for fixup functions, etc.
 	 */
 	down_write(&pci_bus_sem);
+	if (list_is_singular(&bus->devices))
+		sibling = pci_dev_get(list_first_entry(&bus->devices,
+					     struct pci_dev, bus_list));
 	list_add_tail(&dev->bus_list, &bus->devices);
 	up_write(&pci_bus_sem);
 
+	/*
+	 * The kernel doesn't allow the "bus" reset method for a device on a
+	 * bus with multiple functions, but the first device on the bus may
+	 * initialize with that since we haven't discovered other functions
+	 * yet. Re-initialize the methods if it was previously the only bus
+	 * device.
+	 */
+	if (sibling)
+		pci_init_reset_methods(sibling);
+
 	ret = pcibios_device_add(dev);
 	WARN_ON(ret < 0);
 
Signature · 1 line
2.47.3