mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Simon Sandström" <simon@nikanor.nu>
To: gregkh@linuxfoundation.org
Cc: dan.carpenter@oracle.com, jeremy@azazel.net,
	devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
	"Simon Sandström" <simon@nikanor.nu>
Subject: [PATCH] staging: kpc2000: simplify error handling in kp2000_pcie_probe
Date: Wed, 19 Jun 2019 08:36:07 +0200	[thread overview]
Message-ID: <20190619063607.20722-1-simon@nikanor.nu> (raw)

We can get rid of a few iounmaps in the middle of the function by
re-ordering the error handling labels and adding two new labels.

Signed-off-by: Simon Sandström <simon@nikanor.nu>
---

This change has not been tested besides by compiling. It might be good
took take an extra look to make sure that I got everything right.

Also, this change was proposed by Dan Carpenter. Should I add anything
in the commit message to show this?

- Simon

 drivers/staging/kpc2000/kpc2000/core.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/kpc2000/kpc2000/core.c b/drivers/staging/kpc2000/kpc2000/core.c
index 610ea549d240..cb05cca687e1 100644
--- a/drivers/staging/kpc2000/kpc2000/core.c
+++ b/drivers/staging/kpc2000/kpc2000/core.c
@@ -351,12 +351,11 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 
 	err = pci_request_region(pcard->pdev, REG_BAR, KP_DRIVER_NAME_KP2000);
 	if (err) {
-		iounmap(pcard->regs_bar_base);
 		dev_err(&pcard->pdev->dev,
 			"probe: failed to acquire PCI region (%d)\n",
 			err);
 		err = -ENODEV;
-		goto err_disable_device;
+		goto err_unmap_regs;
 	}
 
 	pcard->regs_base_resource.start = reg_bar_phys_addr;
@@ -374,7 +373,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 		dev_err(&pcard->pdev->dev,
 			"probe: DMA_BAR could not remap memory to virtual space\n");
 		err = -ENODEV;
-		goto err_unmap_regs;
+		goto err_release_regs;
 	}
 	dev_dbg(&pcard->pdev->dev,
 		"probe: DMA_BAR virt hardware address start [%p]\n",
@@ -384,11 +383,10 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 
 	err = pci_request_region(pcard->pdev, DMA_BAR, "kp2000_pcie");
 	if (err) {
-		iounmap(pcard->dma_bar_base);
 		dev_err(&pcard->pdev->dev,
 			"probe: failed to acquire PCI region (%d)\n", err);
 		err = -ENODEV;
-		goto err_unmap_regs;
+		goto err_unmap_dma;
 	}
 
 	pcard->dma_base_resource.start = dma_bar_phys_addr;
@@ -400,7 +398,7 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	pcard->sysinfo_regs_base = pcard->regs_bar_base;
 	err = read_system_regs(pcard);
 	if (err)
-		goto err_unmap_dma;
+		goto err_release_dma;
 
 	// Disable all "user" interrupts because they're not used yet.
 	writeq(0xFFFFFFFFFFFFFFFF,
@@ -438,14 +436,14 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	if (err) {
 		dev_err(&pcard->pdev->dev,
 			"CANNOT use DMA mask %0llx\n", DMA_BIT_MASK(64));
-		goto err_unmap_dma;
+		goto err_release_dma;
 	}
 	dev_dbg(&pcard->pdev->dev,
 		"Using DMA mask %0llx\n", dma_get_mask(PCARD_TO_DEV(pcard)));
 
 	err = pci_enable_msi(pcard->pdev);
 	if (err < 0)
-		goto err_unmap_dma;
+		goto err_release_dma;
 
 	rv = request_irq(pcard->pdev->irq, kp2000_irq_handler, IRQF_SHARED,
 			 pcard->name, pcard);
@@ -478,14 +476,14 @@ static int kp2000_pcie_probe(struct pci_dev *pdev,
 	free_irq(pcard->pdev->irq, pcard);
 err_disable_msi:
 	pci_disable_msi(pcard->pdev);
+err_release_dma:
+	pci_release_region(pdev, DMA_BAR);
 err_unmap_dma:
 	iounmap(pcard->dma_bar_base);
-	pci_release_region(pdev, DMA_BAR);
-	pcard->dma_bar_base = NULL;
+err_release_regs:
+	pci_release_region(pdev, REG_BAR);
 err_unmap_regs:
 	iounmap(pcard->regs_bar_base);
-	pci_release_region(pdev, REG_BAR);
-	pcard->regs_bar_base = NULL;
 err_disable_device:
 	pci_disable_device(pcard->pdev);
 err_remove_ida:
-- 
2.20.1


             reply	other threads:[~2019-06-19  6:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-19  6:36 Simon Sandström [this message]
2019-06-19  6:53 ` Dan Carpenter

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=20190619063607.20722-1-simon@nikanor.nu \
    --to=simon@nikanor.nu \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jeremy@azazel.net \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®