Skip to content

Commit aa92050

Browse files
committed
ALSA: mtpav: Allocate resources with device-managed APIs
This patch converts the resource management in mtpav driver with devres as a clean up. Each manual resource management is converted with the corresponding devres helper now. This should give no user-visible functional changes. Link: https://lore.kernel.org/r/20210715075941.23332-75-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent ed539fc commit aa92050

1 file changed

Lines changed: 9 additions & 21 deletions

File tree

sound/drivers/mtpav.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,15 @@ static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id)
566566
*/
567567
static int snd_mtpav_get_ISA(struct mtpav *mcard)
568568
{
569-
mcard->res_port = request_region(port, 3, "MotuMTPAV MIDI");
569+
mcard->res_port = devm_request_region(mcard->card->dev, port, 3,
570+
"MotuMTPAV MIDI");
570571
if (!mcard->res_port) {
571572
snd_printk(KERN_ERR "MTVAP port 0x%lx is busy\n", port);
572573
return -EBUSY;
573574
}
574575
mcard->port = port;
575-
if (request_irq(irq, snd_mtpav_irqh, 0, "MOTU MTPAV", mcard)) {
576+
if (devm_request_irq(mcard->card->dev, irq, snd_mtpav_irqh, 0,
577+
"MOTU MTPAV", mcard)) {
576578
snd_printk(KERN_ERR "MTVAP IRQ %d busy\n", irq);
577579
return -EBUSY;
578580
}
@@ -667,9 +669,6 @@ static void snd_mtpav_free(struct snd_card *card)
667669
if (crd->istimer > 0)
668670
snd_mtpav_remove_output_timer(crd);
669671
spin_unlock_irqrestore(&crd->spinlock, flags);
670-
if (crd->irq >= 0)
671-
free_irq(crd->irq, (void *)crd);
672-
release_and_free_resource(crd->res_port);
673672
}
674673

675674
/*
@@ -680,8 +679,8 @@ static int snd_mtpav_probe(struct platform_device *dev)
680679
int err;
681680
struct mtpav *mtp_card;
682681

683-
err = snd_card_new(&dev->dev, index, id, THIS_MODULE,
684-
sizeof(*mtp_card), &card);
682+
err = snd_devm_card_new(&dev->dev, index, id, THIS_MODULE,
683+
sizeof(*mtp_card), &card);
685684
if (err < 0)
686685
return err;
687686

@@ -698,13 +697,13 @@ static int snd_mtpav_probe(struct platform_device *dev)
698697

699698
err = snd_mtpav_get_RAWMIDI(mtp_card);
700699
if (err < 0)
701-
goto __error;
700+
return err;
702701

703702
mtp_card->inmidiport = mtp_card->num_ports + MTPAV_PIDX_BROADCAST;
704703

705704
err = snd_mtpav_get_ISA(mtp_card);
706705
if (err < 0)
707-
goto __error;
706+
return err;
708707

709708
strcpy(card->driver, "MTPAV");
710709
strcpy(card->shortname, "MTPAV on parallel port");
@@ -715,28 +714,17 @@ static int snd_mtpav_probe(struct platform_device *dev)
715714

716715
err = snd_card_register(mtp_card->card);
717716
if (err < 0)
718-
goto __error;
717+
return err;
719718

720719
platform_set_drvdata(dev, card);
721720
printk(KERN_INFO "Motu MidiTimePiece on parallel port irq: %d ioport: 0x%lx\n", irq, port);
722721
return 0;
723-
724-
__error:
725-
snd_card_free(card);
726-
return err;
727-
}
728-
729-
static int snd_mtpav_remove(struct platform_device *devptr)
730-
{
731-
snd_card_free(platform_get_drvdata(devptr));
732-
return 0;
733722
}
734723

735724
#define SND_MTPAV_DRIVER "snd_mtpav"
736725

737726
static struct platform_driver snd_mtpav_driver = {
738727
.probe = snd_mtpav_probe,
739-
.remove = snd_mtpav_remove,
740728
.driver = {
741729
.name = SND_MTPAV_DRIVER,
742730
},

0 commit comments

Comments
 (0)