Commit b0e45390 authored by Florian Fainelli's avatar Florian Fainelli Committed by Jeff Garzik

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: default avatarFlorian Fainelli <florian.fainelli@telecomint.eu>
Signed-off-by: default avatarJeff Garzik <jgarzik@redhat.com>
parent 1de95294
...@@ -1054,24 +1054,27 @@ static int __devinit r6040_init_one(struct pci_dev *pdev, ...@@ -1054,24 +1054,27 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
err = pci_enable_device(pdev); err = pci_enable_device(pdev);
if (err) if (err)
return err; goto err_out;
/* this should always be supported */ /* this should always be supported */
if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) { err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
if (err) {
printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses" printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses"
"not supported by the card\n"); "not supported by the card\n");
return -ENODEV; goto err_out;
} }
if (pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK)) { err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
if (err) {
printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses" printk(KERN_ERR DRV_NAME "32-bit PCI DMA addresses"
"not supported by the card\n"); "not supported by the card\n");
return -ENODEV; goto err_out;
} }
/* IO Size check */ /* IO Size check */
if (pci_resource_len(pdev, 0) < io_size) { if (pci_resource_len(pdev, 0) < io_size) {
printk(KERN_ERR "Insufficient PCI resources, aborting\n"); printk(KERN_ERR DRV_NAME "Insufficient PCI resources, aborting\n");
return -EIO; err = -EIO;
goto err_out;
} }
pioaddr = pci_resource_start(pdev, 0); /* IO map base address */ 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,23 +1082,26 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
dev = alloc_etherdev(sizeof(struct r6040_private)); dev = alloc_etherdev(sizeof(struct r6040_private));
if (!dev) { if (!dev) {
printk(KERN_ERR "Failed to allocate etherdev\n"); printk(KERN_ERR DRV_NAME "Failed to allocate etherdev\n");
return -ENOMEM; err = -ENOMEM;
goto err_out;
} }
SET_NETDEV_DEV(dev, &pdev->dev); SET_NETDEV_DEV(dev, &pdev->dev);
lp = netdev_priv(dev); lp = netdev_priv(dev);
if (pci_request_regions(pdev, DRV_NAME)) { err = pci_request_regions(pdev, DRV_NAME);
if (err) {
printk(KERN_ERR DRV_NAME ": Failed to request PCI regions\n"); printk(KERN_ERR DRV_NAME ": Failed to request PCI regions\n");
err = -ENODEV; goto err_out_free_dev;
goto err_out_disable;
} }
ioaddr = pci_iomap(pdev, bar, io_size); ioaddr = pci_iomap(pdev, bar, io_size);
if (!ioaddr) { if (!ioaddr) {
printk(KERN_ERR "ioremap failed for device %s\n", printk(KERN_ERR "ioremap failed for device %s\n",
pci_name(pdev)); pci_name(pdev));
return -EIO; err = -EIO;
goto err_out_free_res;
} }
/* Init system & device */ /* Init system & device */
...@@ -1147,17 +1153,17 @@ static int __devinit r6040_init_one(struct pci_dev *pdev, ...@@ -1147,17 +1153,17 @@ static int __devinit r6040_init_one(struct pci_dev *pdev,
err = register_netdev(dev); err = register_netdev(dev);
if (err) { if (err) {
printk(KERN_ERR DRV_NAME ": Failed to register net device\n"); printk(KERN_ERR DRV_NAME ": Failed to register net device\n");
goto err_out_res; goto err_out_unmap;
} }
return 0; return 0;
err_out_res: err_out_unmap:
pci_iounmap(pdev, ioaddr);
err_out_free_res:
pci_release_regions(pdev); pci_release_regions(pdev);
err_out_disable: err_out_free_dev:
pci_disable_device(pdev);
pci_set_drvdata(pdev, NULL);
free_netdev(dev); free_netdev(dev);
err_out:
return err; return err;
} }
......
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