Commit 10dc8ad5 authored by Takashi Iwai's avatar Takashi Iwai
Browse files

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 1c98f574 "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: default avatarTakashi Iwai <tiwai@suse.de>
parent d6f9afe9
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -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;
	}
+2 −1
Original line number Diff line number Diff line
@@ -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 */
+4 −2
Original line number Diff line number Diff line
@@ -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;
+39 −26
Original line number Diff line number Diff line
@@ -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)
	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,
		err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB,
					  chip->mpu_port,
					  MPU401_INFO_IRQ_HOOK, -1,
					       &chip->rmidi)) < 0)
					  &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;
		}
+10 −4
Original line number Diff line number Diff line
@@ -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;
	}
Loading