[PATCH 3/3] ALSA: ens1370: Use common error handling code in snd_ensoniq_create()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Nov 2017 18:28:30 +0100

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

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
 sound/pci/ens1370.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 55c5173036d3..4b4ca772cafb 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -2097,8 +2097,8 @@ static int snd_ensoniq_create(struct snd_card *card,
 		return err;
 	ensoniq = kzalloc(sizeof(*ensoniq), GFP_KERNEL);
 	if (ensoniq == NULL) {
-		pci_disable_device(pci);
-		return -ENOMEM;
+		err = -ENOMEM;
+		goto disable_device;
 	}
 	spin_lock_init(&ensoniq->reg_lock);
 	mutex_init(&ensoniq->src_mutex);
@@ -2108,23 +2108,20 @@ static int snd_ensoniq_create(struct snd_card *card,
 	err = pci_request_regions(pci, "Ensoniq AudioPCI");
 	if (err < 0) {
 		kfree(ensoniq);
-		pci_disable_device(pci);
-		return err;
+		goto disable_device;
 	}
 	ensoniq->port = pci_resource_start(pci, 0);
 	if (request_irq(pci->irq, snd_audiopci_interrupt, IRQF_SHARED,
 			KBUILD_MODNAME, ensoniq)) {
 		dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
-		snd_ensoniq_free(ensoniq);
-		return -EBUSY;
+		goto e_busy;
 	}
 	ensoniq->irq = pci->irq;
 #ifdef CHIP1370
 	if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
 				16, &ensoniq->dma_bug) < 0) {
 		dev_err(card->dev, "unable to allocate space for phantom area - dma_bug\n");
-		snd_ensoniq_free(ensoniq);
-		return -EBUSY;
+		goto e_busy;
 	}
 #endif
 	pci_set_master(pci);
@@ -2150,15 +2147,23 @@ static int snd_ensoniq_create(struct snd_card *card,
 
 	snd_ensoniq_chip_init(ensoniq);
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, ensoniq, &ops);
-	if (err < 0) {
-		snd_ensoniq_free(ensoniq);
-		return err;
-	}
+	if (err < 0)
+		goto free_sound_chip;
 
 	snd_ensoniq_proc_init(ensoniq);
 
 	*rensoniq = ensoniq;
 	return 0;
+
+disable_device:
+	pci_disable_device(pci);
+	return err;
+
+e_busy:
+	err = -EBUSY;
+free_sound_chip:
+	snd_ensoniq_free(ensoniq);
+	return err;
 }
 
 /*
-- 
2.15.0

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux