[PATCH 15/18] staging: rtl8187e: call disable_pci_device() if pci_probe() failed

From: Kulikov Vasiliy
Date: Fri Aug 06 2010 - 15:53:31 EST


Driver should call disable_pci_device() if it returns from pci_probe()
with error. Also it must not be called if request_*_region() fails as
it means that somebody uses device resources and rules the device.

Signed-off-by: Kulikov Vasiliy <segooon@xxxxxxxxx>
---
drivers/staging/rtl8192e/r8192E_core.c | 16 ++++++++++++----
1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8192e/r8192E_core.c b/drivers/staging/rtl8192e/r8192E_core.c
index 17a806f..7ea2959 100644
--- a/drivers/staging/rtl8192e/r8192E_core.c
+++ b/drivers/staging/rtl8192e/r8192E_core.c
@@ -6325,6 +6325,8 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
struct net_device *dev = NULL;
struct r8192_priv *priv= NULL;
u8 unit = 0;
+ int ret = -ENODEV;
+ int pci_dev_busy = 0;

#ifdef CONFIG_RTL8192_IO_MAP
unsigned long pio_start, pio_len, pio_flags;
@@ -6344,8 +6346,10 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
pci_set_dma_mask(pdev, 0xffffff00ULL);
pci_set_consistent_dma_mask(pdev,0xffffff00ULL);
dev = alloc_ieee80211(sizeof(struct r8192_priv));
- if (!dev)
- return -ENOMEM;
+ if (!dev) {
+ ret = -ENOMEM;
+ goto fail_free;
+ }

pci_set_drvdata(pdev, dev);
SET_NETDEV_DEV(dev, &pdev->dev);
@@ -6373,6 +6377,7 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
//DMESG("IO space @ 0x%08lx", pio_start );
if( ! request_region( pio_start, pio_len, RTL819xE_MODULE_NAME ) ){
RT_TRACE(COMP_ERR,"request_region failed!");
+ pci_dev_busy = 1;
goto fail;
}

@@ -6393,6 +6398,7 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
//DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
if( ! request_mem_region(pmem_start, pmem_len, RTL819xE_MODULE_NAME)) {
RT_TRACE(COMP_ERR,"request_mem_region failed!");
+ pci_dev_busy = 1;
goto fail;
}

@@ -6494,11 +6500,13 @@ fail:
free_ieee80211(dev);
}

- pci_disable_device(pdev);
+fail_free:
+ if (!pci_dev_busy)
+ pci_disable_device(pdev);

DMESG("wlan driver load failed\n");
pci_set_drvdata(pdev, NULL);
- return -ENODEV;
+ return ret;

}

--
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/