Commit d7472c38 authored by David S. Miller's avatar David S. Miller

sparc64: Simplify error handling in PCI controller probing.

Based upon suggestions from Stephen Rothwell.
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fd098316
...@@ -515,13 +515,13 @@ static int __devinit fire_probe(struct of_device *op, ...@@ -515,13 +515,13 @@ static int __devinit fire_probe(struct of_device *op,
p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
if (!p) { if (!p) {
printk(KERN_ERR PFX "Cannot allocate controller info.\n"); printk(KERN_ERR PFX "Cannot allocate controller info.\n");
goto out_free; goto out_err;
} }
iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) { if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n"); printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n");
goto out_free; goto out_free_controller;
} }
p->pbm_A.iommu = iommu; p->pbm_A.iommu = iommu;
...@@ -529,21 +529,20 @@ static int __devinit fire_probe(struct of_device *op, ...@@ -529,21 +529,20 @@ static int __devinit fire_probe(struct of_device *op,
iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) { if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n"); printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n");
goto out_free; goto out_free_iommu_A;
} }
p->pbm_B.iommu = iommu; p->pbm_B.iommu = iommu;
return pci_fire_pbm_init(p, dp, portid); return pci_fire_pbm_init(p, dp, portid);
out_free: out_free_iommu_A:
if (p) { kfree(p->pbm_A.iommu);
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu); out_free_controller:
if (p->pbm_B.iommu) kfree(p);
kfree(p->pbm_B.iommu);
kfree(p); out_err:
}
return err; return err;
} }
......
...@@ -1051,13 +1051,13 @@ static int __devinit psycho_probe(struct of_device *op, ...@@ -1051,13 +1051,13 @@ static int __devinit psycho_probe(struct of_device *op,
p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
if (!p) { if (!p) {
printk(KERN_ERR PFX "Cannot allocate controller info.\n"); printk(KERN_ERR PFX "Cannot allocate controller info.\n");
goto out_free; goto out_err;
} }
iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) { if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n"); printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n");
goto out_free; goto out_free_controller;
} }
p->pbm_A.iommu = p->pbm_B.iommu = iommu; p->pbm_A.iommu = p->pbm_B.iommu = iommu;
...@@ -1069,7 +1069,7 @@ static int __devinit psycho_probe(struct of_device *op, ...@@ -1069,7 +1069,7 @@ static int __devinit psycho_probe(struct of_device *op,
err = -ENODEV; err = -ENODEV;
if (!pr_regs) { if (!pr_regs) {
printk(KERN_ERR PFX "No reg property.\n"); printk(KERN_ERR PFX "No reg property.\n");
goto out_free; goto out_free_iommu;
} }
p->pbm_A.controller_regs = pr_regs[2].phys_addr; p->pbm_A.controller_regs = pr_regs[2].phys_addr;
...@@ -1082,7 +1082,7 @@ static int __devinit psycho_probe(struct of_device *op, ...@@ -1082,7 +1082,7 @@ static int __devinit psycho_probe(struct of_device *op,
err = psycho_iommu_init(&p->pbm_A); err = psycho_iommu_init(&p->pbm_A);
if (err) if (err)
goto out_free; goto out_free_iommu;
is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000); is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);
...@@ -1090,12 +1090,13 @@ static int __devinit psycho_probe(struct of_device *op, ...@@ -1090,12 +1090,13 @@ static int __devinit psycho_probe(struct of_device *op,
return 0; return 0;
out_free: out_free_iommu:
if (p) { kfree(p->pbm_A.iommu);
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu); out_free_controller:
kfree(p); kfree(p);
}
out_err:
return err; return err;
} }
......
...@@ -786,13 +786,13 @@ static int __devinit sabre_probe(struct of_device *op, ...@@ -786,13 +786,13 @@ static int __devinit sabre_probe(struct of_device *op,
p = kzalloc(sizeof(*p), GFP_ATOMIC); p = kzalloc(sizeof(*p), GFP_ATOMIC);
if (!p) { if (!p) {
printk(KERN_ERR PFX "Cannot allocate controller info.\n"); printk(KERN_ERR PFX "Cannot allocate controller info.\n");
goto out_free; goto out_err;
} }
iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC); iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
if (!iommu) { if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n"); printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n");
goto out_free; goto out_free_controller;
} }
pbm = &p->pbm_A; pbm = &p->pbm_A;
...@@ -813,7 +813,7 @@ static int __devinit sabre_probe(struct of_device *op, ...@@ -813,7 +813,7 @@ static int __devinit sabre_probe(struct of_device *op,
err = -ENODEV; err = -ENODEV;
if (!pr_regs) { if (!pr_regs) {
printk(KERN_ERR PFX "No reg property\n"); printk(KERN_ERR PFX "No reg property\n");
goto out_free; goto out_free_iommu;
} }
/* /*
...@@ -843,7 +843,7 @@ static int __devinit sabre_probe(struct of_device *op, ...@@ -843,7 +843,7 @@ static int __devinit sabre_probe(struct of_device *op,
vdma = of_get_property(dp, "virtual-dma", NULL); vdma = of_get_property(dp, "virtual-dma", NULL);
if (!vdma) { if (!vdma) {
printk(KERN_ERR PFX "No virtual-dma property\n"); printk(KERN_ERR PFX "No virtual-dma property\n");
goto out_free; goto out_free_iommu;
} }
dma_mask = vdma[0]; dma_mask = vdma[0];
...@@ -863,12 +863,12 @@ static int __devinit sabre_probe(struct of_device *op, ...@@ -863,12 +863,12 @@ static int __devinit sabre_probe(struct of_device *op,
break; break;
default: default:
printk(KERN_ERR PFX "Strange virtual-dma size.\n"); printk(KERN_ERR PFX "Strange virtual-dma size.\n");
goto out_free; goto out_free_iommu;
} }
err = sabre_iommu_init(pbm, tsbsize, vdma[0], dma_mask); err = sabre_iommu_init(pbm, tsbsize, vdma[0], dma_mask);
if (err) if (err)
goto out_free; goto out_free_iommu;
/* /*
* Look for APB underneath. * Look for APB underneath.
...@@ -876,12 +876,13 @@ static int __devinit sabre_probe(struct of_device *op, ...@@ -876,12 +876,13 @@ static int __devinit sabre_probe(struct of_device *op,
sabre_pbm_init(p, pbm, dp); sabre_pbm_init(p, pbm, dp);
return 0; return 0;
out_free: out_free_iommu:
if (p) { kfree(p->pbm_A.iommu);
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu); out_free_controller:
kfree(p); kfree(p);
}
out_err:
return err; return err;
} }
......
...@@ -1443,14 +1443,16 @@ static int __devinit __schizo_init(struct device_node *dp, unsigned long chip_ty ...@@ -1443,14 +1443,16 @@ static int __devinit __schizo_init(struct device_node *dp, unsigned long chip_ty
struct pci_pbm_info *pbm; struct pci_pbm_info *pbm;
struct iommu *iommu; struct iommu *iommu;
u32 portid; u32 portid;
int err;
portid = of_getintprop_default(dp, "portid", 0xff); portid = of_getintprop_default(dp, "portid", 0xff);
err = -ENOMEM;
for (pbm = pci_pbm_root; pbm; pbm = pbm->next) { for (pbm = pci_pbm_root; pbm; pbm = pbm->next) {
if (portid_compare(pbm->portid, portid, chip_type)) { if (portid_compare(pbm->portid, portid, chip_type)) {
if (schizo_pbm_init(pbm->parent, dp, if (schizo_pbm_init(pbm->parent, dp,
portid, chip_type)) portid, chip_type))
return -ENOMEM; goto out_err;
return 0; return 0;
} }
} }
...@@ -1458,13 +1460,13 @@ static int __devinit __schizo_init(struct device_node *dp, unsigned long chip_ty ...@@ -1458,13 +1460,13 @@ static int __devinit __schizo_init(struct device_node *dp, unsigned long chip_ty
p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
if (!p) { if (!p) {
printk(KERN_ERR PFX "Cannot allocate controller info.\n"); printk(KERN_ERR PFX "Cannot allocate controller info.\n");
goto out_free; goto out_err;
} }
iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) { if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n"); printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n");
goto out_free; goto out_free_controller;
} }
p->pbm_A.iommu = iommu; p->pbm_A.iommu = iommu;
...@@ -1472,25 +1474,27 @@ static int __devinit __schizo_init(struct device_node *dp, unsigned long chip_ty ...@@ -1472,25 +1474,27 @@ static int __devinit __schizo_init(struct device_node *dp, unsigned long chip_ty
iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) { if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM B iommu.\n"); printk(KERN_ERR PFX "Cannot allocate PBM B iommu.\n");
goto out_free; goto out_free_iommu_A;
} }
p->pbm_B.iommu = iommu; p->pbm_B.iommu = iommu;
if (schizo_pbm_init(p, dp, portid, chip_type)) if (schizo_pbm_init(p, dp, portid, chip_type))
goto out_free; goto out_free_iommu_B;
return 0; return 0;
out_free: out_free_iommu_B:
if (p) { kfree(p->pbm_B.iommu);
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu); out_free_iommu_A:
if (p->pbm_B.iommu) kfree(p->pbm_A.iommu);
kfree(p->pbm_B.iommu);
kfree(p); out_free_controller:
} kfree(p);
return -ENOMEM;
out_err:
return err;
} }
static int __devinit schizo_probe(struct of_device *op, static int __devinit schizo_probe(struct of_device *op,
......
...@@ -949,7 +949,7 @@ static int __devinit pci_sun4v_probe(struct of_device *op, ...@@ -949,7 +949,7 @@ static int __devinit pci_sun4v_probe(struct of_device *op,
struct device_node *dp; struct device_node *dp;
struct iommu *iommu; struct iommu *iommu;
u32 devhandle; u32 devhandle;
int i; int i, err;
dp = op->node; dp = op->node;
...@@ -970,9 +970,10 @@ static int __devinit pci_sun4v_probe(struct of_device *op, ...@@ -970,9 +970,10 @@ static int __devinit pci_sun4v_probe(struct of_device *op,
} }
regs = of_get_property(dp, "reg", NULL); regs = of_get_property(dp, "reg", NULL);
err = -ENODEV;
if (!regs) { if (!regs) {
printk(KERN_ERR PFX "Could not find config registers\n"); printk(KERN_ERR PFX "Could not find config registers\n");
return -ENODEV; goto out_err;
} }
devhandle = (regs->phys_addr >> 32UL) & 0x0fffffff; devhandle = (regs->phys_addr >> 32UL) & 0x0fffffff;
...@@ -982,11 +983,12 @@ static int __devinit pci_sun4v_probe(struct of_device *op, ...@@ -982,11 +983,12 @@ static int __devinit pci_sun4v_probe(struct of_device *op,
} }
} }
err = -ENOMEM;
for_each_possible_cpu(i) { for_each_possible_cpu(i) {
unsigned long page = get_zeroed_page(GFP_ATOMIC); unsigned long page = get_zeroed_page(GFP_ATOMIC);
if (!page) if (!page)
return -ENOMEM; goto out_err;
per_cpu(iommu_batch, i).pglist = (u64 *) page; per_cpu(iommu_batch, i).pglist = (u64 *) page;
} }
...@@ -994,13 +996,13 @@ static int __devinit pci_sun4v_probe(struct of_device *op, ...@@ -994,13 +996,13 @@ static int __devinit pci_sun4v_probe(struct of_device *op,
p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
if (!p) { if (!p) {
printk(KERN_ERR PFX "Could not allocate pci_controller_info\n"); printk(KERN_ERR PFX "Could not allocate pci_controller_info\n");
goto out_free; goto out_err;
} }
iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) { if (!iommu) {
printk(KERN_ERR PFX "Could not allocate pbm A iommu\n"); printk(KERN_ERR PFX "Could not allocate pbm A iommu\n");
goto out_free; goto out_free_controller;
} }
p->pbm_A.iommu = iommu; p->pbm_A.iommu = iommu;
...@@ -1008,22 +1010,21 @@ static int __devinit pci_sun4v_probe(struct of_device *op, ...@@ -1008,22 +1010,21 @@ static int __devinit pci_sun4v_probe(struct of_device *op,
iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) { if (!iommu) {
printk(KERN_ERR PFX "Could not allocate pbm B iommu\n"); printk(KERN_ERR PFX "Could not allocate pbm B iommu\n");
goto out_free; goto out_free_iommu_A;
} }
p->pbm_B.iommu = iommu; p->pbm_B.iommu = iommu;
return pci_sun4v_pbm_init(p, dp, devhandle); return pci_sun4v_pbm_init(p, dp, devhandle);
out_free: out_free_iommu_A:
if (p) { kfree(p->pbm_A.iommu);
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu); out_free_controller:
if (p->pbm_B.iommu) kfree(p);
kfree(p->pbm_B.iommu);
kfree(p); out_err:
} return err;
return -ENOMEM;
} }
static struct of_device_id __initdata pci_sun4v_match[] = { static struct of_device_id __initdata pci_sun4v_match[] = {
......
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