Skip to content

Commit

Permalink
sparc64: Simplify error handling in PCI controller probing.
Browse files Browse the repository at this point in the history
Based upon suggestions from Stephen Rothwell.

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Aug 31, 2008
1 parent fd09831 commit d7472c3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 62 deletions.
21 changes: 10 additions & 11 deletions arch/sparc64/kernel/pci_fire.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,35 +515,34 @@ static int __devinit fire_probe(struct of_device *op,
p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
if (!p) {
printk(KERN_ERR PFX "Cannot allocate controller info.\n");
goto out_free;
goto out_err;
}

iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n");
goto out_free;
goto out_free_controller;
}

p->pbm_A.iommu = iommu;

iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n");
goto out_free;
goto out_free_iommu_A;
}

p->pbm_B.iommu = iommu;

return pci_fire_pbm_init(p, dp, portid);

out_free:
if (p) {
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu);
if (p->pbm_B.iommu)
kfree(p->pbm_B.iommu);
kfree(p);
}
out_free_iommu_A:
kfree(p->pbm_A.iommu);

out_free_controller:
kfree(p);

out_err:
return err;
}

Expand Down
21 changes: 11 additions & 10 deletions arch/sparc64/kernel/pci_psycho.c
Original file line number Diff line number Diff line change
Expand Up @@ -1051,13 +1051,13 @@ static int __devinit psycho_probe(struct of_device *op,
p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
if (!p) {
printk(KERN_ERR PFX "Cannot allocate controller info.\n");
goto out_free;
goto out_err;
}

iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) {
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;
Expand All @@ -1069,7 +1069,7 @@ static int __devinit psycho_probe(struct of_device *op,
err = -ENODEV;
if (!pr_regs) {
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;
Expand All @@ -1082,20 +1082,21 @@ static int __devinit psycho_probe(struct of_device *op,

err = psycho_iommu_init(&p->pbm_A);
if (err)
goto out_free;
goto out_free_iommu;

is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000);

psycho_pbm_init(p, dp, is_pbm_a);

return 0;

out_free:
if (p) {
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu);
kfree(p);
}
out_free_iommu:
kfree(p->pbm_A.iommu);

out_free_controller:
kfree(p);

out_err:
return err;
}

Expand Down
25 changes: 13 additions & 12 deletions arch/sparc64/kernel/pci_sabre.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,13 +786,13 @@ static int __devinit sabre_probe(struct of_device *op,
p = kzalloc(sizeof(*p), GFP_ATOMIC);
if (!p) {
printk(KERN_ERR PFX "Cannot allocate controller info.\n");
goto out_free;
goto out_err;
}

iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC);
if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n");
goto out_free;
goto out_free_controller;
}

pbm = &p->pbm_A;
Expand All @@ -813,7 +813,7 @@ static int __devinit sabre_probe(struct of_device *op,
err = -ENODEV;
if (!pr_regs) {
printk(KERN_ERR PFX "No reg property\n");
goto out_free;
goto out_free_iommu;
}

/*
Expand Down Expand Up @@ -843,7 +843,7 @@ static int __devinit sabre_probe(struct of_device *op,
vdma = of_get_property(dp, "virtual-dma", NULL);
if (!vdma) {
printk(KERN_ERR PFX "No virtual-dma property\n");
goto out_free;
goto out_free_iommu;
}

dma_mask = vdma[0];
Expand All @@ -863,25 +863,26 @@ static int __devinit sabre_probe(struct of_device *op,
break;
default:
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);
if (err)
goto out_free;
goto out_free_iommu;

/*
* Look for APB underneath.
*/
sabre_pbm_init(p, pbm, dp);
return 0;

out_free:
if (p) {
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu);
kfree(p);
}
out_free_iommu:
kfree(p->pbm_A.iommu);

out_free_controller:
kfree(p);

out_err:
return err;
}

Expand Down
32 changes: 18 additions & 14 deletions arch/sparc64/kernel/pci_schizo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1443,54 +1443,58 @@ static int __devinit __schizo_init(struct device_node *dp, unsigned long chip_ty
struct pci_pbm_info *pbm;
struct iommu *iommu;
u32 portid;
int err;

portid = of_getintprop_default(dp, "portid", 0xff);

err = -ENOMEM;
for (pbm = pci_pbm_root; pbm; pbm = pbm->next) {
if (portid_compare(pbm->portid, portid, chip_type)) {
if (schizo_pbm_init(pbm->parent, dp,
portid, chip_type))
return -ENOMEM;
goto out_err;
return 0;
}
}

p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
if (!p) {
printk(KERN_ERR PFX "Cannot allocate controller info.\n");
goto out_free;
goto out_err;
}

iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n");
goto out_free;
goto out_free_controller;
}

p->pbm_A.iommu = iommu;

iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) {
printk(KERN_ERR PFX "Cannot allocate PBM B iommu.\n");
goto out_free;
goto out_free_iommu_A;
}

p->pbm_B.iommu = iommu;

if (schizo_pbm_init(p, dp, portid, chip_type))
goto out_free;
goto out_free_iommu_B;

return 0;

out_free:
if (p) {
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu);
if (p->pbm_B.iommu)
kfree(p->pbm_B.iommu);
kfree(p);
}
return -ENOMEM;
out_free_iommu_B:
kfree(p->pbm_B.iommu);

out_free_iommu_A:
kfree(p->pbm_A.iommu);

out_free_controller:
kfree(p);

out_err:
return err;
}

static int __devinit schizo_probe(struct of_device *op,
Expand Down
31 changes: 16 additions & 15 deletions arch/sparc64/kernel/pci_sun4v.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ static int __devinit pci_sun4v_probe(struct of_device *op,
struct device_node *dp;
struct iommu *iommu;
u32 devhandle;
int i;
int i, err;

dp = op->node;

Expand All @@ -970,9 +970,10 @@ static int __devinit pci_sun4v_probe(struct of_device *op,
}

regs = of_get_property(dp, "reg", NULL);
err = -ENODEV;
if (!regs) {
printk(KERN_ERR PFX "Could not find config registers\n");
return -ENODEV;
goto out_err;
}
devhandle = (regs->phys_addr >> 32UL) & 0x0fffffff;

Expand All @@ -982,48 +983,48 @@ static int __devinit pci_sun4v_probe(struct of_device *op,
}
}

err = -ENOMEM;
for_each_possible_cpu(i) {
unsigned long page = get_zeroed_page(GFP_ATOMIC);

if (!page)
return -ENOMEM;
goto out_err;

per_cpu(iommu_batch, i).pglist = (u64 *) page;
}

p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC);
if (!p) {
printk(KERN_ERR PFX "Could not allocate pci_controller_info\n");
goto out_free;
goto out_err;
}

iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) {
printk(KERN_ERR PFX "Could not allocate pbm A iommu\n");
goto out_free;
goto out_free_controller;
}

p->pbm_A.iommu = iommu;

iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC);
if (!iommu) {
printk(KERN_ERR PFX "Could not allocate pbm B iommu\n");
goto out_free;
goto out_free_iommu_A;
}

p->pbm_B.iommu = iommu;

return pci_sun4v_pbm_init(p, dp, devhandle);

out_free:
if (p) {
if (p->pbm_A.iommu)
kfree(p->pbm_A.iommu);
if (p->pbm_B.iommu)
kfree(p->pbm_B.iommu);
kfree(p);
}
return -ENOMEM;
out_free_iommu_A:
kfree(p->pbm_A.iommu);

out_free_controller:
kfree(p);

out_err:
return err;
}

static struct of_device_id __initdata pci_sun4v_match[] = {
Expand Down

0 comments on commit d7472c3

Please sign in to comment.