ALSA: sb: Fix assignment in if condition

A lot of code for SB drivers is in a legacy style with assignment in
if condition.  This also made harder to catch some bugs (e.g. the
commit 1c98f57440 "ALSA: emu8000: Fix a use after free in
snd_emu8000_create_mixer").

This patch fixes the coding style.  All are rather simple conversions
and there should be no functional changes.
(The changes in snd_emu8000_new() for hw->res_port1, 2 and 3 are
 slightly different from the older ones, but this shouldn't matter
 much in practice.)

Link: https://lore.kernel.org/r/20210608140540.17885-2-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2021-06-08 16:04:35 +02:00
parent d6f9afe947
commit 10dc8ad5ff
11 changed files with 130 additions and 89 deletions

View File

@ -1029,7 +1029,9 @@ 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++) {
if ((err = snd_ctl_add(card, emu->controls[i] = snd_ctl_new1(mixer_defs[i], emu))) < 0) {
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;
goto __error;
}
@ -1095,9 +1097,10 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports,
hw->port1 = port;
hw->port2 = port + 0x400;
hw->port3 = port + 0x800;
if (!(hw->res_port1 = request_region(hw->port1, 4, "Emu8000-1")) ||
!(hw->res_port2 = request_region(hw->port2, 4, "Emu8000-2")) ||
!(hw->res_port3 = request_region(hw->port3, 4, "Emu8000-3"))) {
hw->res_port1 = request_region(hw->port1, 4, "Emu8000-1");
hw->res_port2 = request_region(hw->port2, 4, "Emu8000-2");
hw->res_port3 = request_region(hw->port3, 4, "Emu8000-3");
if (!hw->res_port1 || !hw->res_port2 || !hw->res_port3) {
snd_printk(KERN_ERR "sbawe: can't grab ports 0x%lx, 0x%lx, 0x%lx\n", hw->port1, hw->port2, hw->port3);
snd_emu8000_free(hw);
return -EBUSY;
@ -1118,12 +1121,14 @@ snd_emu8000_new(struct snd_card *card, int index, long port, int seq_ports,
}
snd_emu8000_init_hw(hw);
if ((err = snd_emu8000_create_mixer(card, hw)) < 0) {
err = snd_emu8000_create_mixer(card, hw);
if (err < 0) {
snd_emu8000_free(hw);
return err;
}
if ((err = snd_device_new(card, SNDRV_DEV_CODEC, hw, &ops)) < 0) {
err = snd_device_new(card, SNDRV_DEV_CODEC, hw, &ops);
if (err < 0) {
snd_emu8000_free(hw);
return err;
}

View File

@ -191,7 +191,8 @@ snd_emu8000_sample_new(struct snd_emux *rec, struct snd_sf_sample *sp,
sp->v.truesize = truesize * 2; /* in bytes */
snd_emux_terminate_all(emu->emu);
if ((rc = snd_emu8000_open_dma(emu, EMU8000_RAM_WRITE)) != 0)
rc = snd_emu8000_open_dma(emu, EMU8000_RAM_WRITE);
if (rc)
return rc;
/* Set the address to start writing at */

View File

@ -626,7 +626,8 @@ static int emu8k_pcm_prepare(struct snd_pcm_substream *subs)
int err, i, ch;
snd_emux_terminate_all(rec->emu->emu);
if ((err = emu8k_open_dram_for_pcm(rec->emu, rec->voices)) != 0)
err = emu8k_open_dram_for_pcm(rec->emu, rec->voices);
if (err)
return err;
rec->dram_opened = 1;
@ -682,7 +683,8 @@ int snd_emu8000_pcm_new(struct snd_card *card, struct snd_emu8000 *emu, int inde
struct snd_pcm *pcm;
int err;
if ((err = snd_pcm_new(card, "Emu8000 PCM", index, 1, 0, &pcm)) < 0)
err = snd_pcm_new(card, "Emu8000 PCM", index, 1, 0, &pcm);
if (err < 0)
return err;
pcm->private_data = emu;
pcm->private_free = snd_emu8000_pcm_free;

View File

@ -332,14 +332,9 @@ static int snd_sb16_probe(struct snd_card *card, int dev)
xdma8 = dma8[dev];
xdma16 = dma16[dev];
if ((err = snd_sbdsp_create(card,
port[dev],
xirq,
snd_sb16dsp_interrupt,
xdma8,
xdma16,
SB_HW_AUTO,
&chip)) < 0)
err = snd_sbdsp_create(card, port[dev], xirq, snd_sb16dsp_interrupt,
xdma8, xdma16, SB_HW_AUTO, &chip);
if (err < 0)
return err;
acard->chip = chip;
@ -348,10 +343,14 @@ static int snd_sb16_probe(struct snd_card *card, int dev)
return -ENODEV;
}
chip->mpu_port = mpu_port[dev];
if (! is_isapnp_selected(dev) && (err = snd_sb16dsp_configure(chip)) < 0)
return err;
if (!is_isapnp_selected(dev)) {
err = snd_sb16dsp_configure(chip);
if (err < 0)
return err;
}
if ((err = snd_sb16dsp_pcm(chip, 0)) < 0)
err = snd_sb16dsp_pcm(chip, 0);
if (err < 0)
return err;
strcpy(card->driver,
@ -371,10 +370,11 @@ static int snd_sb16_probe(struct snd_card *card, int dev)
xdma8 >= 0 ? "&" : "", xdma16);
if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB,
chip->mpu_port,
MPU401_INFO_IRQ_HOOK, -1,
&chip->rmidi)) < 0)
err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB,
chip->mpu_port,
MPU401_INFO_IRQ_HOOK, -1,
&chip->rmidi);
if (err < 0)
return err;
chip->rmidi_callback = snd_mpu401_uart_interrupt;
}
@ -397,12 +397,14 @@ static int snd_sb16_probe(struct snd_card *card, int dev)
#else
int seqdev = 1;
#endif
if ((err = snd_opl3_hwdep_new(opl3, 0, seqdev, &synth)) < 0)
err = snd_opl3_hwdep_new(opl3, 0, seqdev, &synth);
if (err < 0)
return err;
}
}
if ((err = snd_sbmixer_new(chip)) < 0)
err = snd_sbmixer_new(chip);
if (err < 0)
return err;
#ifdef CONFIG_SND_SB16_CSP
@ -419,8 +421,9 @@ static int snd_sb16_probe(struct snd_card *card, int dev)
#endif
#ifdef SNDRV_SBAWE_EMU8000
if (awe_port[dev] > 0) {
if ((err = snd_emu8000_new(card, 1, awe_port[dev],
seq_ports[dev], NULL)) < 0) {
err = snd_emu8000_new(card, 1, awe_port[dev],
seq_ports[dev], NULL);
if (err < 0) {
snd_printk(KERN_ERR PFX "fatal error - EMU-8000 synthesizer not detected at 0x%lx\n", awe_port[dev]);
return err;
@ -435,7 +438,8 @@ static int snd_sb16_probe(struct snd_card *card, int dev)
(mic_agc[dev] ? 0x00 : 0x01));
spin_unlock_irqrestore(&chip->mixer_lock, flags);
if ((err = snd_card_register(card)) < 0)
err = snd_card_register(card);
if (err < 0)
return err;
return 0;
@ -484,7 +488,8 @@ static int snd_sb16_isa_probe1(int dev, struct device *pdev)
awe_port[dev] = port[dev] + 0x400;
#endif
if ((err = snd_sb16_probe(card, dev)) < 0) {
err = snd_sb16_probe(card, dev);
if (err < 0) {
snd_card_free(card);
return err;
}
@ -506,19 +511,22 @@ static int snd_sb16_isa_probe(struct device *pdev, unsigned int dev)
static const int possible_dmas16[] = {5, 6, 7, -1};
if (irq[dev] == SNDRV_AUTO_IRQ) {
if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) {
irq[dev] = snd_legacy_find_free_irq(possible_irqs);
if (irq[dev] < 0) {
snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
return -EBUSY;
}
}
if (dma8[dev] == SNDRV_AUTO_DMA) {
if ((dma8[dev] = snd_legacy_find_free_dma(possible_dmas8)) < 0) {
dma8[dev] = snd_legacy_find_free_dma(possible_dmas8);
if (dma8[dev] < 0) {
snd_printk(KERN_ERR PFX "unable to find a free 8-bit DMA\n");
return -EBUSY;
}
}
if (dma16[dev] == SNDRV_AUTO_DMA) {
if ((dma16[dev] = snd_legacy_find_free_dma(possible_dmas16)) < 0) {
dma16[dev] = snd_legacy_find_free_dma(possible_dmas16);
if (dma16[dev] < 0) {
snd_printk(KERN_ERR PFX "unable to find a free 16-bit DMA\n");
return -EBUSY;
}
@ -591,8 +599,13 @@ static int snd_sb16_pnp_detect(struct pnp_card_link *pcard,
res = snd_sb16_card_new(&pcard->card->dev, dev, &card);
if (res < 0)
return res;
if ((res = snd_card_sb16_pnp(dev, card->private_data, pcard, pid)) < 0 ||
(res = snd_sb16_probe(card, dev)) < 0) {
res = snd_card_sb16_pnp(dev, card->private_data, pcard, pid);
if (res < 0) {
snd_card_free(card);
return res;
}
res = snd_sb16_probe(card, dev);
if (res < 0) {
snd_card_free(card);
return res;
}

View File

@ -112,10 +112,12 @@ int snd_sb_csp_new(struct snd_sb *chip, int device, struct snd_hwdep ** rhwdep)
if (csp_detect(chip, &version))
return -ENODEV;
if ((err = snd_hwdep_new(chip->card, "SB16-CSP", device, &hw)) < 0)
err = snd_hwdep_new(chip->card, "SB16-CSP", device, &hw);
if (err < 0)
return err;
if ((p = kzalloc(sizeof(*p), GFP_KERNEL)) == NULL) {
p = kzalloc(sizeof(*p), GFP_KERNEL);
if (!p) {
snd_device_free(chip->card, hw);
return -ENOMEM;
}
@ -1045,11 +1047,15 @@ static int snd_sb_qsound_build(struct snd_sb_csp * p)
spin_lock_init(&p->q_lock);
if ((err = snd_ctl_add(card, p->qsound_switch = snd_ctl_new1(&snd_sb_qsound_switch, p))) < 0) {
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;
goto __error;
}
if ((err = snd_ctl_add(card, p->qsound_space = snd_ctl_new1(&snd_sb_qsound_space, p))) < 0) {
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;
goto __error;
}

View File

@ -703,7 +703,8 @@ static int snd_sb16_dma_control_put(struct snd_kcontrol *kcontrol, struct snd_ct
unsigned char nval, oval;
int change;
if ((nval = ucontrol->value.enumerated.item[0]) > 2)
nval = ucontrol->value.enumerated.item[0];
if (nval > 2)
return -EINVAL;
spin_lock_irqsave(&chip->reg_lock, flags);
oval = snd_sb16_get_dma_mode(chip);
@ -836,7 +837,8 @@ int snd_sb16dsp_pcm(struct snd_sb *chip, int device)
struct snd_pcm *pcm;
int err;
if ((err = snd_pcm_new(card, "SB16 DSP", device, 1, 1, &pcm)) < 0)
err = snd_pcm_new(card, "SB16 DSP", device, 1, 1, &pcm);
if (err < 0)
return err;
sprintf(pcm->name, "DSP v%i.%i", chip->version >> 8, chip->version & 0xff);
pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;

View File

@ -101,12 +101,10 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
}
if (port[dev] != SNDRV_AUTO_PORT) {
if ((err = snd_sbdsp_create(card, port[dev], irq[dev],
snd_sb8_interrupt,
dma8[dev],
-1,
SB_HW_AUTO,
&chip)) < 0)
err = snd_sbdsp_create(card, port[dev], irq[dev],
snd_sb8_interrupt, dma8[dev],
-1, SB_HW_AUTO, &chip);
if (err < 0)
goto _err;
} else {
/* auto-probe legacy ports */
@ -145,32 +143,35 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
goto _err;
}
if ((err = snd_sb8dsp_pcm(chip, 0)) < 0)
err = snd_sb8dsp_pcm(chip, 0);
if (err < 0)
goto _err;
if ((err = snd_sbmixer_new(chip)) < 0)
err = snd_sbmixer_new(chip);
if (err < 0)
goto _err;
if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
if ((err = snd_opl3_create(card, chip->port + 8, 0,
OPL3_HW_AUTO, 1,
&opl3)) < 0) {
err = snd_opl3_create(card, chip->port + 8, 0,
OPL3_HW_AUTO, 1, &opl3);
if (err < 0)
snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx\n", chip->port + 8);
}
} else {
if ((err = snd_opl3_create(card, chip->port, chip->port + 2,
OPL3_HW_AUTO, 1,
&opl3)) < 0) {
err = snd_opl3_create(card, chip->port, chip->port + 2,
OPL3_HW_AUTO, 1, &opl3);
if (err < 0) {
snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx-0x%lx\n",
chip->port, chip->port + 2);
}
}
if (err >= 0) {
if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
if (err < 0)
goto _err;
}
if ((err = snd_sb8dsp_midi(chip, 0)) < 0)
err = snd_sb8dsp_midi(chip, 0);
if (err < 0)
goto _err;
strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
@ -180,7 +181,8 @@ static int snd_sb8_probe(struct device *pdev, unsigned int dev)
chip->port,
irq[dev], dma8[dev]);
if ((err = snd_card_register(card)) < 0)
err = snd_card_register(card);
if (err < 0)
goto _err;
dev_set_drvdata(pdev, card);

View File

@ -567,7 +567,8 @@ int snd_sb8dsp_pcm(struct snd_sb *chip, int device)
int err;
size_t max_prealloc = 64 * 1024;
if ((err = snd_pcm_new(card, "SB8 DSP", device, 1, 1, &pcm)) < 0)
err = snd_pcm_new(card, "SB8 DSP", device, 1, 1, &pcm);
if (err < 0)
return err;
sprintf(pcm->name, "DSP v%i.%i", chip->version >> 8, chip->version & 0xff);
pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;

View File

@ -251,7 +251,8 @@ int snd_sb8dsp_midi(struct snd_sb *chip, int device)
struct snd_rawmidi *rmidi;
int err;
if ((err = snd_rawmidi_new(chip->card, "SB8 MIDI", device, 1, 1, &rmidi)) < 0)
err = snd_rawmidi_new(chip->card, "SB8 MIDI", device, 1, 1, &rmidi);
if (err < 0)
return err;
strcpy(rmidi->name, "SB8 MIDI");
snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_sb8dsp_midi_output);

View File

@ -238,7 +238,8 @@ int snd_sbdsp_create(struct snd_card *card,
if (hardware == SB_HW_ALS4000)
goto __skip_allocation;
if ((chip->res_port = request_region(port, 16, "SoundBlaster")) == NULL) {
chip->res_port = request_region(port, 16, "SoundBlaster");
if (!chip->res_port) {
snd_printk(KERN_ERR "sb: can't grab port 0x%lx\n", port);
snd_sbdsp_free(chip);
return -EBUSY;
@ -267,11 +268,13 @@ int snd_sbdsp_create(struct snd_card *card,
__skip_allocation:
chip->card = card;
chip->hardware = hardware;
if ((err = snd_sbdsp_probe(chip)) < 0) {
err = snd_sbdsp_probe(chip);
if (err < 0) {
snd_sbdsp_free(chip);
return err;
}
if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
snd_sbdsp_free(chip);
return err;
}

View File

@ -485,7 +485,8 @@ int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int ty
strscpy(ctl->id.name, name, sizeof(ctl->id.name));
ctl->id.index = index;
ctl->private_value = value;
if ((err = snd_ctl_add(chip->card, ctl)) < 0)
err = snd_ctl_add(chip->card, ctl);
if (err < 0)
return err;
return 0;
}
@ -736,33 +737,36 @@ int snd_sbmixer_new(struct snd_sb *chip)
return 0; /* no mixer chip on SB1.x */
case SB_HW_20:
case SB_HW_201:
if ((err = snd_sbmixer_init(chip,
snd_sb20_controls,
ARRAY_SIZE(snd_sb20_controls),
snd_sb20_init_values,
ARRAY_SIZE(snd_sb20_init_values),
"CTL1335")) < 0)
err = snd_sbmixer_init(chip,
snd_sb20_controls,
ARRAY_SIZE(snd_sb20_controls),
snd_sb20_init_values,
ARRAY_SIZE(snd_sb20_init_values),
"CTL1335");
if (err < 0)
return err;
break;
case SB_HW_PRO:
case SB_HW_JAZZ16:
if ((err = snd_sbmixer_init(chip,
snd_sbpro_controls,
ARRAY_SIZE(snd_sbpro_controls),
snd_sbpro_init_values,
ARRAY_SIZE(snd_sbpro_init_values),
"CTL1345")) < 0)
err = snd_sbmixer_init(chip,
snd_sbpro_controls,
ARRAY_SIZE(snd_sbpro_controls),
snd_sbpro_init_values,
ARRAY_SIZE(snd_sbpro_init_values),
"CTL1345");
if (err < 0)
return err;
break;
case SB_HW_16:
case SB_HW_ALS100:
case SB_HW_CS5530:
if ((err = snd_sbmixer_init(chip,
snd_sb16_controls,
ARRAY_SIZE(snd_sb16_controls),
snd_sb16_init_values,
ARRAY_SIZE(snd_sb16_init_values),
"CTL1745")) < 0)
err = snd_sbmixer_init(chip,
snd_sb16_controls,
ARRAY_SIZE(snd_sb16_controls),
snd_sb16_init_values,
ARRAY_SIZE(snd_sb16_init_values),
"CTL1745");
if (err < 0)
return err;
break;
case SB_HW_ALS4000:
@ -775,12 +779,13 @@ int snd_sbmixer_new(struct snd_sb *chip)
"ALS4000");
if (err < 0)
return err;
if ((err = snd_sbmixer_init(chip,
snd_als4000_controls,
ARRAY_SIZE(snd_als4000_controls),
snd_als4000_init_values,
ARRAY_SIZE(snd_als4000_init_values),
"ALS4000")) < 0)
err = snd_sbmixer_init(chip,
snd_als4000_controls,
ARRAY_SIZE(snd_als4000_controls),
snd_als4000_init_values,
ARRAY_SIZE(snd_als4000_init_values),
"ALS4000");
if (err < 0)
return err;
break;
case SB_HW_DT019X: