All of lore.kernel.org
 help / color / mirror / Atom feed
From: Francois Romieu <romieu@fr.zoreil.com>
To: netdev@vger.kernel.org
Cc: "David Miller" <davem@davemloft.net>,
	Grant Grundler <grundler@parisc-linux.org>
Subject: [PATCH net-next #2 24/39] xircom_cb: fix device probe error path.
Date: Fri,  6 Apr 2012 12:06:38 +0200	[thread overview]
Message-ID: <271dcd170006b9d55eb555b2e79e22c1fa86e0a0.1333704409.git.romieu@fr.zoreil.com> (raw)
In-Reply-To: <1333704408.git.romieu@fr.zoreil.com>

- unbalanced pci_disable_device
- PCI ressources were not released
- mismatching pci_alloc_.../kfree pairs are replaced by DMA alloc helpers.

Signed-off-by: Francois Romieu <romieu@fr.zoreil.com>
Cc: Grant Grundler <grundler@parisc-linux.org>
---
 drivers/net/ethernet/dec/tulip/xircom_cb.c |   53 ++++++++++++++++++----------
 1 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/dec/tulip/xircom_cb.c b/drivers/net/ethernet/dec/tulip/xircom_cb.c
index fdb329f..cbcc6d6 100644
--- a/drivers/net/ethernet/dec/tulip/xircom_cb.c
+++ b/drivers/net/ethernet/dec/tulip/xircom_cb.c
@@ -192,15 +192,18 @@ static const struct net_device_ops netdev_ops = {
  */
 static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
+	struct device *d = &pdev->dev;
 	struct net_device *dev = NULL;
 	struct xircom_private *private;
 	unsigned long flags;
 	unsigned short tmp16;
+	int rc;
 
 	/* First do the PCI initialisation */
 
-	if (pci_enable_device(pdev))
-		return -ENODEV;
+	rc = pci_enable_device(pdev);
+	if (rc < 0)
+		goto out;
 
 	/* disable all powermanagement */
 	pci_write_config_dword(pdev, PCI_POWERMGMT, 0x0000);
@@ -211,11 +214,13 @@ static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_
 	pci_read_config_word (pdev,PCI_STATUS, &tmp16);
 	pci_write_config_word (pdev, PCI_STATUS,tmp16);
 
-	if (!request_region(pci_resource_start(pdev, 0), 128, "xircom_cb")) {
+	rc = pci_request_regions(pdev, "xircom_cb");
+	if (rc < 0) {
 		pr_err("%s: failed to allocate io-region\n", __func__);
-		return -ENODEV;
+		goto err_disable;
 	}
 
+	rc = -ENOMEM;
 	/*
 	   Before changing the hardware, allocate the memory.
 	   This way, we can fail gracefully if not enough memory
@@ -223,17 +228,21 @@ static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_
 	 */
 	dev = alloc_etherdev(sizeof(struct xircom_private));
 	if (!dev)
-		goto device_fail;
+		goto err_release;
 
 	private = netdev_priv(dev);
 
 	/* Allocate the send/receive buffers */
-	private->rx_buffer = pci_alloc_consistent(pdev,8192,&private->rx_dma_handle);
+	private->rx_buffer = dma_alloc_coherent(d, 8192,
+						&private->rx_dma_handle,
+						GFP_KERNEL);
 	if (private->rx_buffer == NULL) {
 		pr_err("%s: no memory for rx buffer\n", __func__);
 		goto rx_buf_fail;
 	}
-	private->tx_buffer = pci_alloc_consistent(pdev,8192,&private->tx_dma_handle);
+	private->tx_buffer = dma_alloc_coherent(d, 8192,
+						&private->tx_dma_handle,
+						GFP_KERNEL);
 	if (private->tx_buffer == NULL) {
 		pr_err("%s: no memory for tx buffer\n", __func__);
 		goto tx_buf_fail;
@@ -256,7 +265,8 @@ static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_
 	dev->netdev_ops = &netdev_ops;
 	pci_set_drvdata(pdev, dev);
 
-	if (register_netdev(dev)) {
+	rc = register_netdev(dev);
+	if (rc < 0) {
 		pr_err("%s: netdevice registration failed\n", __func__);
 		goto reg_fail;
 	}
@@ -273,17 +283,21 @@ static int __devinit xircom_probe(struct pci_dev *pdev, const struct pci_device_
 	spin_unlock_irqrestore(&private->lock,flags);
 
 	trigger_receive(private);
-
-	return 0;
+out:
+	return rc;
 
 reg_fail:
-	kfree(private->tx_buffer);
+	pci_set_drvdata(pdev, NULL);
+	dma_free_coherent(d, 8192, private->tx_buffer, private->tx_dma_handle);
 tx_buf_fail:
-	kfree(private->rx_buffer);
+	dma_free_coherent(d, 8192, private->rx_buffer, private->rx_dma_handle);
 rx_buf_fail:
 	free_netdev(dev);
-device_fail:
-	return -ENODEV;
+err_release:
+	pci_release_regions(pdev);
+err_disable:
+	pci_disable_device(pdev);
+	goto out;
 }
 
 
@@ -297,14 +311,15 @@ static void __devexit xircom_remove(struct pci_dev *pdev)
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
 	struct xircom_private *card = netdev_priv(dev);
+	struct device *d = &pdev->dev;
 
-	pci_free_consistent(pdev,8192,card->rx_buffer,card->rx_dma_handle);
-	pci_free_consistent(pdev,8192,card->tx_buffer,card->tx_dma_handle);
-
-	release_region(dev->base_addr, 128);
 	unregister_netdev(dev);
-	free_netdev(dev);
 	pci_set_drvdata(pdev, NULL);
+	dma_free_coherent(d, 8192, card->tx_buffer, card->tx_dma_handle);
+	dma_free_coherent(d, 8192, card->rx_buffer, card->rx_dma_handle);
+	free_netdev(dev);
+	pci_release_regions(pdev);
+	pci_disable_device(pdev);
 }
 
 static irqreturn_t xircom_interrupt(int irq, void *dev_instance)
-- 
1.7.7.6

  parent reply	other threads:[~2012-04-06 10:10 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-06 10:06 [PATCH net-next #2 00/39] net_device.{base_addr, irq} removal update Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 01/39] sungem: stop using net_device.{base_addr, irq} Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 02/39] tehuti: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 03/39] forcedeth: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 04/39] atl1c: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 05/39] via-rhine: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 06/39] hamachi: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 07/39] via-velocity: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 08/39] sundance: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 09/39] vxge: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 10/39] fealnx: " Francois Romieu
2012-04-06 10:21   ` David Miller
2012-04-06 10:06 ` [PATCH net-next #2 11/39] atl1e: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 12/39] s2io: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 13/39] 8139cp: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 14/39] yellowfin: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 15/39] starfire: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 16/39] starfire: remove deprecated options Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 17/39] bnx2: stop using net_device.{base_addr, irq} Francois Romieu
2012-04-06 15:07   ` Michael Chan
2012-04-06 10:06 ` [PATCH net-next #2 18/39] winbond840: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 19/39] sc92031: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 20/39] sis190: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 21/39] tulip_core: " Francois Romieu
2012-04-06 16:57   ` Grant Grundler
2012-04-06 10:06 ` [PATCH net-next #2 22/39] sunhme: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 23/39] uli526x: fix regions leak in driver probe error path Francois Romieu
2012-04-06 17:15   ` Grant Grundler
2012-04-06 10:06 ` Francois Romieu [this message]
2012-04-06 16:56   ` [PATCH net-next #2 24/39] xircom_cb: fix device " Grant Grundler
2012-04-06 10:06 ` [PATCH net-next #2 25/39] xircom_cb: stop using net_device.{base_addr, irq} and convert to __iomem Francois Romieu
2012-04-06 16:42   ` Grant Grundler
2012-04-06 10:06 ` [PATCH net-next #2 26/39] de2104x: stop using net_device.{base_addr, irq} Francois Romieu
2012-04-06 16:54   ` Grant Grundler
2012-04-06 10:06 ` [PATCH net-next #2 27/39] smsc9420: " Francois Romieu
2012-04-06 10:23   ` David Miller
2012-04-06 10:06 ` [PATCH net-next #2 28/39] natsemi: " Francois Romieu
2012-04-10 22:53   ` Tim Hockin
2012-04-10 23:30     ` David Miller
2012-04-10 23:39       ` Tim Hockin
2012-04-11  0:02         ` David Miller
2012-04-11  0:19           ` Tim Hockin
2012-04-11  0:42             ` David Miller
2012-04-11  0:59               ` Tim Hockin
2012-04-11  1:11                 ` David Miller
2012-04-11  1:16                   ` Tim Hockin
2012-04-06 10:06 ` [PATCH net-next #2 29/39] 8139too: dev->{base_addr, irq} removal Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 30/39] dl2k: stop using net_device.{base_addr, irq} and convert to __iomem Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 31/39] uli526x: " Francois Romieu
2012-04-06 16:53   ` Grant Grundler
2012-04-06 10:06 ` [PATCH net-next #2 32/39] epic100: " Francois Romieu
2012-04-06 10:25   ` David Miller
2012-04-06 10:06 ` [PATCH net-next #2 33/39] dmfe: " Francois Romieu
2012-04-06 16:31   ` Grant Grundler
2012-04-06 10:06 ` [PATCH net-next #2 34/39] sis900: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 35/39] myri10ge: stop using net_device.{base_addr, irq} Francois Romieu
2012-04-06 11:48   ` Andrew Gallatin
2012-04-06 10:06 ` [PATCH net-next #2 36/39] rrunner: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 37/39] ipw2200: " Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 38/39] ipw2100: stop using net_device.base_addr Francois Romieu
2012-04-06 10:06 ` [PATCH net-next #2 39/39] ipw2100: remove useless tests in the PCI device remove path Francois Romieu
2012-04-06 10:26 ` [PATCH net-next #2 00/39] net_device.{base_addr, irq} removal update David Miller
2012-04-06 17:17   ` Grant Grundler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=271dcd170006b9d55eb555b2e79e22c1fa86e0a0.1333704409.git.romieu@fr.zoreil.com \
    --to=romieu@fr.zoreil.com \
    --cc=davem@davemloft.net \
    --cc=grundler@parisc-linux.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.