Skip to content

Commit

Permalink
staging: et131x: Further tidy up of 131x_pci_setup()
Browse files Browse the repository at this point in the history
* Removed unused bool variable.
* Eliminated mid-function returns, used gotos instead

Signed-off-by: Mark Einon <mark.einon@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Mark Einon authored and Greg Kroah-Hartman committed Aug 29, 2011
1 parent 7f9615e commit 6d15059
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
58 changes: 27 additions & 31 deletions drivers/staging/et131x/et131x_initpci.c
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,6 @@ static struct et131x_adapter *et131x_adapter_init(struct net_device *netdev,

struct et131x_adapter *adapter;

/* Setup the fundamental net_device and private adapter structure
* elements */
SET_NETDEV_DEV(netdev, &pdev->dev);

/* Allocate private adapter struct and copy in relevant information */
adapter = netdev_priv(netdev);
adapter->pdev = pci_dev_get(pdev);
Expand Down Expand Up @@ -579,33 +575,29 @@ static struct et131x_adapter *et131x_adapter_init(struct net_device *netdev,
static int __devinit et131x_pci_setup(struct pci_dev *pdev,
const struct pci_device_id *ent)
{
int result = -EBUSY;
int result;
int pm_cap;
bool pci_using_dac;
struct net_device *netdev;
struct et131x_adapter *adapter;

/* Enable the device via the PCI subsystem */
if (pci_enable_device(pdev) != 0) {
dev_err(&pdev->dev,
"pci_enable_device() failed\n");
return -EIO;
result = pci_enable_device(pdev);
if (result) {
dev_err(&pdev->dev, "pci_enable_device() failed\n");
goto err_out;
}

/* Perform some basic PCI checks */
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");
goto err_disable;
}

if (pci_request_regions(pdev, DRIVER_NAME)) {
dev_err(&pdev->dev,
"Can't get PCI resources\n");
dev_err(&pdev->dev, "Can't get PCI resources\n");
goto err_disable;
}

/* Enable PCI bus mastering */
pci_set_master(pdev);

/* Query PCI for Power Mgmt Capabilities
Expand All @@ -614,7 +606,7 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
* needed?
*/
pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
if (pm_cap == 0) {
if (!pm_cap) {
dev_err(&pdev->dev,
"Cannot find Power Management capabilities\n");
result = -EIO;
Expand All @@ -623,37 +615,42 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,

/* Check the DMA addressing support of this device */
if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
pci_using_dac = true;

result = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
if (result != 0) {
if (result) {
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;
}
} else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
pci_using_dac = false;
result = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
if (result) {
dev_err(&pdev->dev,
"Unable to obtain 32 bit DMA for consistent allocations\n");
goto err_release_res;
}
} else {
dev_err(&pdev->dev,
"No usable DMA addressing method\n");
dev_err(&pdev->dev, "No usable DMA addressing method\n");
result = -EIO;
goto err_release_res;
}

/* Allocate netdev and private adapter structs */
netdev = et131x_device_alloc();
if (netdev == NULL) {
if (!netdev) {
dev_err(&pdev->dev, "Couldn't alloc netdev struct\n");
result = -ENOMEM;
goto err_release_res;
}

SET_NETDEV_DEV(netdev, &pdev->dev);

adapter = et131x_adapter_init(netdev, pdev);
/* Initialise the PCI setup for the device */
et131x_pci_init(adapter, pdev);

/* Map the bus-relative registers to system virtual memory */
adapter->regs = pci_ioremap_bar(pdev, 0);
if (adapter->regs == NULL) {
if (!adapter->regs) {
dev_err(&pdev->dev, "Cannot map device registers\n");
result = -ENOMEM;
goto err_free_dev;
Expand All @@ -670,17 +667,15 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,

/* Allocate DMA memory */
result = et131x_adapter_memory_alloc(adapter);
if (result != 0) {
if (result) {
dev_err(&pdev->dev, "Could not alloc adapater memory (DMA)\n");
goto err_iounmap;
}

/* Init send data structures */
et131x_init_send(adapter);

/*
* Set up the task structure for the ISR's deferred handler
*/
/* Set up the task structure for the ISR's deferred handler */
INIT_WORK(&adapter->task, et131x_isr_handler);

/* Copy address into the net_device struct */
Expand All @@ -699,8 +694,7 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
/* Initialize link state */
netif_carrier_off(adapter->netdev);

/* Initialize variable for counting how long we do not have
link status */
/* Init variable for counting how long we do not have link status */
adapter->boot_coma = 0;

/* We can enable interrupts now
Expand All @@ -723,6 +717,7 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
*/
pci_set_drvdata(pdev, netdev);
pci_save_state(adapter->pdev);

return result;

err_mem_free:
Expand All @@ -736,6 +731,7 @@ static int __devinit et131x_pci_setup(struct pci_dev *pdev,
pci_release_regions(pdev);
err_disable:
pci_disable_device(pdev);
err_out:
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/et131x/et131x_netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ struct net_device *et131x_device_alloc(void)
/* Alloc net_device and adapter structs */
netdev = alloc_etherdev(sizeof(struct et131x_adapter));

if (netdev == NULL) {
if (!netdev) {
printk(KERN_ERR "et131x: Alloc of net_device struct failed\n");
return NULL;
}
Expand Down

0 comments on commit 6d15059

Please sign in to comment.