ALSA: sb: Minor coding style fixes
authorTakashi Iwai <tiwai@suse.de>
Tue, 8 Jun 2021 14:04:36 +0000 (16:04 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 9 Jun 2021 15:29:37 +0000 (17:29 +0200)
The handling of snd_ctl_new1() and snd_ctl_add() can be sometimes
tricky, as snd_ctl_add() automatically removes the passed object at
its error path.  The recent fix addressed an overlooked issue that is
relevant with that in SB driver code, and it can be a bit more
simplified by assigning to a temporary variable, i.e. storing to the
struct field only after the creation succeeds.

Link: https://lore.kernel.org/r/20210608140540.17885-3-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/isa/sb/emu8000.c
sound/isa/sb/sb16_csp.c

index 896a862a9f9c074ff2709112b828bf45ce057def..5e41879402653ca5b49e6b5a0266584c324c9ab7 100644 (file)
@@ -1020,6 +1020,7 @@ static const struct snd_kcontrol_new *mixer_defs[EMU8000_NUM_CONTROLS] = {
 static int
 snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu)
 {
+       struct snd_kcontrol *kctl;
        int i, err = 0;
 
        if (snd_BUG_ON(!emu || !card))
@@ -1029,12 +1030,11 @@ snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu)
 
        memset(emu->controls, 0, sizeof(emu->controls));
        for (i = 0; i < EMU8000_NUM_CONTROLS; i++) {
-               emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu);
-               err = snd_ctl_add(card, emu->controls[i]);
-               if (err < 0) {
-                       emu->controls[i] = NULL;
+               kctl = snd_ctl_new1(mixer_defs[i], emu);
+               err = snd_ctl_add(card, kctl);
+               if (err < 0)
                        goto __error;
-               }
+               emu->controls[i] = kctl;
        }
        return 0;
 
index d6ce6b16421c8e8fd9a20877a7d9c1a8912394d0..dec68ae6b599df2234d22658c7b7669e3bcd99ee 100644 (file)
@@ -1036,6 +1036,7 @@ static const struct snd_kcontrol_new snd_sb_qsound_space = {
 static int snd_sb_qsound_build(struct snd_sb_csp * p)
 {
        struct snd_card *card;
+       struct snd_kcontrol *kctl;
        int err;
 
        if (snd_BUG_ON(!p))
@@ -1047,18 +1048,16 @@ static int snd_sb_qsound_build(struct snd_sb_csp * p)
 
        spin_lock_init(&p->q_lock);
 
-       p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p);
-       err = snd_ctl_add(card, p->qsound_switch);
-       if (err < 0) {
-               p->qsound_switch = NULL;
+       kctl = snd_ctl_new1(&snd_sb_qsound_switch, p);
+       err = snd_ctl_add(card, kctl);
+       if (err < 0)
                goto __error;
-       }
-       p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p);
-       err = snd_ctl_add(card, p->qsound_space);
-       if (err < 0) {
-               p->qsound_space = NULL;
+       p->qsound_switch = kctl;
+       kctl = snd_ctl_new1(&snd_sb_qsound_space, p);
+       err = snd_ctl_add(card, kctl);
+       if (err < 0)
                goto __error;
-       }
+       p->qsound_space = kctl;
 
        return 0;