[PATCH 3/3] ALSA: trident: Use common error handling code in snd_trident_mixer()

From: SF Markus Elfring
Date: Sat Nov 18 2017 - 14:14:27 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 18 Nov 2017 19:49:50 +0100

Adjust 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/trident/trident_main.c | 71 +++++++++++++++++++---------------------
1 file changed, 33 insertions(+), 38 deletions(-)

diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index 9843a61a8ead..2cb5da02ad9b 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -2980,7 +2980,7 @@ static int snd_trident_mixer(struct snd_trident *trident, int pcm_spdif_device)

err = snd_ac97_bus(trident->card, 0, &ops, NULL, &trident->ac97_bus);
if (err < 0)
- goto __out;
+ goto free_control;

memset(&_ac97, 0, sizeof(_ac97));
_ac97.private_data = trident;
@@ -2992,12 +2992,12 @@ static int snd_trident_mixer(struct snd_trident *trident, int pcm_spdif_device)
if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
err = snd_trident_sis_reset(trident);
if (err < 0)
- goto __out;
+ goto free_control;
if (retries-- > 0)
goto __again;
err = -EIO;
}
- goto __out;
+ goto free_control;
}

/* secondary codec? */
@@ -3025,12 +3025,12 @@ static int snd_trident_mixer(struct snd_trident *trident, int pcm_spdif_device)
kctl = snd_ctl_new1(&snd_trident_vol_wave_control, trident);
err = snd_ctl_add(card, kctl);
if (err < 0)
- goto __out;
+ goto free_control;
kctl->put(kctl, uctl);
kctl = snd_ctl_new1(&snd_trident_vol_music_control, trident);
err = snd_ctl_add(card, kctl);
if (err < 0)
- goto __out;
+ goto free_control;
kctl->put(kctl, uctl);
outl(trident->musicvol_wavevol = 0x00000000, TRID_REG(trident, T4D_MUSICVOL_WAVEVOL));
} else {
@@ -3046,52 +3046,51 @@ static int snd_trident_mixer(struct snd_trident *trident, int pcm_spdif_device)

trident->ctl_vol = snd_ctl_new1(&snd_trident_pcm_vol_control, trident);
if (!trident->ctl_vol)
- goto __nomem;
+ goto e_nomem;

err = snd_ctl_add(card, trident->ctl_vol);
if (err)
- goto __out;
+ goto free_control;

trident->ctl_pan = snd_ctl_new1(&snd_trident_pcm_pan_control, trident);
if (!trident->ctl_pan)
- goto __nomem;
+ goto e_nomem;

err = snd_ctl_add(card, trident->ctl_pan);
if (err)
- goto __out;
+ goto free_control;

trident->ctl_rvol = snd_ctl_new1(&snd_trident_pcm_rvol_control,
trident);
if (!trident->ctl_rvol)
- goto __nomem;
+ goto e_nomem;

err = snd_ctl_add(card, trident->ctl_rvol);
if (err)
- goto __out;
+ goto free_control;

trident->ctl_cvol = snd_ctl_new1(&snd_trident_pcm_cvol_control,
trident);
if (!trident->ctl_cvol)
- goto __nomem;
+ goto e_nomem;

err = snd_ctl_add(card, trident->ctl_cvol);
if (err)
- goto __out;
+ goto free_control;

if (trident->device == TRIDENT_DEVICE_ID_NX) {
kctl = snd_ctl_new1(&snd_trident_ac97_rear_control, trident);
err = snd_ctl_add(card, kctl);
if (err < 0)
- goto __out;
+ goto free_control;
kctl->put(kctl, uctl);
}
if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {

kctl = snd_ctl_new1(&snd_trident_spdif_control, trident);
- if (kctl == NULL) {
- err = -ENOMEM;
- goto __out;
- }
+ if (!kctl)
+ goto e_nomem;
+
if (trident->ac97->ext_id & AC97_EI_SPDIF)
kctl->id.index++;
if (trident->ac97_sec && (trident->ac97_sec->ext_id & AC97_EI_SPDIF))
@@ -3099,51 +3098,47 @@ static int snd_trident_mixer(struct snd_trident *trident, int pcm_spdif_device)
idx = kctl->id.index;
err = snd_ctl_add(card, kctl);
if (err < 0)
- goto __out;
+ goto free_control;
kctl->put(kctl, uctl);

kctl = snd_ctl_new1(&snd_trident_spdif_default, trident);
- if (kctl == NULL) {
- err = -ENOMEM;
- goto __out;
- }
+ if (!kctl)
+ goto e_nomem;
+
kctl->id.index = idx;
kctl->id.device = pcm_spdif_device;
err = snd_ctl_add(card, kctl);
if (err < 0)
- goto __out;
+ goto free_control;

kctl = snd_ctl_new1(&snd_trident_spdif_mask, trident);
- if (kctl == NULL) {
- err = -ENOMEM;
- goto __out;
- }
+ if (!kctl)
+ goto e_nomem;
+
kctl->id.index = idx;
kctl->id.device = pcm_spdif_device;
err = snd_ctl_add(card, kctl);
if (err < 0)
- goto __out;
+ goto free_control;

kctl = snd_ctl_new1(&snd_trident_spdif_stream, trident);
- if (kctl == NULL) {
- err = -ENOMEM;
- goto __out;
- }
+ if (!kctl)
+ goto e_nomem;
+
kctl->id.index = idx;
kctl->id.device = pcm_spdif_device;
err = snd_ctl_add(card, kctl);
if (err < 0)
- goto __out;
+ goto free_control;
trident->spdif_pcm_ctl = kctl;
}

err = 0;
- goto __out;
+ goto free_control;

- __nomem:
+e_nomem:
err = -ENOMEM;
-
- __out:
+free_control:
kfree(uctl);

return err;
--
2.15.0