Skip to content

Commit c90570d

Browse files
YijingWangbjorn-helgaas
authored andcommitted
PCI: Assign resources before drivers claim devices (pci_scan_bus())
Previously, pci_scan_bus() created a root PCI bus, enumerated the devices on it, and called pci_bus_add_devices(), which made the devices available for drivers to claim them. Most callers assigned resources to devices after pci_scan_bus() returns, which may be after drivers have claimed the devices. This is incorrect; the PCI core should not change device resources while a driver is managing the device. Remove pci_bus_add_devices() from pci_scan_bus() and do it after any resource assignment in the callers. [bhelgaas: changelog, check for failure in mcf_pci_init()] Signed-off-by: Yijing Wang <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> CC: "David S. Miller" <[email protected]> CC: Geert Uytterhoeven <[email protected]> CC: Guan Xuetao <[email protected]> CC: Richard Henderson <[email protected]> CC: Ivan Kokshaysky <[email protected]> CC: Matt Turner <[email protected]>
1 parent c517d83 commit c90570d

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

arch/alpha/kernel/sys_nautilus.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ nautilus_init_pci(void)
207207

208208
/* Scan our single hose. */
209209
bus = pci_scan_bus(0, alpha_mv.pci_ops, hose);
210+
if (!bus)
211+
return;
212+
210213
hose->bus = bus;
211214
pcibios_claim_one_bus(bus);
212215

@@ -253,6 +256,7 @@ nautilus_init_pci(void)
253256
for the root bus, so just clear it. */
254257
bus->self = NULL;
255258
pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq);
259+
pci_bus_add_devices(bus);
256260
}
257261

258262
/*

arch/m68k/coldfire/pci.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,16 @@ static int __init mcf_pci_init(void)
313313
schedule_timeout(msecs_to_jiffies(200));
314314

315315
rootbus = pci_scan_bus(0, &mcf_pci_ops, NULL);
316+
if (!rootbus)
317+
return -ENODEV;
318+
316319
rootbus->resource[0] = &mcf_pci_io;
317320
rootbus->resource[1] = &mcf_pci_mem;
318321

319322
pci_fixup_irqs(pci_common_swizzle, mcf_pci_map_irq);
320323
pci_bus_size_bridges(rootbus);
321324
pci_bus_assign_resources(rootbus);
325+
pci_bus_add_devices(rootbus);
322326
return 0;
323327
}
324328

arch/sparc/kernel/pcic.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,16 @@ static void __init pcic_pbm_scan_bus(struct linux_pcic *pcic)
391391
struct linux_pbm_info *pbm = &pcic->pbm;
392392

393393
pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno, &pcic_ops, pbm);
394+
if (!pbm->pci_bus)
395+
return;
396+
394397
#if 0 /* deadwood transplanted from sparc64 */
395398
pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
396399
pci_record_assignments(pbm, pbm->pci_bus);
397400
pci_assign_unassigned(pbm, pbm->pci_bus);
398401
pci_fixup_irq(pbm, pbm->pci_bus);
399402
#endif
403+
pci_bus_add_devices(pbm->pci_bus);
400404
}
401405

402406
/*

arch/unicore32/kernel/pci.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,10 @@ static int __init pci_common_init(void)
266266
pci_fixup_irqs(pci_common_swizzle, pci_puv3_map_irq);
267267

268268
if (!pci_has_flag(PCI_PROBE_ONLY)) {
269-
/*
270-
* Size the bridge windows.
271-
*/
272269
pci_bus_size_bridges(puv3_bus);
273-
274-
/*
275-
* Assign resources.
276-
*/
277270
pci_bus_assign_resources(puv3_bus);
278271
}
279-
272+
pci_bus_add_devices(puv3_bus);
280273
return 0;
281274
}
282275
subsys_initcall(pci_common_init);

drivers/pci/hotplug/ibmphp_core.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ static void ibm_unconfigure_device(struct pci_func *func)
738738
*/
739739
static u8 bus_structure_fixup(u8 busno)
740740
{
741-
struct pci_bus *bus;
741+
struct pci_bus *bus, *b;
742742
struct pci_dev *dev;
743743
u16 l;
744744

@@ -765,7 +765,11 @@ static u8 bus_structure_fixup(u8 busno)
765765
(l != 0x0000) && (l != 0xffff)) {
766766
debug("%s - Inside bus_structure_fixup()\n",
767767
__func__);
768-
pci_scan_bus(busno, ibmphp_pci_bus->ops, NULL);
768+
b = pci_scan_bus(busno, ibmphp_pci_bus->ops, NULL);
769+
if (!b)
770+
continue;
771+
772+
pci_bus_add_devices(b);
769773
break;
770774
}
771775
}

drivers/pci/probe.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,6 @@ struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops,
21232123
b = pci_create_root_bus(NULL, bus, ops, sysdata, &resources);
21242124
if (b) {
21252125
pci_scan_child_bus(b);
2126-
pci_bus_add_devices(b);
21272126
} else {
21282127
pci_free_resource_list(&resources);
21292128
}

0 commit comments

Comments
 (0)