Commit 1f5ca8ec authored by Markus Elfring's avatar Markus Elfring Committed by Takashi Iwai

ALSA: ymfpci: Use common error handling code in snd_card_ymfpci_probe()

* Add a jump target so that a bit of exception handling can be better
  reused at the end of this function.

  This issue was detected by using the Coccinelle software.

* The script "checkpatch.pl" pointed information out like the following.

  ERROR: do not use assignment in if condition

  Thus fix a few source code places.

[ This also fixed a potential use-after-free at error path of
  snd_opl3_hwdep_new(), too -- tiwai ]
Signed-off-by: default avatarMarkus Elfring <elfring@users.sourceforge.net>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent f804fff1
...@@ -268,10 +268,9 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci, ...@@ -268,10 +268,9 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
if ((err = snd_ymfpci_create(card, pci, if ((err = snd_ymfpci_create(card, pci,
old_legacy_ctrl, old_legacy_ctrl,
&chip)) < 0) { &chip)) < 0) {
snd_card_free(card);
release_and_free_resource(mpu_res); release_and_free_resource(mpu_res);
release_and_free_resource(fm_res); release_and_free_resource(fm_res);
return err; goto free_card;
} }
chip->fm_res = fm_res; chip->fm_res = fm_res;
chip->mpu_res = mpu_res; chip->mpu_res = mpu_res;
...@@ -283,35 +282,31 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci, ...@@ -283,35 +282,31 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
card->shortname, card->shortname,
chip->reg_area_phys, chip->reg_area_phys,
chip->irq); chip->irq);
if ((err = snd_ymfpci_pcm(chip, 0)) < 0) { err = snd_ymfpci_pcm(chip, 0);
snd_card_free(card); if (err < 0)
return err; goto free_card;
}
if ((err = snd_ymfpci_pcm_spdif(chip, 1)) < 0) { err = snd_ymfpci_pcm_spdif(chip, 1);
snd_card_free(card); if (err < 0)
return err; goto free_card;
}
err = snd_ymfpci_mixer(chip, rear_switch[dev]); err = snd_ymfpci_mixer(chip, rear_switch[dev]);
if (err < 0) { if (err < 0)
snd_card_free(card); goto free_card;
return err;
}
if (chip->ac97->ext_id & AC97_EI_SDAC) { if (chip->ac97->ext_id & AC97_EI_SDAC) {
err = snd_ymfpci_pcm_4ch(chip, 2); err = snd_ymfpci_pcm_4ch(chip, 2);
if (err < 0) { if (err < 0)
snd_card_free(card); goto free_card;
return err;
}
err = snd_ymfpci_pcm2(chip, 3); err = snd_ymfpci_pcm2(chip, 3);
if (err < 0) { if (err < 0)
snd_card_free(card); goto free_card;
return err;
}
}
if ((err = snd_ymfpci_timer(chip, 0)) < 0) {
snd_card_free(card);
return err;
} }
err = snd_ymfpci_timer(chip, 0);
if (err < 0)
goto free_card;
if (chip->mpu_res) { if (chip->mpu_res) {
if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI, if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI,
mpu_port[dev], mpu_port[dev],
...@@ -336,21 +331,24 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci, ...@@ -336,21 +331,24 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
legacy_ctrl &= ~YMFPCI_LEGACY_FMEN; legacy_ctrl &= ~YMFPCI_LEGACY_FMEN;
pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
} else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) { } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
snd_card_free(card);
dev_err(card->dev, "cannot create opl3 hwdep\n"); dev_err(card->dev, "cannot create opl3 hwdep\n");
return err; goto free_card;
} }
} }
snd_ymfpci_create_gameport(chip, dev, legacy_ctrl, legacy_ctrl2); snd_ymfpci_create_gameport(chip, dev, legacy_ctrl, legacy_ctrl2);
if ((err = snd_card_register(card)) < 0) { err = snd_card_register(card);
snd_card_free(card); if (err < 0)
return err; goto free_card;
}
pci_set_drvdata(pci, card); pci_set_drvdata(pci, card);
dev++; dev++;
return 0; return 0;
free_card:
snd_card_free(card);
return err;
} }
static void snd_card_ymfpci_remove(struct pci_dev *pci) static void snd_card_ymfpci_remove(struct pci_dev *pci)
......
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