[alsa-devel] [PATCH 3/3] ALSA: es1938: Use common error handling code in snd_es1938_create()
SF Markus Elfring
elfring at users.sourceforge.net
Tue Nov 14 21:38:28 CET 2017
From: Markus Elfring <elfring at users.sourceforge.net>
Date: Tue, 14 Nov 2017 21:25:55 +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 at users.sourceforge.net>
---
sound/pci/es1938.c | 29 +++++++++++++++++------------
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index b19e611345d1..2b4dd1297bbc 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1606,14 +1606,14 @@ static int snd_es1938_create(struct snd_card *card,
dma_set_coherent_mask(&pci->dev, DMA_BIT_MASK(24)) < 0) {
dev_err(card->dev,
"architecture does not support 24bit PCI busmaster DMA\n");
- pci_disable_device(pci);
- return -ENXIO;
+ err = -ENXIO;
+ goto disable_device;
}
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
if (chip == NULL) {
- pci_disable_device(pci);
- return -ENOMEM;
+ err = -ENOMEM;
+ goto disable_device;
}
spin_lock_init(&chip->reg_lock);
spin_lock_init(&chip->mixer_lock);
@@ -1623,8 +1623,7 @@ static int snd_es1938_create(struct snd_card *card,
err = pci_request_regions(pci, "ESS Solo-1");
if (err < 0) {
kfree(chip);
- pci_disable_device(pci);
- return err;
+ goto disable_device;
}
chip->io_port = pci_resource_start(pci, 0);
chip->sb_port = pci_resource_start(pci, 1);
@@ -1634,8 +1633,8 @@ static int snd_es1938_create(struct snd_card *card,
if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED,
KBUILD_MODNAME, chip)) {
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
- snd_es1938_free(chip);
- return -EBUSY;
+ err = -EBUSY;
+ goto free_sound_chip;
}
chip->irq = pci->irq;
dev_dbg(card->dev,
@@ -1647,13 +1646,19 @@ static int snd_es1938_create(struct snd_card *card,
snd_es1938_chip_init(chip);
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
- if (err < 0) {
- snd_es1938_free(chip);
- return err;
- }
+ if (err < 0)
+ goto free_sound_chip;
*rchip = chip;
return 0;
+
+disable_device:
+ pci_disable_device(pci);
+ return err;
+
+free_sound_chip:
+ snd_es1938_free(chip);
+ return err;
}
/* --------------------------------------------------------------------
--
2.15.0
More information about the Alsa-devel
mailing list