ALSA: rme96: Allocate resources with device-managed APIs

This patch converts the resource management in PCI rme96 driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-23-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2021-07-15 09:58:44 +02:00
parent 102e6156de
commit df06df7cc9

View File

@ -1562,33 +1562,17 @@ static const struct snd_pcm_ops snd_rme96_capture_adat_ops = {
}; };
static void static void
snd_rme96_free(void *private_data) snd_rme96_free(struct rme96 *rme96)
{ {
struct rme96 *rme96 = (struct rme96 *)private_data;
if (!rme96)
return;
if (rme96->irq >= 0) { if (rme96->irq >= 0) {
snd_rme96_trigger(rme96, RME96_STOP_BOTH); snd_rme96_trigger(rme96, RME96_STOP_BOTH);
rme96->areg &= ~RME96_AR_DAC_EN; rme96->areg &= ~RME96_AR_DAC_EN;
writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG); writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
free_irq(rme96->irq, (void *)rme96);
rme96->irq = -1;
}
if (rme96->iobase) {
iounmap(rme96->iobase);
rme96->iobase = NULL;
}
if (rme96->port) {
pci_release_regions(rme96->pci);
rme96->port = 0;
} }
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
vfree(rme96->playback_suspend_buffer); vfree(rme96->playback_suspend_buffer);
vfree(rme96->capture_suspend_buffer); vfree(rme96->capture_suspend_buffer);
#endif #endif
pci_disable_device(rme96->pci);
} }
static void static void
@ -1614,7 +1598,7 @@ snd_rme96_create(struct rme96 *rme96)
rme96->irq = -1; rme96->irq = -1;
spin_lock_init(&rme96->lock); spin_lock_init(&rme96->lock);
err = pci_enable_device(pci); err = pcim_enable_device(pci);
if (err < 0) if (err < 0)
return err; return err;
@ -1623,16 +1607,16 @@ snd_rme96_create(struct rme96 *rme96)
return err; return err;
rme96->port = pci_resource_start(rme96->pci, 0); rme96->port = pci_resource_start(rme96->pci, 0);
rme96->iobase = ioremap(rme96->port, RME96_IO_SIZE); rme96->iobase = devm_ioremap(&pci->dev, rme96->port, RME96_IO_SIZE);
if (!rme96->iobase) { if (!rme96->iobase) {
dev_err(rme96->card->dev, dev_err(rme96->card->dev,
"unable to remap memory region 0x%lx-0x%lx\n", "unable to remap memory region 0x%lx-0x%lx\n",
rme96->port, rme96->port + RME96_IO_SIZE - 1); rme96->port, rme96->port + RME96_IO_SIZE - 1);
return -ENOMEM; return -EBUSY;
} }
if (request_irq(pci->irq, snd_rme96_interrupt, IRQF_SHARED, if (devm_request_irq(&pci->dev, pci->irq, snd_rme96_interrupt,
KBUILD_MODNAME, rme96)) { IRQF_SHARED, KBUILD_MODNAME, rme96)) {
dev_err(rme96->card->dev, "unable to grab IRQ %d\n", pci->irq); dev_err(rme96->card->dev, "unable to grab IRQ %d\n", pci->irq);
return -EBUSY; return -EBUSY;
} }
@ -2462,8 +2446,8 @@ snd_rme96_probe(struct pci_dev *pci,
dev++; dev++;
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,
sizeof(struct rme96), &card); sizeof(*rme96), &card);
if (err < 0) if (err < 0)
return err; return err;
card->private_free = snd_rme96_card_free; card->private_free = snd_rme96_card_free;
@ -2472,19 +2456,15 @@ snd_rme96_probe(struct pci_dev *pci,
rme96->pci = pci; rme96->pci = pci;
err = snd_rme96_create(rme96); err = snd_rme96_create(rme96);
if (err) if (err)
goto free_card; return err;
#ifdef CONFIG_PM_SLEEP #ifdef CONFIG_PM_SLEEP
rme96->playback_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); rme96->playback_suspend_buffer = vmalloc(RME96_BUFFER_SIZE);
if (!rme96->playback_suspend_buffer) { if (!rme96->playback_suspend_buffer)
err = -ENOMEM; return -ENOMEM;
goto free_card;
}
rme96->capture_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); rme96->capture_suspend_buffer = vmalloc(RME96_BUFFER_SIZE);
if (!rme96->capture_suspend_buffer) { if (!rme96->capture_suspend_buffer)
err = -ENOMEM; return -ENOMEM;
goto free_card;
}
#endif #endif
strcpy(card->driver, "Digi96"); strcpy(card->driver, "Digi96");
@ -2511,26 +2491,17 @@ snd_rme96_probe(struct pci_dev *pci,
rme96->port, rme96->irq); rme96->port, rme96->irq);
err = snd_card_register(card); err = snd_card_register(card);
if (err) if (err)
goto free_card; return err;
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_rme96_remove(struct pci_dev *pci)
{
snd_card_free(pci_get_drvdata(pci));
} }
static struct pci_driver rme96_driver = { static struct pci_driver rme96_driver = {
.name = KBUILD_MODNAME, .name = KBUILD_MODNAME,
.id_table = snd_rme96_ids, .id_table = snd_rme96_ids,
.probe = snd_rme96_probe, .probe = snd_rme96_probe,
.remove = snd_rme96_remove,
.driver = { .driver = {
.pm = RME96_PM_OPS, .pm = RME96_PM_OPS,
}, },