Commit 36e7b12b authored by Takashi Iwai's avatar Takashi Iwai

ALSA: sb: Minor coding style fixes

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.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 10dc8ad5
...@@ -1020,6 +1020,7 @@ static const struct snd_kcontrol_new *mixer_defs[EMU8000_NUM_CONTROLS] = { ...@@ -1020,6 +1020,7 @@ static const struct snd_kcontrol_new *mixer_defs[EMU8000_NUM_CONTROLS] = {
static int static int
snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu) snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu)
{ {
struct snd_kcontrol *kctl;
int i, err = 0; int i, err = 0;
if (snd_BUG_ON(!emu || !card)) if (snd_BUG_ON(!emu || !card))
...@@ -1029,12 +1030,11 @@ snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu) ...@@ -1029,12 +1030,11 @@ snd_emu8000_create_mixer(struct snd_card *card, struct snd_emu8000 *emu)
memset(emu->controls, 0, sizeof(emu->controls)); memset(emu->controls, 0, sizeof(emu->controls));
for (i = 0; i < EMU8000_NUM_CONTROLS; i++) { for (i = 0; i < EMU8000_NUM_CONTROLS; i++) {
emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu); kctl = snd_ctl_new1(mixer_defs[i], emu);
err = snd_ctl_add(card, emu->controls[i]); err = snd_ctl_add(card, kctl);
if (err < 0) { if (err < 0)
emu->controls[i] = NULL;
goto __error; goto __error;
} emu->controls[i] = kctl;
} }
return 0; return 0;
......
...@@ -1036,6 +1036,7 @@ static const struct snd_kcontrol_new snd_sb_qsound_space = { ...@@ -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) static int snd_sb_qsound_build(struct snd_sb_csp * p)
{ {
struct snd_card *card; struct snd_card *card;
struct snd_kcontrol *kctl;
int err; int err;
if (snd_BUG_ON(!p)) if (snd_BUG_ON(!p))
...@@ -1047,18 +1048,16 @@ static int snd_sb_qsound_build(struct snd_sb_csp * p) ...@@ -1047,18 +1048,16 @@ static int snd_sb_qsound_build(struct snd_sb_csp * p)
spin_lock_init(&p->q_lock); spin_lock_init(&p->q_lock);
p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p); kctl = snd_ctl_new1(&snd_sb_qsound_switch, p);
err = snd_ctl_add(card, p->qsound_switch); err = snd_ctl_add(card, kctl);
if (err < 0) { if (err < 0)
p->qsound_switch = NULL;
goto __error; goto __error;
} p->qsound_switch = kctl;
p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p); kctl = snd_ctl_new1(&snd_sb_qsound_space, p);
err = snd_ctl_add(card, p->qsound_space); err = snd_ctl_add(card, kctl);
if (err < 0) { if (err < 0)
p->qsound_space = NULL;
goto __error; goto __error;
} p->qsound_space = kctl;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment