linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zheyu Ma <zheyuma97@gmail.com>
To: stas.yakovlev@gmail.com, kvalo@kernel.org, davem@davemloft.net,
	kuba@kernel.org, pabeni@redhat.com
Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, Zheyu Ma <zheyuma97@gmail.com>
Subject: [PATCH] wireless: ipw2x00: Refine the error handling of ipw2100_pci_init_one()
Date: Sat,  9 Apr 2022 14:24:49 +0800	[thread overview]
Message-ID: <20220409062449.3752252-1-zheyuma97@gmail.com> (raw)

The driver should release resources in reverse order, i.e., the
resources requested first should be released last, and the driver
should adjust the order of error handling code by this rule.

Signed-off-by: Zheyu Ma <zheyuma97@gmail.com>
---
 drivers/net/wireless/intel/ipw2x00/ipw2100.c | 34 +++++++++-----------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/drivers/net/wireless/intel/ipw2x00/ipw2100.c b/drivers/net/wireless/intel/ipw2x00/ipw2100.c
index 2ace2b27ecad..b10d10660eb8 100644
--- a/drivers/net/wireless/intel/ipw2x00/ipw2100.c
+++ b/drivers/net/wireless/intel/ipw2x00/ipw2100.c
@@ -6166,7 +6166,7 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
 		printk(KERN_WARNING DRV_NAME
 		       "Error calling ioremap.\n");
 		err = -EIO;
-		goto fail;
+		goto out;
 	}
 
 	/* allocate and initialize our net_device */
@@ -6175,36 +6175,33 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
 		printk(KERN_WARNING DRV_NAME
 		       "Error calling ipw2100_alloc_device.\n");
 		err = -ENOMEM;
-		goto fail;
+		goto fail_iounmap;
 	}
 
+	priv = libipw_priv(dev);
+	pci_set_master(pci_dev);
+	pci_set_drvdata(pci_dev, priv);
+
 	/* set up PCI mappings for device */
 	err = pci_enable_device(pci_dev);
 	if (err) {
 		printk(KERN_WARNING DRV_NAME
 		       "Error calling pci_enable_device.\n");
-		return err;
+		goto fail_dev;
 	}
 
-	priv = libipw_priv(dev);
-
-	pci_set_master(pci_dev);
-	pci_set_drvdata(pci_dev, priv);
-
 	err = dma_set_mask(&pci_dev->dev, DMA_BIT_MASK(32));
 	if (err) {
 		printk(KERN_WARNING DRV_NAME
 		       "Error calling pci_set_dma_mask.\n");
-		pci_disable_device(pci_dev);
-		return err;
+		goto fail_disable;
 	}
 
 	err = pci_request_regions(pci_dev, DRV_NAME);
 	if (err) {
 		printk(KERN_WARNING DRV_NAME
 		       "Error calling pci_request_regions.\n");
-		pci_disable_device(pci_dev);
-		return err;
+		goto fail_disable;
 	}
 
 	/* We disable the RETRY_TIMEOUT register (0x41) to keep
@@ -6306,9 +6303,13 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
 out:
 	return err;
 
-      fail_unlock:
+fail_unlock:
 	mutex_unlock(&priv->action_mutex);
-      fail:
+fail:
+	pci_release_regions(pci_dev);
+fail_disable:
+	pci_disable_device(pci_dev);
+fail_dev:
 	if (dev) {
 		if (registered >= 2)
 			unregister_netdev(dev);
@@ -6334,11 +6335,8 @@ static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
 
 		free_libipw(dev, 0);
 	}
-
+fail_iounmap:
 	pci_iounmap(pci_dev, ioaddr);
-
-	pci_release_regions(pci_dev);
-	pci_disable_device(pci_dev);
 	goto out;
 }
 
-- 
2.25.1


             reply	other threads:[~2022-04-09  6:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-09  6:24 Zheyu Ma [this message]
2022-04-12 13:55 ` [PATCH] wireless: ipw2x00: Refine the error handling of ipw2100_pci_init_one() Kalle Valo
2022-04-13 18:39 ` Stanislav Yakovlev
2022-04-18  3:04   ` Zheyu Ma
2022-04-22 19:25     ` Stanislav Yakovlev
2022-05-20  3:46       ` Zheyu Ma

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=20220409062449.3752252-1-zheyuma97@gmail.com \
    --to=zheyuma97@gmail.com \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=stas.yakovlev@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).