Skip to content

Commit 8a69580

Browse files
committed
ide: add ide_host_free() helper (take 2)
* Add ide_host_free() helper and convert ide_host_remove() to use it. * Fix handling of ide_host_register() failure in ide_host_add(), icside.c, ide-generic.c, falconide.c and sgiioc4.c. While at it: * Fix handling of ide_host_alloc_all() failure in ide-generic.c. * Fix handling of ide_host_alloc() failure in falconide.c (also return the correct error value if no device is found). v2: * falconide build fix. (From Stephen Rothwell) Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
1 parent 18de101 commit 8a69580

6 files changed

Lines changed: 88 additions & 20 deletions

File tree

‎drivers/ide/arm/icside.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
445445
void __iomem *base;
446446
struct ide_host *host;
447447
hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
448+
int ret;
448449

449450
base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
450451
if (!base)
@@ -472,9 +473,15 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
472473

473474
ecard_set_drvdata(ec, state);
474475

475-
ide_host_register(host, NULL, hws);
476+
ret = ide_host_register(host, NULL, hws);
477+
if (ret)
478+
goto err_free;
476479

477480
return 0;
481+
err_free:
482+
ide_host_free(host);
483+
ecard_set_drvdata(ec, NULL);
484+
return ret;
478485
}
479486

480487
static const struct ide_port_info icside_v6_port_info __initdata = {
@@ -547,11 +554,17 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
547554
d.dma_ops = NULL;
548555
}
549556

550-
ide_host_register(host, &d, hws);
557+
ret = ide_host_register(host, NULL, hws);
558+
if (ret)
559+
goto err_free;
551560

552561
return 0;
553-
554-
out:
562+
err_free:
563+
ide_host_free(host);
564+
if (d.dma_ops)
565+
free_dma(ec->dma);
566+
ecard_set_drvdata(ec, NULL);
567+
out:
555568
return ret;
556569
}
557570

‎drivers/ide/ide-generic.c‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@ static int __init ide_generic_init(void)
8484
{
8585
hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS];
8686
struct ide_host *host;
87-
int i;
87+
unsigned long io_addr;
88+
int i, rc;
8889

8990
printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module "
9091
"parameter for probing all legacy ISA IDE ports\n");
9192

9293
for (i = 0; i < MAX_HWIFS; i++) {
93-
unsigned long io_addr = ide_default_io_base(i);
94+
io_addr = ide_default_io_base(i);
9495

9596
hws[i] = NULL;
9697

@@ -120,14 +121,32 @@ static int __init ide_generic_init(void)
120121
}
121122

122123
host = ide_host_alloc_all(NULL, hws);
123-
if (host)
124-
ide_host_register(host, NULL, hws);
124+
if (host == NULL) {
125+
rc = -ENOMEM;
126+
goto err;
127+
}
128+
129+
rc = ide_host_register(host, NULL, hws);
130+
if (rc)
131+
goto err_free;
125132

126133
if (ide_generic_sysfs_init())
127134
printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
128135
"class\n");
129136

130137
return 0;
138+
err_free:
139+
ide_host_free(host);
140+
err:
141+
for (i = 0; i < MAX_HWIFS; i++) {
142+
if (hws[i] == NULL)
143+
continue;
144+
145+
io_addr = hws[i]->io_ports.data_addr;
146+
release_region(io_addr + 0x206, 1);
147+
release_region(io_addr, 8);
148+
}
149+
return rc;
131150
}
132151

133152
module_init(ide_generic_init);

‎drivers/ide/ide-probe.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,12 +1729,17 @@ int ide_host_add(const struct ide_port_info *d, hw_regs_t **hws,
17291729
struct ide_host **hostp)
17301730
{
17311731
struct ide_host *host;
1732+
int rc;
17321733

17331734
host = ide_host_alloc(d, hws);
17341735
if (host == NULL)
17351736
return -ENOMEM;
17361737

1737-
ide_host_register(host, d, hws);
1738+
rc = ide_host_register(host, d, hws);
1739+
if (rc) {
1740+
ide_host_free(host);
1741+
return rc;
1742+
}
17381743

17391744
if (hostp)
17401745
*hostp = host;
@@ -1743,7 +1748,7 @@ int ide_host_add(const struct ide_port_info *d, hw_regs_t **hws,
17431748
}
17441749
EXPORT_SYMBOL_GPL(ide_host_add);
17451750

1746-
void ide_host_remove(struct ide_host *host)
1751+
void ide_host_free(struct ide_host *host)
17471752
{
17481753
ide_hwif_t *hwif;
17491754
int i;
@@ -1754,13 +1759,25 @@ void ide_host_remove(struct ide_host *host)
17541759
if (hwif == NULL)
17551760
continue;
17561761

1757-
ide_unregister(hwif);
17581762
ide_free_port_slot(hwif->index);
17591763
kfree(hwif);
17601764
}
17611765

17621766
kfree(host);
17631767
}
1768+
EXPORT_SYMBOL_GPL(ide_host_free);
1769+
1770+
void ide_host_remove(struct ide_host *host)
1771+
{
1772+
int i;
1773+
1774+
for (i = 0; i < MAX_HWIFS; i++) {
1775+
if (host->ports[i])
1776+
ide_unregister(host->ports[i]);
1777+
}
1778+
1779+
ide_host_free(host);
1780+
}
17641781
EXPORT_SYMBOL_GPL(ide_host_remove);
17651782

17661783
void ide_port_scan(ide_hwif_t *hwif)

‎drivers/ide/legacy/falconide.c‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ static int __init falconide_init(void)
114114
{
115115
struct ide_host *host;
116116
hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
117+
int rc;
117118

118119
if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE))
119-
return 0;
120+
return -ENODEV;
120121

121122
printk(KERN_INFO "ide: Falcon IDE controller\n");
122123

@@ -128,13 +129,24 @@ static int __init falconide_init(void)
128129
falconide_setup_ports(&hw);
129130

130131
host = ide_host_alloc(&falconide_port_info, hws);
131-
if (host) {
132-
ide_get_lock(NULL, NULL);
133-
ide_host_register(host, &falconide_port_info, hws);
134-
ide_release_lock();
132+
if (host == NULL) {
133+
rc = -ENOMEM;
134+
goto err;
135135
}
136136

137+
ide_get_lock(NULL, NULL);
138+
rc = ide_host_register(host, &falconide_port_info, hws);
139+
ide_release_lock();
140+
141+
if (rc)
142+
goto err_free;
143+
137144
return 0;
145+
err_free:
146+
ide_host_free(host);
147+
err:
148+
release_mem_region(ATA_HD_BASE, 0x40);
149+
return rc;
138150
}
139151

140152
module_init(falconide_init);

‎drivers/ide/pci/sgiioc4.c‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
603603
struct ide_host *host;
604604
hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
605605
struct ide_port_info d = sgiioc4_port_info;
606+
int rc;
606607

607608
/* Get the CmdBlk and CtrlBlk Base Registers */
608609
bar0 = pci_resource_start(dev, 0);
@@ -638,17 +639,22 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
638639
writel(0x03, (void __iomem *)(irqport + IOC4_INTR_SET * 4));
639640

640641
host = ide_host_alloc(&d, hws);
641-
if (host == NULL)
642+
if (host == NULL) {
643+
rc = -ENOMEM;
642644
goto err;
645+
}
643646

644-
if (ide_host_register(host, &d, hws))
645-
return -EIO;
647+
rc = ide_host_register(host, &d, hws);
648+
if (rc)
649+
goto err_free;
646650

647651
return 0;
652+
err_free:
653+
ide_host_free(host);
648654
err:
649655
release_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE);
650656
iounmap(virt_base);
651-
return -ENOMEM;
657+
return rc;
652658
}
653659

654660
static unsigned int __devinit

‎include/linux/ide.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,7 @@ void ide_port_apply_params(ide_hwif_t *);
12361236

12371237
struct ide_host *ide_host_alloc_all(const struct ide_port_info *, hw_regs_t **);
12381238
struct ide_host *ide_host_alloc(const struct ide_port_info *, hw_regs_t **);
1239+
void ide_host_free(struct ide_host *);
12391240
int ide_host_register(struct ide_host *, const struct ide_port_info *,
12401241
hw_regs_t **);
12411242
int ide_host_add(const struct ide_port_info *, hw_regs_t **,

0 commit comments

Comments
 (0)