From: SF Markus Elfring <elfring@users.sourceforge.net>
To: alsa-devel@alsa-project.org, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>
Cc: LKML <linux-kernel@vger.kernel.org>, kernel-janitors@vger.kernel.org
Subject: [PATCH] ALSA: ac97_codec: Use common error handling code in snd_ac97_mixer()
Date: Sat, 11 Nov 2017 22:40:35 +0100 [thread overview]
Message-ID: <18b1926e-d801-4b9b-abab-8474113f556f@users.sourceforge.net> (raw)
From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 11 Nov 2017 22:30:51 +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.
* The script "checkpatch.pl" pointed information out like the following.
ERROR: do not use assignment in if condition
Thus fix three affected source code places.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
sound/pci/ac97/ac97_codec.c | 50 +++++++++++++++++++++++----------------------
1 file changed, 26 insertions(+), 24 deletions(-)
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index 1ef7cdf1d3e8..2289cdcf2d48 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -2103,8 +2103,8 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
ac97_err(ac97,
"AC'97 %d access is not valid [0x%x], removing mixer.\n",
ac97->num, ac97->id);
- snd_ac97_free(ac97);
- return -EIO;
+ err = -EIO;
+ goto free_ac;
}
pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
if (pid)
@@ -2138,8 +2138,8 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
ac97_err(ac97,
"AC'97 %d access error (not audio or modem codec)\n",
ac97->num);
- snd_ac97_free(ac97);
- return -EACCES;
+ err = -EACCES;
+ goto free_ac;
}
if (bus->ops->reset) // FIXME: always skipping?
@@ -2267,14 +2267,12 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
}
}
sprintf(comp, "AC97a:%08x", ac97->id);
- if ((err = snd_component_add(card, comp)) < 0) {
- snd_ac97_free(ac97);
- return err;
- }
- if (snd_ac97_mixer_build(ac97) < 0) {
- snd_ac97_free(ac97);
- return -ENOMEM;
- }
+ err = snd_component_add(card, comp);
+ if (err < 0)
+ goto free_ac;
+
+ if (snd_ac97_mixer_build(ac97) < 0)
+ goto e_nomem;
}
if (ac97_is_modem(ac97)) {
char comp[16];
@@ -2287,24 +2285,28 @@ int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
}
}
sprintf(comp, "AC97m:%08x", ac97->id);
- if ((err = snd_component_add(card, comp)) < 0) {
- snd_ac97_free(ac97);
- return err;
- }
- if (snd_ac97_modem_build(card, ac97) < 0) {
- snd_ac97_free(ac97);
- return -ENOMEM;
- }
+ err = snd_component_add(card, comp);
+ if (err < 0)
+ goto free_ac;
+
+ if (snd_ac97_modem_build(card, ac97) < 0)
+ goto e_nomem;
}
if (ac97_is_audio(ac97))
update_power_regs(ac97);
snd_ac97_proc_init(ac97);
- if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops)) < 0) {
- snd_ac97_free(ac97);
- return err;
- }
+ err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops);
+ if (err < 0)
+ goto free_ac;
+
*rac97 = ac97;
return 0;
+
+e_nomem:
+ err = -ENOMEM;
+free_ac:
+ snd_ac97_free(ac97);
+ return err;
}
EXPORT_SYMBOL(snd_ac97_mixer);
--
2.15.0
reply other threads:[~2017-11-11 21:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=18b1926e-d801-4b9b-abab-8474113f556f@users.sourceforge.net \
--to=elfring@users.sourceforge.net \
--cc=alsa-devel@alsa-project.org \
--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;
as well as URLs for NNTP newsgroup(s).