aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ppc/pmac.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-04-26 11:36:32 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-04-26 11:36:32 -0400
commit5297a3e522ff77e01fd0e792acc5ff0517822708 (patch)
tree1d91f87ffed7e1f0b6e2a9e9e5515f053f4eea37 /drivers/ide/ppc/pmac.c
parent7d9f3d51cf351ac35b4004cc40c7fd885fb30c5c (diff)
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: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ppc/pmac.c')
-rw-r--r--drivers/ide/ppc/pmac.c49
1 files changed, 33 insertions, 16 deletions
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 88619b50d9ef..2793e5fe137e 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -79,8 +79,6 @@ typedef struct pmac_ide_hwif {
79 79
80} pmac_ide_hwif_t; 80} pmac_ide_hwif_t;
81 81
82static pmac_ide_hwif_t pmac_ide[MAX_HWIFS];
83
84enum { 82enum {
85 controller_ohare, /* OHare based */ 83 controller_ohare, /* OHare based */
86 controller_heathrow, /* Heathrow/Paddington */ 84 controller_heathrow, /* Heathrow/Paddington */
@@ -1094,29 +1092,34 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
1094 int i, rc; 1092 int i, rc;
1095 hw_regs_t hw; 1093 hw_regs_t hw;
1096 1094
1095 pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
1096 if (pmif == NULL)
1097 return -ENOMEM;
1098
1097 i = 0; 1099 i = 0;
1098 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0 1100 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0))
1099 || pmac_ide[i].node != NULL))
1100 ++i; 1101 ++i;
1101 if (i >= MAX_HWIFS) { 1102 if (i >= MAX_HWIFS) {
1102 printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n"); 1103 printk(KERN_ERR "ide-pmac: MacIO interface attach with no slot\n");
1103 printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name); 1104 printk(KERN_ERR " %s\n", mdev->ofdev.node->full_name);
1104 return -ENODEV; 1105 rc = -ENODEV;
1106 goto out_free_pmif;
1105 } 1107 }
1106 1108
1107 pmif = &pmac_ide[i];
1108 hwif = &ide_hwifs[i]; 1109 hwif = &ide_hwifs[i];
1109 1110
1110 if (macio_resource_count(mdev) == 0) { 1111 if (macio_resource_count(mdev) == 0) {
1111 printk(KERN_WARNING "ide%d: no address for %s\n", 1112 printk(KERN_WARNING "ide%d: no address for %s\n",
1112 i, mdev->ofdev.node->full_name); 1113 i, mdev->ofdev.node->full_name);
1113 return -ENXIO; 1114 rc = -ENXIO;
1115 goto out_free_pmif;
1114 } 1116 }
1115 1117
1116 /* Request memory resource for IO ports */ 1118 /* Request memory resource for IO ports */
1117 if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) { 1119 if (macio_request_resource(mdev, 0, "ide-pmac (ports)")) {
1118 printk(KERN_ERR "ide%d: can't request mmio resource !\n", i); 1120 printk(KERN_ERR "ide%d: can't request mmio resource !\n", i);
1119 return -EBUSY; 1121 rc = -EBUSY;
1122 goto out_free_pmif;
1120 } 1123 }
1121 1124
1122 /* XXX This is bogus. Should be fixed in the registry by checking 1125 /* 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 iounmap(pmif->dma_regs); 1169 iounmap(pmif->dma_regs);
1167 macio_release_resource(mdev, 1); 1170 macio_release_resource(mdev, 1);
1168 } 1171 }
1169 memset(pmif, 0, sizeof(*pmif));
1170 macio_release_resource(mdev, 0); 1172 macio_release_resource(mdev, 0);
1173 kfree(pmif);
1171 } 1174 }
1172 1175
1173 return rc; 1176 return rc;
1177
1178out_free_pmif:
1179 kfree(pmif);
1180 return rc;
1174} 1181}
1175 1182
1176static int 1183static int
@@ -1223,30 +1230,36 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1223 printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n"); 1230 printk(KERN_ERR "ide-pmac: cannot find MacIO node for Kauai ATA interface\n");
1224 return -ENODEV; 1231 return -ENODEV;
1225 } 1232 }
1233
1234 pmif = kzalloc(sizeof(*pmif), GFP_KERNEL);
1235 if (pmif == NULL)
1236 return -ENOMEM;
1237
1226 i = 0; 1238 i = 0;
1227 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0 1239 while (i < MAX_HWIFS && (ide_hwifs[i].io_ports[IDE_DATA_OFFSET] != 0))
1228 || pmac_ide[i].node != NULL))
1229 ++i; 1240 ++i;
1230 if (i >= MAX_HWIFS) { 1241 if (i >= MAX_HWIFS) {
1231 printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n"); 1242 printk(KERN_ERR "ide-pmac: PCI interface attach with no slot\n");
1232 printk(KERN_ERR " %s\n", np->full_name); 1243 printk(KERN_ERR " %s\n", np->full_name);
1233 return -ENODEV; 1244 rc = -ENODEV;
1245 goto out_free_pmif;
1234 } 1246 }
1235 1247
1236 pmif = &pmac_ide[i];
1237 hwif = &ide_hwifs[i]; 1248 hwif = &ide_hwifs[i];
1238 1249
1239 if (pci_enable_device(pdev)) { 1250 if (pci_enable_device(pdev)) {
1240 printk(KERN_WARNING "ide%i: Can't enable PCI device for %s\n", 1251 printk(KERN_WARNING "ide%i: Can't enable PCI device for %s\n",
1241 i, np->full_name); 1252 i, np->full_name);
1242 return -ENXIO; 1253 rc = -ENXIO;
1254 goto out_free_pmif;
1243 } 1255 }
1244 pci_set_master(pdev); 1256 pci_set_master(pdev);
1245 1257
1246 if (pci_request_regions(pdev, "Kauai ATA")) { 1258 if (pci_request_regions(pdev, "Kauai ATA")) {
1247 printk(KERN_ERR "ide%d: Cannot obtain PCI resources for %s\n", 1259 printk(KERN_ERR "ide%d: Cannot obtain PCI resources for %s\n",
1248 i, np->full_name); 1260 i, np->full_name);
1249 return -ENXIO; 1261 rc = -ENXIO;
1262 goto out_free_pmif;
1250 } 1263 }
1251 1264
1252 hwif->dev = &pdev->dev; 1265 hwif->dev = &pdev->dev;
@@ -1276,11 +1289,15 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
1276 /* The inteface is released to the common IDE layer */ 1289 /* The inteface is released to the common IDE layer */
1277 pci_set_drvdata(pdev, NULL); 1290 pci_set_drvdata(pdev, NULL);
1278 iounmap(base); 1291 iounmap(base);
1279 memset(pmif, 0, sizeof(*pmif));
1280 pci_release_regions(pdev); 1292 pci_release_regions(pdev);
1293 kfree(pmif);
1281 } 1294 }
1282 1295
1283 return rc; 1296 return rc;
1297
1298out_free_pmif:
1299 kfree(pmif);
1300 return rc;
1284} 1301}
1285 1302
1286static int 1303static int