aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/r6040.c
diff options
context:
space:
mode:
authorFlorian Fainelli <florian.fainelli@telecomint.eu>2008-07-21 06:32:29 -0400
committerJeff Garzik <jgarzik@redhat.com>2008-07-22 20:00:01 -0400
commitb0e453902ad53580a77c2b1baddcc0b2d8ce8acc (patch)
tree6e58208b5872fe4a18c0aa52cd1e2fc32180defc /drivers/net/r6040.c
parent1de95294f16cab0e924e1b4cd9b554a6eca65e6e (diff)
r6040: rework init_one error handling
This patch reworks the error handling in r6040_init_one in order not to leak resources and correcly unmap and release PCI regions of the MAC. Also prefix printk's with the driver name for clarity. Signed-off-by: Florian Fainelli <florian.fainelli@telecomint.eu> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
Diffstat (limited to 'drivers/net/r6040.c')
-rw-r--r--drivers/net/r6040.c44
1 files changed, 25 insertions, 19 deletions
diff --git a/drivers/net/r6040.c b/drivers/net/r6040.c
index 1cafa92c282c..6531ff565c54 100644
--- a/drivers/net/r6040.c
+++ b/drivers/net/r6040.c
@@ -1054,24 +1054,27 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
1054 1054
1055 err = pci_enable_device(pdev); 1055 err = pci_enable_device(pdev);
1056 if (err) 1056 if (err)
1057 return err; 1057 goto err_out;
1058 1058
1059 /* this should always be supported */ 1059 /* this should always be supported */
1060 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { 1060 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
1061 if (err) {
1061 printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses" 1062 printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses"
1062 "not supported by the card\n"); 1063 "not supported by the card\n");
1063 return -ENODEV; 1064 goto err_out;
1064 } 1065 }
1065 if (pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)) { 1066 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1067 if (err) {
1066 printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses" 1068 printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses"
1067 "not supported by the card\n"); 1069 "not supported by the card\n");
1068 return -ENODEV; 1070 goto err_out;
1069 } 1071 }
1070 1072
1071 /* IO Size check */ 1073 /* IO Size check */
1072 if (pci_resource_len(pdev, 0) < io_size) { 1074 if (pci_resource_len(pdev, 0) < io_size) {
1073 printk(KERN_ERR "Insufficient PCI resources, aborting\n"); 1075 printk(KERN_ERR DRV_NAME "Insufficient PCI resources, aborting\n");
1074 return -EIO; 1076 err = -EIO;
1077 goto err_out;
1075 } 1078 }
1076 1079
1077 pioaddr = pci_resource_start(pdev, 0); /* IO map base address */ 1080 pioaddr = pci_resource_start(pdev, 0); /* IO map base address */
@@ -1079,23 +1082,26 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
1079 1082
1080 dev = alloc_etherdev(sizeof(struct r6040_private)); 1083 dev = alloc_etherdev(sizeof(struct r6040_private));
1081 if (!dev) { 1084 if (!dev) {
1082 printk(KERN_ERR "Failed to allocate etherdev\n"); 1085 printk(KERN_ERR DRV_NAME "Failed to allocate etherdev\n");
1083 return -ENOMEM; 1086 err = -ENOMEM;
1087 goto err_out;
1084 } 1088 }
1085 SET_NETDEV_DEV(dev, &pdev->dev); 1089 SET_NETDEV_DEV(dev, &pdev->dev);
1086 lp = netdev_priv(dev); 1090 lp = netdev_priv(dev);
1087 1091
1088 if (pci_request_regions(pdev, DRV_NAME)) { 1092 err = pci_request_regions(pdev, DRV_NAME);
1093
1094 if (err) {
1089 printk(KERN_ERR DRV_NAME ": Failed to request PCI regions\n"); 1095 printk(KERN_ERR DRV_NAME ": Failed to request PCI regions\n");
1090 err = -ENODEV; 1096 goto err_out_free_dev;
1091 goto err_out_disable;
1092 } 1097 }
1093 1098
1094 ioaddr = pci_iomap(pdev, bar, io_size); 1099 ioaddr = pci_iomap(pdev, bar, io_size);
1095 if (!ioaddr) { 1100 if (!ioaddr) {
1096 printk(KERN_ERR "ioremap failed for device %s\n", 1101 printk(KERN_ERR "ioremap failed for device %s\n",
1097 pci_name(pdev)); 1102 pci_name(pdev));
1098 return -EIO; 1103 err = -EIO;
1104 goto err_out_free_res;
1099 } 1105 }
1100 1106
1101 /* Init system & device */ 1107 /* Init system & device */
@@ -1147,17 +1153,17 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
1147 err = register_netdev(dev); 1153 err = register_netdev(dev);
1148 if (err) { 1154 if (err) {
1149 printk(KERN_ERR DRV_NAME ": Failed to register net device\n"); 1155 printk(KERN_ERR DRV_NAME ": Failed to register net device\n");
1150 goto err_out_res; 1156 goto err_out_unmap;
1151 } 1157 }
1152 return 0; 1158 return 0;
1153 1159
1154err_out_res: 1160err_out_unmap:
1161 pci_iounmap(pdev, ioaddr);
1162err_out_free_res:
1155 pci_release_regions(pdev); 1163 pci_release_regions(pdev);
1156err_out_disable: 1164err_out_free_dev:
1157 pci_disable_device(pdev);
1158 pci_set_drvdata(pdev, NULL);
1159 free_netdev(dev); 1165 free_netdev(dev);
1160 1166err_out:
1161 return err; 1167 return err;
1162} 1168}
1163 1169