ide: fix ide_register_port() failure handling

* Factor out port freeing from ide_host_free() to ide_free_port().

* Add ide_disable_port() and use it on ide_register_port() failure.

Cc: Ian Campbell <Ian.Campbell@citrix.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
This commit is contained in:
Bartlomiej Zolnierkiewicz 2009-02-02 20:12:21 +01:00
parent e5461f38b4
commit 9a100f4b78

View file

@ -1467,6 +1467,30 @@ struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
} }
EXPORT_SYMBOL_GPL(ide_host_alloc); EXPORT_SYMBOL_GPL(ide_host_alloc);
static void ide_port_free(ide_hwif_t *hwif)
{
ide_port_free_devices(hwif);
ide_free_port_slot(hwif->index);
kfree(hwif);
}
static void ide_disable_port(ide_hwif_t *hwif)
{
struct ide_host *host = hwif->host;
int i;
printk(KERN_INFO "%s: disabling port\n", hwif->name);
for (i = 0; i < MAX_HOST_PORTS; i++) {
if (host->ports[i] == hwif) {
host->ports[i] = NULL;
host->n_ports--;
}
}
ide_port_free(hwif);
}
int ide_host_register(struct ide_host *host, const struct ide_port_info *d, int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
hw_regs_t **hws) hw_regs_t **hws)
{ {
@ -1507,8 +1531,12 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
hwif->present = 1; hwif->present = 1;
if (hwif->chipset != ide_4drives || !hwif->mate || if (hwif->chipset != ide_4drives || !hwif->mate ||
!hwif->mate->present) !hwif->mate->present) {
ide_register_port(hwif); if (ide_register_port(hwif)) {
ide_disable_port(hwif);
continue;
}
}
if (hwif->present) if (hwif->present)
ide_port_tune_devices(hwif); ide_port_tune_devices(hwif);
@ -1660,12 +1688,8 @@ void ide_host_free(struct ide_host *host)
int i; int i;
ide_host_for_each_port(i, hwif, host) { ide_host_for_each_port(i, hwif, host) {
if (hwif == NULL) if (hwif)
continue; ide_port_free(hwif);
ide_port_free_devices(hwif);
ide_free_port_slot(hwif->index);
kfree(hwif);
} }
kfree(host); kfree(host);