Commit 546c201a authored by Takashi Iwai's avatar Takashi Iwai

ALSA: riptide: Allocate resources with device-managed APIs

This patch converts the resource management in PCI riptide driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper, and the card object release is
managed now via card->private_free instead of a lowlevel snd_device.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-45-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 596ae97a
...@@ -1798,13 +1798,11 @@ static int snd_riptide_initialize(struct snd_riptide *chip) ...@@ -1798,13 +1798,11 @@ static int snd_riptide_initialize(struct snd_riptide *chip)
return err; return err;
} }
static int snd_riptide_free(struct snd_riptide *chip) static void snd_riptide_free(struct snd_card *card)
{ {
struct snd_riptide *chip = card->private_data;
struct cmdif *cif; struct cmdif *cif;
if (!chip)
return 0;
cif = chip->cif; cif = chip->cif;
if (cif) { if (cif) {
SET_GRESET(cif->hwport); SET_GRESET(cif->hwport);
...@@ -1812,39 +1810,19 @@ static int snd_riptide_free(struct snd_riptide *chip) ...@@ -1812,39 +1810,19 @@ static int snd_riptide_free(struct snd_riptide *chip)
UNSET_GRESET(cif->hwport); UNSET_GRESET(cif->hwport);
kfree(chip->cif); kfree(chip->cif);
} }
if (chip->irq >= 0)
free_irq(chip->irq, chip);
release_firmware(chip->fw_entry); release_firmware(chip->fw_entry);
release_and_free_resource(chip->res_port);
kfree(chip);
return 0;
}
static int snd_riptide_dev_free(struct snd_device *device)
{
struct snd_riptide *chip = device->device_data;
return snd_riptide_free(chip);
} }
static int static int
snd_riptide_create(struct snd_card *card, struct pci_dev *pci, snd_riptide_create(struct snd_card *card, struct pci_dev *pci)
struct snd_riptide **rchip)
{ {
struct snd_riptide *chip; struct snd_riptide *chip = card->private_data;
struct riptideport *hwport; struct riptideport *hwport;
int err; int err;
static const struct snd_device_ops ops = {
.dev_free = snd_riptide_dev_free,
};
*rchip = NULL; err = pcim_enable_device(pci);
err = pci_enable_device(pci);
if (err < 0) if (err < 0)
return err; return err;
chip = kzalloc(sizeof(struct snd_riptide), GFP_KERNEL);
if (!chip)
return -ENOMEM;
spin_lock_init(&chip->lock); spin_lock_init(&chip->lock);
chip->card = card; chip->card = card;
...@@ -1855,24 +1833,20 @@ snd_riptide_create(struct snd_card *card, struct pci_dev *pci, ...@@ -1855,24 +1833,20 @@ snd_riptide_create(struct snd_card *card, struct pci_dev *pci,
chip->received_irqs = 0; chip->received_irqs = 0;
chip->handled_irqs = 0; chip->handled_irqs = 0;
chip->cif = NULL; chip->cif = NULL;
card->private_free = snd_riptide_free;
chip->res_port = request_region(chip->port, 64, "RIPTIDE"); err = pci_request_regions(pci, "RIPTIDE");
if (!chip->res_port) { if (err < 0)
snd_printk(KERN_ERR return err;
"Riptide: unable to grab region 0x%lx-0x%lx\n",
chip->port, chip->port + 64 - 1);
snd_riptide_free(chip);
return -EBUSY;
}
hwport = (struct riptideport *)chip->port; hwport = (struct riptideport *)chip->port;
UNSET_AIE(hwport); UNSET_AIE(hwport);
if (request_threaded_irq(pci->irq, snd_riptide_interrupt, if (devm_request_threaded_irq(&pci->dev, pci->irq,
snd_riptide_interrupt,
riptide_handleirq, IRQF_SHARED, riptide_handleirq, IRQF_SHARED,
KBUILD_MODNAME, chip)) { KBUILD_MODNAME, chip)) {
snd_printk(KERN_ERR "Riptide: unable to grab IRQ %d\n", snd_printk(KERN_ERR "Riptide: unable to grab IRQ %d\n",
pci->irq); pci->irq);
snd_riptide_free(chip);
return -EBUSY; return -EBUSY;
} }
chip->irq = pci->irq; chip->irq = pci->irq;
...@@ -1880,18 +1854,9 @@ snd_riptide_create(struct snd_card *card, struct pci_dev *pci, ...@@ -1880,18 +1854,9 @@ snd_riptide_create(struct snd_card *card, struct pci_dev *pci,
chip->device_id = pci->device; chip->device_id = pci->device;
pci_set_master(pci); pci_set_master(pci);
err = snd_riptide_initialize(chip); err = snd_riptide_initialize(chip);
if (err < 0) { if (err < 0)
snd_riptide_free(chip);
return err;
}
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
snd_riptide_free(chip);
return err; return err;
}
*rchip = chip;
return 0; return 0;
} }
...@@ -2073,20 +2038,20 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) ...@@ -2073,20 +2038,20 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
return -ENOENT; return -ENOENT;
} }
err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
0, &card); sizeof(*chip), &card);
if (err < 0) if (err < 0)
return err; return err;
err = snd_riptide_create(card, pci, &chip); chip = card->private_data;
err = snd_riptide_create(card, pci);
if (err < 0) if (err < 0)
goto error; return err;
card->private_data = chip;
err = snd_riptide_pcm(chip, 0); err = snd_riptide_pcm(chip, 0);
if (err < 0) if (err < 0)
goto error; return err;
err = snd_riptide_mixer(chip); err = snd_riptide_mixer(chip);
if (err < 0) if (err < 0)
goto error; return err;
val = LEGACY_ENABLE_ALL; val = LEGACY_ENABLE_ALL;
if (opl3_port[dev]) if (opl3_port[dev])
...@@ -2153,26 +2118,16 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) ...@@ -2153,26 +2118,16 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
snd_riptide_proc_init(chip); snd_riptide_proc_init(chip);
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0)
goto error; return err;
pci_set_drvdata(pci, card); pci_set_drvdata(pci, card);
dev++; dev++;
return 0; return 0;
error:
snd_card_free(card);
return err;
}
static void snd_card_riptide_remove(struct pci_dev *pci)
{
snd_card_free(pci_get_drvdata(pci));
} }
static struct pci_driver driver = { static struct pci_driver driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = snd_riptide_ids, .id_table = snd_riptide_ids,
.probe = snd_card_riptide_probe, .probe = snd_card_riptide_probe,
.remove = snd_card_riptide_remove,
.driver = { .driver = {
.pm = RIPTIDE_PM_OPS, .pm = RIPTIDE_PM_OPS,
}, },
......
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