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. Signed-off-by: Takashi Iwai <tiwai@xxxxxxx> --- sound/pci/rme96.c | 57 ++++++++++++----------------------------------- 1 file changed, 14 insertions(+), 43 deletions(-) diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c index fc7ac077559c..8fc811504920 100644 --- a/sound/pci/rme96.c +++ b/sound/pci/rme96.c @@ -1562,33 +1562,17 @@ static const struct snd_pcm_ops snd_rme96_capture_adat_ops = { }; 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) { snd_rme96_trigger(rme96, RME96_STOP_BOTH); rme96->areg &= ~RME96_AR_DAC_EN; 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 vfree(rme96->playback_suspend_buffer); vfree(rme96->capture_suspend_buffer); #endif - pci_disable_device(rme96->pci); } static void @@ -1614,7 +1598,7 @@ snd_rme96_create(struct rme96 *rme96) rme96->irq = -1; spin_lock_init(&rme96->lock); - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; @@ -1623,16 +1607,16 @@ snd_rme96_create(struct rme96 *rme96) return err; 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) { dev_err(rme96->card->dev, "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1); - return -ENOMEM; + return -EBUSY; } - if (request_irq(pci->irq, snd_rme96_interrupt, IRQF_SHARED, - KBUILD_MODNAME, rme96)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_rme96_interrupt, + IRQF_SHARED, KBUILD_MODNAME, rme96)) { dev_err(rme96->card->dev, "unable to grab IRQ %d\n", pci->irq); return -EBUSY; } @@ -2462,8 +2446,8 @@ snd_rme96_probe(struct pci_dev *pci, dev++; return -ENOENT; } - err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, - sizeof(struct rme96), &card); + err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, + sizeof(*rme96), &card); if (err < 0) return err; card->private_free = snd_rme96_card_free; @@ -2472,19 +2456,15 @@ snd_rme96_probe(struct pci_dev *pci, rme96->pci = pci; err = snd_rme96_create(rme96); if (err) - goto free_card; + return err; #ifdef CONFIG_PM_SLEEP rme96->playback_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); - if (!rme96->playback_suspend_buffer) { - err = -ENOMEM; - goto free_card; - } + if (!rme96->playback_suspend_buffer) + return -ENOMEM; rme96->capture_suspend_buffer = vmalloc(RME96_BUFFER_SIZE); - if (!rme96->capture_suspend_buffer) { - err = -ENOMEM; - goto free_card; - } + if (!rme96->capture_suspend_buffer) + return -ENOMEM; #endif strcpy(card->driver, "Digi96"); @@ -2511,26 +2491,17 @@ snd_rme96_probe(struct pci_dev *pci, rme96->port, rme96->irq); err = snd_card_register(card); if (err) - goto free_card; + return err; pci_set_drvdata(pci, card); dev++; 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 = { .name = KBUILD_MODNAME, .id_table = snd_rme96_ids, .probe = snd_rme96_probe, - .remove = snd_rme96_remove, .driver = { .pm = RME96_PM_OPS, }, -- 2.26.2