ide-pmac: dynamically allocate struct pmac_ide_hwif instances (take 2)

* Dynamically allocate struct pmac_ide_hwif instances in pmac_ide_macio_attach()
  and pmac_ide_pci_attach(), then remove no longer needed pmac_ide[].

v2:
* Build fix from Kamalesh Babulal.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Kamalesh Babulal <kamalesh@linux.vnet.ibm.com>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 7d9f3d51
...@@ -79,8 +79,6 @@ typedef struct pmac_ide_hwif { ...@@ -79,8 +79,6 @@ typedef struct pmac_ide_hwif {
} pmac_ide_hwif_t; } pmac_ide_hwif_t;
static pmac_ide_hwif_t pmac_ide[MAX_HWIFS];
enum { enum {
controller_ohare, /* OHare based */ controller_ohare, /* OHare based */
controller_heathrow, /* Heathrow/Paddington */ controller_heathrow, /* Heathrow/Paddington */
...@@ -1094,29 +1092,34 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match) ...@@ -1094,29 +1092,34 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
int i, rc; int i, rc;
hw_regs_t hw; hw_regs_t hw;
pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
if (pmif == NULL)
return -ENOMEM;
i = 0; i = 0;
while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0))
|| pmac_ide[i].node != NULL))
++i; ++i;
if (i >= MAX_HWIFS) { if (i >= MAX_HWIFS) {
printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n"); printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n");
printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name); printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name);
return -ENODEV; rc = -ENODEV;
goto out_free_pmif;
} }
pmif = &pmac_ide[i];
hwif = &ide_hwifs[i]; hwif = &ide_hwifs[i];
if (macio_resource_count(mdev) == 0) { if (macio_resource_count(mdev) == 0) {
printk(KERN_WARNING "ide%d: no address for %s\n", printk(KERN_WARNING "ide%d: no address for %s\n",
i, mdev->ofdev.node->full_name); i, mdev->ofdev.node->full_name);
return -ENXIO; rc = -ENXIO;
goto out_free_pmif;
} }
/* Request memory resource for IO ports */ /* Request memory resource for IO ports */
if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) { if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) {
printk(KERN_ERR "ide%d: can't request mmio resource !\n", i); printk(KERN_ERR "ide%d: can't request mmio resource !\n", i);
return -EBUSY; rc = -EBUSY;
goto out_free_pmif;
} }
/* XXX This is bogus. Should be fixed in the registry by checking /* XXX This is bogus. Should be fixed in the registry by checking
...@@ -1166,11 +1169,15 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match) ...@@ -1166,11 +1169,15 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
iounmap(pmif->dma_regs); iounmap(pmif->dma_regs);
macio_release_resource(mdev, 1); macio_release_resource(mdev, 1);
} }
memset(pmif, 0, sizeof(*pmif));
macio_release_resource(mdev, 0); macio_release_resource(mdev, 0);
kfree(pmif);
} }
return rc; return rc;
out_free_pmif:
kfree(pmif);
return rc;
} }
static int static int
...@@ -1223,30 +1230,36 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -1223,30 +1230,36 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n"); printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n");
return -ENODEV; return -ENODEV;
} }
pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
if (pmif == NULL)
return -ENOMEM;
i = 0; i = 0;
while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0))
|| pmac_ide[i].node != NULL))
++i; ++i;
if (i >= MAX_HWIFS) { if (i >= MAX_HWIFS) {
printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n"); printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n");
printk(KERN_ERR " %s\n", np->full_name); printk(KERN_ERR " %s\n", np->full_name);
return -ENODEV; rc = -ENODEV;
goto out_free_pmif;
} }
pmif = &pmac_ide[i];
hwif = &ide_hwifs[i]; hwif = &ide_hwifs[i];
if (pci_enable_device(pdev)) { if (pci_enable_device(pdev)) {
printk(KERN_WARNING "ide%i: Can't enable PCI device for %s\n", printk(KERN_WARNING "ide%i: Can't enable PCI device for %s\n",
i, np->full_name); i, np->full_name);
return -ENXIO; rc = -ENXIO;
goto out_free_pmif;
} }
pci_set_master(pdev); pci_set_master(pdev);
if (pci_request_regions(pdev, "Kauai ATA")) { if (pci_request_regions(pdev, "Kauai ATA")) {
printk(KERN_ERR "ide%d: Cannot obtain PCI resources for %s\n", printk(KERN_ERR "ide%d: Cannot obtain PCI resources for %s\n",
i, np->full_name); i, np->full_name);
return -ENXIO; rc = -ENXIO;
goto out_free_pmif;
} }
hwif->dev = &pdev->dev; hwif->dev = &pdev->dev;
...@@ -1276,11 +1289,15 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id) ...@@ -1276,11 +1289,15 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
/* The inteface is released to the common IDE layer */ /* The inteface is released to the common IDE layer */
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
iounmap(base); iounmap(base);
memset(pmif, 0, sizeof(*pmif));
pci_release_regions(pdev); pci_release_regions(pdev);
kfree(pmif);
} }
return rc; return rc;
out_free_pmif:
kfree(pmif);
return rc;
} }
static int static int
......
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