Commit fa9f0a65 authored by Francois Romieu's avatar Francois Romieu Committed by Greg Kroah-Hartman

et131x: fix error paths in et131x_pci_setup.

Wrong status code and unbalanced phy_connect.
Signed-off-by: default avatarFrancois Romieu <romieu@fr.zoreil.com>
Acked-by: default avatarMark Einon <mark.einon@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 834d0ee3
...@@ -4402,6 +4402,7 @@ static void __devexit et131x_pci_remove(struct pci_dev *pdev) ...@@ -4402,6 +4402,7 @@ static void __devexit et131x_pci_remove(struct pci_dev *pdev)
struct et131x_adapter *adapter = netdev_priv(netdev); struct et131x_adapter *adapter = netdev_priv(netdev);
unregister_netdev(netdev); unregister_netdev(netdev);
phy_disconnect(adapter->phydev);
mdiobus_unregister(adapter->mii_bus); mdiobus_unregister(adapter->mii_bus);
kfree(adapter->mii_bus->irq); kfree(adapter->mii_bus->irq);
mdiobus_free(adapter->mii_bus); mdiobus_free(adapter->mii_bus);
...@@ -5250,40 +5251,6 @@ static const struct net_device_ops et131x_netdev_ops = { ...@@ -5250,40 +5251,6 @@ static const struct net_device_ops et131x_netdev_ops = {
.ndo_do_ioctl = et131x_ioctl, .ndo_do_ioctl = et131x_ioctl,
}; };
/**
* et131x_device_alloc
*
* Returns pointer to the allocated and initialized net_device struct for
* this device.
*
* Create instances of net_device and wl_private for the new adapter and
* register the device's entry points in the net_device structure.
*/
struct net_device *et131x_device_alloc(void)
{
struct net_device *netdev;
/* Alloc net_device and adapter structs */
netdev = alloc_etherdev(sizeof(struct et131x_adapter));
if (!netdev) {
printk(KERN_ERR "et131x: Alloc of net_device struct failed\n");
return NULL;
}
/*
* Setup the function registration table (and other data) for a
* net_device
*/
netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
netdev->netdev_ops = &et131x_netdev_ops;
/* Poll? */
/* netdev->poll = &et131x_poll; */
/* netdev->poll_controller = &et131x_poll_controller; */
return netdev;
}
/** /**
* et131x_pci_setup - Perform device initialization * et131x_pci_setup - Perform device initialization
* @pdev: a pointer to the device's pci_dev structure * @pdev: a pointer to the device's pci_dev structure
...@@ -5299,24 +5266,26 @@ struct net_device *et131x_device_alloc(void) ...@@ -5299,24 +5266,26 @@ struct net_device *et131x_device_alloc(void)
static int __devinit et131x_pci_setup(struct pci_dev *pdev, static int __devinit et131x_pci_setup(struct pci_dev *pdev,
const struct pci_device_id *ent) const struct pci_device_id *ent)
{ {
int result;
struct net_device *netdev; struct net_device *netdev;
struct et131x_adapter *adapter; struct et131x_adapter *adapter;
int rc;
int ii; int ii;
result = pci_enable_device(pdev); rc = pci_enable_device(pdev);
if (result) { if (rc < 0) {
dev_err(&pdev->dev, "pci_enable_device() failed\n"); dev_err(&pdev->dev, "pci_enable_device() failed\n");
goto err_out; goto out;
} }
/* Perform some basic PCI checks */ /* Perform some basic PCI checks */
if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
dev_err(&pdev->dev, "Can't find PCI device's base address\n"); dev_err(&pdev->dev, "Can't find PCI device's base address\n");
rc = -ENODEV;
goto err_disable; goto err_disable;
} }
if (pci_request_regions(pdev, DRIVER_NAME)) { rc = pci_request_regions(pdev, DRIVER_NAME);
if (rc < 0) {
dev_err(&pdev->dev, "Can't get PCI resources\n"); dev_err(&pdev->dev, "Can't get PCI resources\n");
goto err_disable; goto err_disable;
} }
...@@ -5325,46 +5294,50 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev, ...@@ -5325,46 +5294,50 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
/* Check the DMA addressing support of this device */ /* Check the DMA addressing support of this device */
if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) { if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
result = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64)); rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64));
if (result) { if (rc < 0) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Unable to obtain 64 bit DMA for consistent allocations\n"); "Unable to obtain 64 bit DMA for consistent allocations\n");
goto err_release_res; goto err_release_res;
} }
} else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) { } else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
result = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); rc = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
if (result) { if (rc < 0) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"Unable to obtain 32 bit DMA for consistent allocations\n"); "Unable to obtain 32 bit DMA for consistent allocations\n");
goto err_release_res; goto err_release_res;
} }
} else { } else {
dev_err(&pdev->dev, "No usable DMA addressing method\n"); dev_err(&pdev->dev, "No usable DMA addressing method\n");
result = -EIO; rc = -EIO;
goto err_release_res; goto err_release_res;
} }
/* Allocate netdev and private adapter structs */ /* Allocate netdev and private adapter structs */
netdev = et131x_device_alloc(); netdev = alloc_etherdev(sizeof(struct et131x_adapter));
if (!netdev) { if (!netdev) {
dev_err(&pdev->dev, "Couldn't alloc netdev struct\n"); dev_err(&pdev->dev, "Couldn't alloc netdev struct\n");
result = -ENOMEM; rc = -ENOMEM;
goto err_release_res; goto err_release_res;
} }
netdev->watchdog_timeo = ET131X_TX_TIMEOUT;
netdev->netdev_ops = &et131x_netdev_ops;
SET_NETDEV_DEV(netdev, &pdev->dev); SET_NETDEV_DEV(netdev, &pdev->dev);
et131x_set_ethtool_ops(netdev); et131x_set_ethtool_ops(netdev);
adapter = et131x_adapter_init(netdev, pdev); adapter = et131x_adapter_init(netdev, pdev);
/* Initialise the PCI setup for the device */ rc = et131x_pci_init(adapter, pdev);
et131x_pci_init(adapter, pdev); if (rc < 0)
goto err_free_dev;
/* Map the bus-relative registers to system virtual memory */ /* Map the bus-relative registers to system virtual memory */
adapter->regs = pci_ioremap_bar(pdev, 0); adapter->regs = pci_ioremap_bar(pdev, 0);
if (!adapter->regs) { if (!adapter->regs) {
dev_err(&pdev->dev, "Cannot map device registers\n"); dev_err(&pdev->dev, "Cannot map device registers\n");
result = -ENOMEM; rc = -ENOMEM;
goto err_free_dev; goto err_free_dev;
} }
...@@ -5378,8 +5351,8 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev, ...@@ -5378,8 +5351,8 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
et131x_disable_interrupts(adapter); et131x_disable_interrupts(adapter);
/* Allocate DMA memory */ /* Allocate DMA memory */
result = et131x_adapter_memory_alloc(adapter); rc = et131x_adapter_memory_alloc(adapter);
if (result) { if (rc < 0) {
dev_err(&pdev->dev, "Could not alloc adapater memory (DMA)\n"); dev_err(&pdev->dev, "Could not alloc adapater memory (DMA)\n");
goto err_iounmap; goto err_iounmap;
} }
...@@ -5397,6 +5370,8 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev, ...@@ -5397,6 +5370,8 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
adapter->boot_coma = 0; adapter->boot_coma = 0;
et1310_disable_phy_coma(adapter); et1310_disable_phy_coma(adapter);
rc = -ENOMEM;
/* Setup the mii_bus struct */ /* Setup the mii_bus struct */
adapter->mii_bus = mdiobus_alloc(); adapter->mii_bus = mdiobus_alloc();
if (!adapter->mii_bus) { if (!adapter->mii_bus) {
...@@ -5420,13 +5395,14 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev, ...@@ -5420,13 +5395,14 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
for (ii = 0; ii < PHY_MAX_ADDR; ii++) for (ii = 0; ii < PHY_MAX_ADDR; ii++)
adapter->mii_bus->irq[ii] = PHY_POLL; adapter->mii_bus->irq[ii] = PHY_POLL;
if (mdiobus_register(adapter->mii_bus)) { rc = mdiobus_register(adapter->mii_bus);
if (rc < 0) {
dev_err(&pdev->dev, "failed to register MII bus\n"); dev_err(&pdev->dev, "failed to register MII bus\n");
mdiobus_free(adapter->mii_bus);
goto err_mdio_free_irq; goto err_mdio_free_irq;
} }
if (et131x_mii_probe(netdev)) { rc = et131x_mii_probe(netdev);
if (rc < 0) {
dev_err(&pdev->dev, "failed to probe MII bus\n"); dev_err(&pdev->dev, "failed to probe MII bus\n");
goto err_mdio_unregister; goto err_mdio_unregister;
} }
...@@ -5442,10 +5418,10 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev, ...@@ -5442,10 +5418,10 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
*/ */
/* Register the net_device struct with the Linux network layer */ /* Register the net_device struct with the Linux network layer */
result = register_netdev(netdev); rc = register_netdev(netdev);
if (result != 0) { if (rc < 0) {
dev_err(&pdev->dev, "register_netdev() failed\n"); dev_err(&pdev->dev, "register_netdev() failed\n");
goto err_mdio_unregister; goto err_phy_disconnect;
} }
/* Register the net_device struct with the PCI subsystem. Save a copy /* Register the net_device struct with the PCI subsystem. Save a copy
...@@ -5454,9 +5430,11 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev, ...@@ -5454,9 +5430,11 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
*/ */
pci_set_drvdata(pdev, netdev); pci_set_drvdata(pdev, netdev);
pci_save_state(adapter->pdev); pci_save_state(adapter->pdev);
out:
return rc;
return result; err_phy_disconnect:
phy_disconnect(adapter->phydev);
err_mdio_unregister: err_mdio_unregister:
mdiobus_unregister(adapter->mii_bus); mdiobus_unregister(adapter->mii_bus);
err_mdio_free_irq: err_mdio_free_irq:
...@@ -5474,8 +5452,7 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev, ...@@ -5474,8 +5452,7 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
pci_release_regions(pdev); pci_release_regions(pdev);
err_disable: err_disable:
pci_disable_device(pdev); pci_disable_device(pdev);
err_out: goto out;
return result;
} }
static DEFINE_PCI_DEVICE_TABLE(et131x_pci_table) = { static DEFINE_PCI_DEVICE_TABLE(et131x_pci_table) = {
......
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