Skip to content

Commit bf4162b

Browse files
Darrick J. Wongjbarnes993
authored andcommitted
PCI hotplug: fakephp: Allocate PCI resources before adding the device
For PCI devices, pci_bus_assign_resources() must be called to set up the pci_device->resource array before pci_bus_add_devices() can be called, else attempts to load drivers results in BAR collision errors where there are none. This is not done in fakephp, so devices can be "unplugged" but scanning the parent bus won't bring the devices back due to resource unallocation. Move the pci_bus_add_device-calling logic into pci_rescan_bus and preface it with a call to pci_bus_assign_resources so that we only have to (re)allocate resources once per bus where a new device is found. Signed-off-by: Darrick J. Wong <djwong@us.ibm.com> Acked-by: Alex Chiang <achiang@hp.com> Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>
1 parent bffac3c commit bf4162b

1 file changed

Lines changed: 26 additions & 16 deletions

File tree

‎drivers/pci/hotplug/fakephp.c‎

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ static void remove_slot_worker(struct work_struct *work)
195195
* Tries hard not to re-enable already existing devices;
196196
* also handles scanning of subfunctions.
197197
*/
198-
static void pci_rescan_slot(struct pci_dev *temp)
198+
static int pci_rescan_slot(struct pci_dev *temp)
199199
{
200200
struct pci_bus *bus = temp->bus;
201201
struct pci_dev *dev;
202202
int func;
203-
int retval;
204203
u8 hdr_type;
204+
int count = 0;
205205

206206
if (!pci_read_config_byte(temp, PCI_HEADER_TYPE, &hdr_type)) {
207207
temp->hdr_type = hdr_type & 0x7f;
@@ -213,17 +213,12 @@ static void pci_rescan_slot(struct pci_dev *temp)
213213
dbg("New device on %s function %x:%x\n",
214214
bus->name, temp->devfn >> 3,
215215
temp->devfn & 7);
216-
retval = pci_bus_add_device(dev);
217-
if (retval)
218-
dev_err(&dev->dev, "error adding "
219-
"device, continuing.\n");
220-
else
221-
add_slot(dev);
216+
count++;
222217
}
223218
}
224219
/* multifunction device? */
225220
if (!(hdr_type & 0x80))
226-
return;
221+
return count;
227222

228223
/* continue scanning for other functions */
229224
for (func = 1, temp->devfn++; func < 8; func++, temp->devfn++) {
@@ -239,16 +234,13 @@ static void pci_rescan_slot(struct pci_dev *temp)
239234
dbg("New device on %s function %x:%x\n",
240235
bus->name, temp->devfn >> 3,
241236
temp->devfn & 7);
242-
retval = pci_bus_add_device(dev);
243-
if (retval)
244-
dev_err(&dev->dev, "error adding "
245-
"device, continuing.\n");
246-
else
247-
add_slot(dev);
237+
count++;
248238
}
249239
}
250240
}
251241
}
242+
243+
return count;
252244
}
253245

254246

@@ -262,6 +254,8 @@ static void pci_rescan_bus(const struct pci_bus *bus)
262254
{
263255
unsigned int devfn;
264256
struct pci_dev *dev;
257+
int retval;
258+
int found = 0;
265259
dev = alloc_pci_dev();
266260
if (!dev)
267261
return;
@@ -270,7 +264,23 @@ static void pci_rescan_bus(const struct pci_bus *bus)
270264
dev->sysdata = bus->sysdata;
271265
for (devfn = 0; devfn < 0x100; devfn += 8) {
272266
dev->devfn = devfn;
273-
pci_rescan_slot(dev);
267+
found += pci_rescan_slot(dev);
268+
}
269+
270+
if (found) {
271+
pci_bus_assign_resources(bus);
272+
list_for_each_entry(dev, &bus->devices, bus_list) {
273+
/* Skip already-added devices */
274+
if (dev->is_added)
275+
continue;
276+
retval = pci_bus_add_device(dev);
277+
if (retval)
278+
dev_err(&dev->dev,
279+
"Error adding device, continuing\n");
280+
else
281+
add_slot(dev);
282+
}
283+
pci_bus_add_devices(bus);
274284
}
275285
kfree(dev);
276286
}

0 commit comments

Comments
 (0)