public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: SF Markus Elfring <elfring@users.sourceforge.net>
To: alsa-devel@alsa-project.org, Arnd Bergmann <arnd@arndb.de>,
	Bhumika Goyal <bhumirks@gmail.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 2/2] ALSA: mixart: Use common error handling code in snd_mixart_probe()
Date: Thu, 16 Nov 2017 16:36:12 +0100	[thread overview]
Message-ID: <d4bad61d-fa9d-283f-1cce-b5c7a7efa640@users.sourceforge.net> (raw)
In-Reply-To: <6f8ce522-66ac-9740-41fb-2df6ab6f3aec@users.sourceforge.net>

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Thu, 16 Nov 2017 16:18:38 +0100

Add jump targets so that a bit of exception handling can be better reused
at the end of this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 sound/pci/mixart/mixart.c | 61 ++++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 30 deletions(-)

diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index ff90a06f775e..928079520502 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -1274,16 +1274,16 @@ static int snd_mixart_probe(struct pci_dev *pci,
 	if (dma_set_mask(&pci->dev, DMA_BIT_MASK(32)) < 0) {
 		dev_err(&pci->dev,
 			"architecture does not support 32bit PCI busmaster DMA\n");
-		pci_disable_device(pci);
-		return -ENXIO;
+		err = -ENXIO;
+		goto disable_device;
 	}
 
 	/*
 	 */
 	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
 	if (! mgr) {
-		pci_disable_device(pci);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto disable_device;
 	}
 
 	mgr->pci = pci;
@@ -1293,8 +1293,7 @@ static int snd_mixart_probe(struct pci_dev *pci,
 	err = pci_request_regions(pci, CARD_NAME);
 	if (err < 0) {
 		kfree(mgr);
-		pci_disable_device(pci);
-		return err;
+		goto disable_device;
 	}
 	for (i = 0; i < 2; i++) {
 		mgr->mem[i].phys = pci_resource_start(pci, i);
@@ -1302,8 +1301,8 @@ static int snd_mixart_probe(struct pci_dev *pci,
 		if (!mgr->mem[i].virt) {
 			dev_err(&pci->dev, "unable to remap resource 0x%lx\n",
 			       mgr->mem[i].phys);
-			snd_mixart_free(mgr);
-			return -EBUSY;
+			err = -EBUSY;
+			goto free_sound_chip;
 		}
 	}
 
@@ -1311,8 +1310,8 @@ static int snd_mixart_probe(struct pci_dev *pci,
 				 snd_mixart_threaded_irq, IRQF_SHARED,
 				 KBUILD_MODNAME, mgr)) {
 		dev_err(&pci->dev, "unable to grab IRQ %d\n", pci->irq);
-		snd_mixart_free(mgr);
-		return -EBUSY;
+		err = -EBUSY;
+		goto free_sound_chip;
 	}
 	mgr->irq = pci->irq;
 
@@ -1345,8 +1344,7 @@ static int snd_mixart_probe(struct pci_dev *pci,
 
 		if (err < 0) {
 			dev_err(&pci->dev, "cannot allocate the card %d\n", i);
-			snd_mixart_free(mgr);
-			return err;
+			goto free_sound_chip;
 		}
 
 		strcpy(card->driver, CARD_NAME);
@@ -1359,8 +1357,7 @@ static int snd_mixart_probe(struct pci_dev *pci,
 		err = snd_mixart_create(mgr, card, i);
 		if (err < 0) {
 			snd_card_free(card);
-			snd_mixart_free(mgr);
-			return err;
+			goto free_sound_chip;
 		}
 
 		if(i==0) {
@@ -1369,10 +1366,8 @@ static int snd_mixart_probe(struct pci_dev *pci,
 		}
 
 		err = snd_card_register(card);
-		if (err < 0) {
-			snd_mixart_free(mgr);
-			return err;
-		}
+		if (err < 0)
+			goto free_sound_chip;
 	}
 
 	/* init firmware status (mgr->dsp_loaded reset in hwdep_new) */
@@ -1382,10 +1377,9 @@ static int snd_mixart_probe(struct pci_dev *pci,
 	size = PAGE_ALIGN( (MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS *
 			    sizeof(struct mixart_flowinfo)) );
 	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
-				size, &mgr->flowinfo) < 0) {
-		snd_mixart_free(mgr);
-		return -ENOMEM;
-	}
+				size, &mgr->flowinfo) < 0)
+		goto e_nomem;
+
 	/* init streaminfo_array */
 	memset(mgr->flowinfo.area, 0, size);
 
@@ -1393,23 +1387,30 @@ static int snd_mixart_probe(struct pci_dev *pci,
 	size = PAGE_ALIGN( (MIXART_MAX_STREAM_PER_CARD * MIXART_MAX_CARDS *
 			    sizeof(struct mixart_bufferinfo)) );
 	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
-				size, &mgr->bufferinfo) < 0) {
-		snd_mixart_free(mgr);
-		return -ENOMEM;
-	}
+				size, &mgr->bufferinfo) < 0)
+		goto e_nomem;
+
 	/* init bufferinfo_array */
 	memset(mgr->bufferinfo.area, 0, size);
 
 	/* set up firmware */
 	err = snd_mixart_setup_firmware(mgr);
-	if (err < 0) {
-		snd_mixart_free(mgr);
-		return err;
-	}
+	if (err < 0)
+		goto free_sound_chip;
 
 	pci_set_drvdata(pci, mgr);
 	dev++;
 	return 0;
+
+disable_device:
+	pci_disable_device(pci);
+	return err;
+
+e_nomem:
+	err = -ENOMEM;
+free_sound_chip:
+	snd_mixart_free(mgr);
+	return err;
 }
 
 static void snd_mixart_remove(struct pci_dev *pci)
-- 
2.15.0

      parent reply	other threads:[~2017-11-16 15:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-16 15:32 [PATCH 0/2] ALSA-miXart: Fine-tuning for seven function implementations SF Markus Elfring
2017-11-16 15:33 ` [PATCH 1/2] ALSA: mixart: Adjust 23 function calls together with a variable assignment SF Markus Elfring
2017-11-16 15:36 ` SF Markus Elfring [this message]

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=d4bad61d-fa9d-283f-1cce-b5c7a7efa640@users.sourceforge.net \
    --to=elfring@users.sourceforge.net \
    --cc=alsa-devel@alsa-project.org \
    --cc=arnd@arndb.de \
    --cc=bhumirks@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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