From: SF Markus Elfring <elfring@users.sourceforge.net>
To: alsa-devel@alsa-project.org, Bhumika Goyal <bhumirks@gmail.com>,
Fabian Frederick <fabf@skynet.be>,
Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH 3/3] ALSA: cs4281: Use common error handling code in snd_cs4281_create()
Date: Mon, 13 Nov 2017 13:53:52 +0100 [thread overview]
Message-ID: <c6e82722-df16-6781-be3f-eba6e9e0fd08@users.sourceforge.net> (raw)
In-Reply-To: <ac9d010b-7a26-1f2d-5034-15abe603c6fd@users.sourceforge.net>
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Mon, 13 Nov 2017 13:34:57 +0100
* Add jump targets so that a bit of exception handling can be better reused
at the end of this function.
* Delete the local variable "tmp" which was unnecessary
because the variable "err" could be used at this place again.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/cs4281.c | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index ed6b97dbd1cc..6cd7300a0182 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -1347,7 +1347,6 @@ static int snd_cs4281_create(struct snd_card *card,
int dual_codec)
{
struct cs4281 *chip;
- unsigned int tmp;
int err;
static struct snd_device_ops ops = {
.dev_free = snd_cs4281_dev_free,
@@ -1359,8 +1358,8 @@ static int snd_cs4281_create(struct snd_card *card,
return err;
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);
chip->card = card;
@@ -1376,43 +1375,45 @@ static int snd_cs4281_create(struct snd_card *card,
err = pci_request_regions(pci, "CS4281");
if (err < 0) {
kfree(chip);
- pci_disable_device(pci);
- return err;
+ goto disable_device;
}
chip->ba0_addr = pci_resource_start(pci, 0);
chip->ba1_addr = pci_resource_start(pci, 1);
chip->ba0 = pci_ioremap_bar(pci, 0);
chip->ba1 = pci_ioremap_bar(pci, 1);
- if (!chip->ba0 || !chip->ba1) {
- snd_cs4281_free(chip);
- return -ENOMEM;
- }
+ if (!chip->ba0 || !chip->ba1)
+ goto e_nomem;
if (request_irq(pci->irq, snd_cs4281_interrupt, IRQF_SHARED,
KBUILD_MODNAME, chip)) {
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
- snd_cs4281_free(chip);
- return -ENOMEM;
+ goto e_nomem;
}
chip->irq = pci->irq;
- tmp = snd_cs4281_chip_init(chip);
- if (tmp) {
- snd_cs4281_free(chip);
- return tmp;
- }
+ err = snd_cs4281_chip_init(chip);
+ if (err)
+ goto free_sound_chip;
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
- if (err < 0) {
- snd_cs4281_free(chip);
- return err;
- }
+ if (err < 0)
+ goto free_sound_chip;
snd_cs4281_proc_init(chip);
*rchip = chip;
return 0;
+
+disable_device:
+ pci_disable_device(pci);
+ return err;
+
+e_nomem:
+ err = -ENOMEM;
+free_sound_chip:
+ snd_cs4281_free(chip);
+ return err;
}
static int snd_cs4281_chip_init(struct cs4281 *chip)
--
2.15.0
prev parent reply other threads:[~2017-11-13 12:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-13 12:50 [PATCH 0/3] ALSA: cs4281: Fine-tuning for five function implementations SF Markus Elfring
2017-11-13 12:51 ` [PATCH 1/3] ALSA: cs4281: Adjust 18 function calls together with a variable assignment SF Markus Elfring
2017-11-13 12:52 ` [PATCH 2/3] ALSA: cs4281: Use common error handling code in snd_cs4281_probe() SF Markus Elfring
2017-11-13 12:53 ` 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=c6e82722-df16-6781-be3f-eba6e9e0fd08@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=alsa-devel@alsa-project.org \
--cc=bhumirks@gmail.com \
--cc=fabf@skynet.be \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=o-takashi@sakamocchi.jp \
--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
all inboxes | Powered by JetHome®