Skip to content

Commit 80cf1f8

Browse files
committed
Merge tag 'pci-v4.14-fixes-4' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci
Pull PCI fixes from Bjorn Helgaas: "Fix legacy IDE probe issues exposed by recent PCI core IRQ mapping changes (Bartlomiej Zolnierkiewicz, Lorenzo Pieralisi)" * tag 'pci-v4.14-fixes-4' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci: ide: fix IRQ assignment for PCI bus order probing ide: pci: free PCI BARs on initialization failure ide: free hwif->portdev on hwif_init() failure
2 parents 2754906 + b1f9e5e commit 80cf1f8

File tree

3 files changed

+50
-27
lines changed

3 files changed

+50
-27
lines changed

drivers/ide/ide-probe.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
14511451
if (hwif_init(hwif) == 0) {
14521452
printk(KERN_INFO "%s: failed to initialize IDE "
14531453
"interface\n", hwif->name);
1454+
device_unregister(hwif->portdev);
14541455
device_unregister(&hwif->gendev);
14551456
ide_disable_port(hwif);
14561457
continue;

drivers/ide/ide-scan-pci.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,22 @@ static int __init ide_scan_pcidev(struct pci_dev *dev)
5656
{
5757
struct list_head *l;
5858
struct pci_driver *d;
59+
int ret;
5960

6061
list_for_each(l, &ide_pci_drivers) {
6162
d = list_entry(l, struct pci_driver, node);
6263
if (d->id_table) {
6364
const struct pci_device_id *id =
6465
pci_match_id(d->id_table, dev);
6566

66-
if (id != NULL && d->probe(dev, id) >= 0) {
67-
dev->driver = d;
68-
pci_dev_get(dev);
69-
return 1;
67+
if (id != NULL) {
68+
pci_assign_irq(dev);
69+
ret = d->probe(dev, id);
70+
if (ret >= 0) {
71+
dev->driver = d;
72+
pci_dev_get(dev);
73+
return 1;
74+
}
7075
}
7176
}
7277
}

drivers/ide/setup-pci.c

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
179179
/**
180180
* ide_pci_enable - do PCI enables
181181
* @dev: PCI device
182+
* @bars: PCI BARs mask
182183
* @d: IDE port info
183184
*
184185
* Enable the IDE PCI device. We attempt to enable the device in full
@@ -189,9 +190,10 @@ EXPORT_SYMBOL_GPL(ide_setup_pci_noise);
189190
* Returns zero on success or an error code
190191
*/
191192

192-
static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
193+
static int ide_pci_enable(struct pci_dev *dev, int bars,
194+
const struct ide_port_info *d)
193195
{
194-
int ret, bars;
196+
int ret;
195197

196198
if (pci_enable_device(dev)) {
197199
ret = pci_enable_device_io(dev);
@@ -216,18 +218,6 @@ static int ide_pci_enable(struct pci_dev *dev, const struct ide_port_info *d)
216218
goto out;
217219
}
218220

219-
if (d->host_flags & IDE_HFLAG_SINGLE)
220-
bars = (1 << 2) - 1;
221-
else
222-
bars = (1 << 4) - 1;
223-
224-
if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) {
225-
if (d->host_flags & IDE_HFLAG_CS5520)
226-
bars |= (1 << 2);
227-
else
228-
bars |= (1 << 4);
229-
}
230-
231221
ret = pci_request_selected_regions(dev, bars, d->name);
232222
if (ret < 0)
233223
printk(KERN_ERR "%s %s: can't reserve resources\n",
@@ -403,6 +393,7 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
403393
/**
404394
* ide_setup_pci_controller - set up IDE PCI
405395
* @dev: PCI device
396+
* @bars: PCI BARs mask
406397
* @d: IDE port info
407398
* @noisy: verbose flag
408399
*
@@ -411,7 +402,7 @@ int ide_hwif_setup_dma(ide_hwif_t *hwif, const struct ide_port_info *d)
411402
* and enables it if need be
412403
*/
413404

414-
static int ide_setup_pci_controller(struct pci_dev *dev,
405+
static int ide_setup_pci_controller(struct pci_dev *dev, int bars,
415406
const struct ide_port_info *d, int noisy)
416407
{
417408
int ret;
@@ -420,24 +411,28 @@ static int ide_setup_pci_controller(struct pci_dev *dev,
420411
if (noisy)
421412
ide_setup_pci_noise(dev, d);
422413

423-
ret = ide_pci_enable(dev, d);
414+
ret = ide_pci_enable(dev, bars, d);
424415
if (ret < 0)
425416
goto out;
426417

427418
ret = pci_read_config_word(dev, PCI_COMMAND, &pcicmd);
428419
if (ret < 0) {
429420
printk(KERN_ERR "%s %s: error accessing PCI regs\n",
430421
d->name, pci_name(dev));
431-
goto out;
422+
goto out_free_bars;
432423
}
433424
if (!(pcicmd & PCI_COMMAND_IO)) { /* is device disabled? */
434425
ret = ide_pci_configure(dev, d);
435426
if (ret < 0)
436-
goto out;
427+
goto out_free_bars;
437428
printk(KERN_INFO "%s %s: device enabled (Linux)\n",
438429
d->name, pci_name(dev));
439430
}
440431

432+
goto out;
433+
434+
out_free_bars:
435+
pci_release_selected_regions(dev, bars);
441436
out:
442437
return ret;
443438
}
@@ -540,21 +535,36 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
540535
{
541536
struct pci_dev *pdev[] = { dev1, dev2 };
542537
struct ide_host *host;
543-
int ret, i, n_ports = dev2 ? 4 : 2;
538+
int ret, i, n_ports = dev2 ? 4 : 2, bars;
544539
struct ide_hw hw[4], *hws[] = { NULL, NULL, NULL, NULL };
545540

541+
if (d->host_flags & IDE_HFLAG_SINGLE)
542+
bars = (1 << 2) - 1;
543+
else
544+
bars = (1 << 4) - 1;
545+
546+
if ((d->host_flags & IDE_HFLAG_NO_DMA) == 0) {
547+
if (d->host_flags & IDE_HFLAG_CS5520)
548+
bars |= (1 << 2);
549+
else
550+
bars |= (1 << 4);
551+
}
552+
546553
for (i = 0; i < n_ports / 2; i++) {
547-
ret = ide_setup_pci_controller(pdev[i], d, !i);
548-
if (ret < 0)
554+
ret = ide_setup_pci_controller(pdev[i], bars, d, !i);
555+
if (ret < 0) {
556+
if (i == 1)
557+
pci_release_selected_regions(pdev[0], bars);
549558
goto out;
559+
}
550560

551561
ide_pci_setup_ports(pdev[i], d, &hw[i*2], &hws[i*2]);
552562
}
553563

554564
host = ide_host_alloc(d, hws, n_ports);
555565
if (host == NULL) {
556566
ret = -ENOMEM;
557-
goto out;
567+
goto out_free_bars;
558568
}
559569

560570
host->dev[0] = &dev1->dev;
@@ -576,7 +586,7 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
576586
* do_ide_setup_pci_device() on the first device!
577587
*/
578588
if (ret < 0)
579-
goto out;
589+
goto out_free_bars;
580590

581591
/* fixup IRQ */
582592
if (ide_pci_is_in_compatibility_mode(pdev[i])) {
@@ -589,6 +599,13 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
589599
ret = ide_host_register(host, d, hws);
590600
if (ret)
591601
ide_host_free(host);
602+
else
603+
goto out;
604+
605+
out_free_bars:
606+
i = n_ports / 2;
607+
while (i--)
608+
pci_release_selected_regions(pdev[i], bars);
592609
out:
593610
return ret;
594611
}

0 commit comments

Comments
 (0)