Commit 4112e16a authored by Alan's avatar Alan Committed by Jeff Garzik

libata-sff: Don't try and activate channels which are not in use

An ATA controller in native mode may have one or more channels disabled
and not assigned resources. In that case the existing code crashes trying
to access I/O ports 0-7.

Add the neccessary check.
Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent d73f30e1
...@@ -832,6 +832,21 @@ void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc) ...@@ -832,6 +832,21 @@ void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
} }
#ifdef CONFIG_PCI #ifdef CONFIG_PCI
static int ata_resources_present(struct pci_dev *pdev, int port)
{
int i;
/* Check the PCI resources for this channel are enabled */
port = port * 2;
for (i = 0; i < 2; i ++) {
if (pci_resource_start(pdev, port + i) == 0 ||
pci_resource_len(pdev, port + i) == 0)
return 0;
}
return 1;
}
/** /**
* ata_pci_init_native_mode - Initialize native-mode driver * ata_pci_init_native_mode - Initialize native-mode driver
* @pdev: pci device to be initialized * @pdev: pci device to be initialized
...@@ -864,6 +879,13 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ...@@ -864,6 +879,13 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
probe_ent->irq = pdev->irq; probe_ent->irq = pdev->irq;
probe_ent->irq_flags = IRQF_SHARED; probe_ent->irq_flags = IRQF_SHARED;
/* Discard disabled ports. Some controllers show their
unused channels this way */
if (ata_resources_present(pdev, 0) == 0)
ports &= ~ATA_PORT_PRIMARY;
if (ata_resources_present(pdev, 1) == 0)
ports &= ~ATA_PORT_SECONDARY;
if (ports & ATA_PORT_PRIMARY) { if (ports & ATA_PORT_PRIMARY) {
probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0); probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0);
probe_ent->port[p].altstatus_addr = probe_ent->port[p].altstatus_addr =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment