On Sat, Jun 15, 2024 at 04:09:41PM +0200, Lukas Wunner wrote: > Below is a small patch which acquires a ref on child. Maybe this > already does the trick? Thanks, it appears your idea works! I've run it through 100 test iterations successfully; previously it would reliably panic within 5 or fewer iterations. I also need the first patch from this series, though, otherwise it inevitably deadlocks. I'd be interested to hear if you have any thoughts on that one. Reviewed-by: Keith Busch <kbusch@xxxxxxxxxx> Tested-by: Keith Busch <kbusch@xxxxxxxxxx> > -- >8 -- > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 2a8063e..82db9a8 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -4753,7 +4753,7 @@ static int pci_bus_max_d3cold_delay(const struct pci_bus *bus) > */ > int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type) > { > - struct pci_dev *child; > + struct pci_dev *child __free(pci_dev_put) = NULL; > int delay; > > if (pci_dev_is_disconnected(dev)) > @@ -4782,8 +4782,9 @@ int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type) > return 0; > } > > - child = list_first_entry(&dev->subordinate->devices, struct pci_dev, > - bus_list); > + > + child = pci_dev_get(list_first_entry(&dev->subordinate->devices, > + struct pci_dev, bus_list)); > up_read(&pci_bus_sem); > > /*