Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sparc64: Simplify error handling in PCI controller probing.

Based upon suggestions from Stephen Rothwell.

Signed-off-by: David S. Miller <davem@davemloft.net>

+68 -62
+10 -11
arch/sparc64/kernel/pci_fire.c
··· 515 515 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); 516 516 if (!p) { 517 517 printk(KERN_ERR PFX "Cannot allocate controller info.\n"); 518 - goto out_free; 518 + goto out_err; 519 519 } 520 520 521 521 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); 522 522 if (!iommu) { 523 523 printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n"); 524 - goto out_free; 524 + goto out_free_controller; 525 525 } 526 526 527 527 p->pbm_A.iommu = iommu; ··· 529 529 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); 530 530 if (!iommu) { 531 531 printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n"); 532 - goto out_free; 532 + goto out_free_iommu_A; 533 533 } 534 534 535 535 p->pbm_B.iommu = iommu; 536 536 537 537 return pci_fire_pbm_init(p, dp, portid); 538 538 539 - out_free: 540 - if (p) { 541 - if (p->pbm_A.iommu) 542 - kfree(p->pbm_A.iommu); 543 - if (p->pbm_B.iommu) 544 - kfree(p->pbm_B.iommu); 545 - kfree(p); 546 - } 539 + out_free_iommu_A: 540 + kfree(p->pbm_A.iommu); 541 + 542 + out_free_controller: 543 + kfree(p); 544 + 545 + out_err: 547 546 return err; 548 547 } 549 548
+11 -10
arch/sparc64/kernel/pci_psycho.c
··· 1051 1051 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); 1052 1052 if (!p) { 1053 1053 printk(KERN_ERR PFX "Cannot allocate controller info.\n"); 1054 - goto out_free; 1054 + goto out_err; 1055 1055 } 1056 1056 1057 1057 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); 1058 1058 if (!iommu) { 1059 1059 printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n"); 1060 - goto out_free; 1060 + goto out_free_controller; 1061 1061 } 1062 1062 1063 1063 p->pbm_A.iommu = p->pbm_B.iommu = iommu; ··· 1069 1069 err = -ENODEV; 1070 1070 if (!pr_regs) { 1071 1071 printk(KERN_ERR PFX "No reg property.\n"); 1072 - goto out_free; 1072 + goto out_free_iommu; 1073 1073 } 1074 1074 1075 1075 p->pbm_A.controller_regs = pr_regs[2].phys_addr; ··· 1082 1082 1083 1083 err = psycho_iommu_init(&p->pbm_A); 1084 1084 if (err) 1085 - goto out_free; 1085 + goto out_free_iommu; 1086 1086 1087 1087 is_pbm_a = ((pr_regs[0].phys_addr & 0x6000) == 0x2000); 1088 1088 ··· 1090 1090 1091 1091 return 0; 1092 1092 1093 - out_free: 1094 - if (p) { 1095 - if (p->pbm_A.iommu) 1096 - kfree(p->pbm_A.iommu); 1097 - kfree(p); 1098 - } 1093 + out_free_iommu: 1094 + kfree(p->pbm_A.iommu); 1095 + 1096 + out_free_controller: 1097 + kfree(p); 1098 + 1099 + out_err: 1099 1100 return err; 1100 1101 } 1101 1102
+13 -12
arch/sparc64/kernel/pci_sabre.c
··· 786 786 p = kzalloc(sizeof(*p), GFP_ATOMIC); 787 787 if (!p) { 788 788 printk(KERN_ERR PFX "Cannot allocate controller info.\n"); 789 - goto out_free; 789 + goto out_err; 790 790 } 791 791 792 792 iommu = kzalloc(sizeof(*iommu), GFP_ATOMIC); 793 793 if (!iommu) { 794 794 printk(KERN_ERR PFX "Cannot allocate PBM iommu.\n"); 795 - goto out_free; 795 + goto out_free_controller; 796 796 } 797 797 798 798 pbm = &p->pbm_A; ··· 813 813 err = -ENODEV; 814 814 if (!pr_regs) { 815 815 printk(KERN_ERR PFX "No reg property\n"); 816 - goto out_free; 816 + goto out_free_iommu; 817 817 } 818 818 819 819 /* ··· 843 843 vdma = of_get_property(dp, "virtual-dma", NULL); 844 844 if (!vdma) { 845 845 printk(KERN_ERR PFX "No virtual-dma property\n"); 846 - goto out_free; 846 + goto out_free_iommu; 847 847 } 848 848 849 849 dma_mask = vdma[0]; ··· 863 863 break; 864 864 default: 865 865 printk(KERN_ERR PFX "Strange virtual-dma size.\n"); 866 - goto out_free; 866 + goto out_free_iommu; 867 867 } 868 868 869 869 err = sabre_iommu_init(pbm, tsbsize, vdma[0], dma_mask); 870 870 if (err) 871 - goto out_free; 871 + goto out_free_iommu; 872 872 873 873 /* 874 874 * Look for APB underneath. ··· 876 876 sabre_pbm_init(p, pbm, dp); 877 877 return 0; 878 878 879 - out_free: 880 - if (p) { 881 - if (p->pbm_A.iommu) 882 - kfree(p->pbm_A.iommu); 883 - kfree(p); 884 - } 879 + out_free_iommu: 880 + kfree(p->pbm_A.iommu); 881 + 882 + out_free_controller: 883 + kfree(p); 884 + 885 + out_err: 885 886 return err; 886 887 } 887 888
+18 -14
arch/sparc64/kernel/pci_schizo.c
··· 1443 1443 struct pci_pbm_info *pbm; 1444 1444 struct iommu *iommu; 1445 1445 u32 portid; 1446 + int err; 1446 1447 1447 1448 portid = of_getintprop_default(dp, "portid", 0xff); 1448 1449 1450 + err = -ENOMEM; 1449 1451 for (pbm = pci_pbm_root; pbm; pbm = pbm->next) { 1450 1452 if (portid_compare(pbm->portid, portid, chip_type)) { 1451 1453 if (schizo_pbm_init(pbm->parent, dp, 1452 1454 portid, chip_type)) 1453 - return -ENOMEM; 1455 + goto out_err; 1454 1456 return 0; 1455 1457 } 1456 1458 } ··· 1460 1458 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); 1461 1459 if (!p) { 1462 1460 printk(KERN_ERR PFX "Cannot allocate controller info.\n"); 1463 - goto out_free; 1461 + goto out_err; 1464 1462 } 1465 1463 1466 1464 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); 1467 1465 if (!iommu) { 1468 1466 printk(KERN_ERR PFX "Cannot allocate PBM A iommu.\n"); 1469 - goto out_free; 1467 + goto out_free_controller; 1470 1468 } 1471 1469 1472 1470 p->pbm_A.iommu = iommu; ··· 1474 1472 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); 1475 1473 if (!iommu) { 1476 1474 printk(KERN_ERR PFX "Cannot allocate PBM B iommu.\n"); 1477 - goto out_free; 1475 + goto out_free_iommu_A; 1478 1476 } 1479 1477 1480 1478 p->pbm_B.iommu = iommu; 1481 1479 1482 1480 if (schizo_pbm_init(p, dp, portid, chip_type)) 1483 - goto out_free; 1481 + goto out_free_iommu_B; 1484 1482 1485 1483 return 0; 1486 1484 1487 - out_free: 1488 - if (p) { 1489 - if (p->pbm_A.iommu) 1490 - kfree(p->pbm_A.iommu); 1491 - if (p->pbm_B.iommu) 1492 - kfree(p->pbm_B.iommu); 1493 - kfree(p); 1494 - } 1495 - return -ENOMEM; 1485 + out_free_iommu_B: 1486 + kfree(p->pbm_B.iommu); 1487 + 1488 + out_free_iommu_A: 1489 + kfree(p->pbm_A.iommu); 1490 + 1491 + out_free_controller: 1492 + kfree(p); 1493 + 1494 + out_err: 1495 + return err; 1496 1496 } 1497 1497 1498 1498 static int __devinit schizo_probe(struct of_device *op,
+16 -15
arch/sparc64/kernel/pci_sun4v.c
··· 949 949 struct device_node *dp; 950 950 struct iommu *iommu; 951 951 u32 devhandle; 952 - int i; 952 + int i, err; 953 953 954 954 dp = op->node; 955 955 ··· 970 970 } 971 971 972 972 regs = of_get_property(dp, "reg", NULL); 973 + err = -ENODEV; 973 974 if (!regs) { 974 975 printk(KERN_ERR PFX "Could not find config registers\n"); 975 - return -ENODEV; 976 + goto out_err; 976 977 } 977 978 devhandle = (regs->phys_addr >> 32UL) & 0x0fffffff; 978 979 ··· 983 982 } 984 983 } 985 984 985 + err = -ENOMEM; 986 986 for_each_possible_cpu(i) { 987 987 unsigned long page = get_zeroed_page(GFP_ATOMIC); 988 988 989 989 if (!page) 990 - return -ENOMEM; 990 + goto out_err; 991 991 992 992 per_cpu(iommu_batch, i).pglist = (u64 *) page; 993 993 } ··· 996 994 p = kzalloc(sizeof(struct pci_controller_info), GFP_ATOMIC); 997 995 if (!p) { 998 996 printk(KERN_ERR PFX "Could not allocate pci_controller_info\n"); 999 - goto out_free; 997 + goto out_err; 1000 998 } 1001 999 1002 1000 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); 1003 1001 if (!iommu) { 1004 1002 printk(KERN_ERR PFX "Could not allocate pbm A iommu\n"); 1005 - goto out_free; 1003 + goto out_free_controller; 1006 1004 } 1007 1005 1008 1006 p->pbm_A.iommu = iommu; ··· 1010 1008 iommu = kzalloc(sizeof(struct iommu), GFP_ATOMIC); 1011 1009 if (!iommu) { 1012 1010 printk(KERN_ERR PFX "Could not allocate pbm B iommu\n"); 1013 - goto out_free; 1011 + goto out_free_iommu_A; 1014 1012 } 1015 1013 1016 1014 p->pbm_B.iommu = iommu; 1017 1015 1018 1016 return pci_sun4v_pbm_init(p, dp, devhandle); 1019 1017 1020 - out_free: 1021 - if (p) { 1022 - if (p->pbm_A.iommu) 1023 - kfree(p->pbm_A.iommu); 1024 - if (p->pbm_B.iommu) 1025 - kfree(p->pbm_B.iommu); 1026 - kfree(p); 1027 - } 1028 - return -ENOMEM; 1018 + out_free_iommu_A: 1019 + kfree(p->pbm_A.iommu); 1020 + 1021 + out_free_controller: 1022 + kfree(p); 1023 + 1024 + out_err: 1025 + return err; 1029 1026 } 1030 1027 1031 1028 static struct of_device_id __initdata pci_sun4v_match[] = {