Commit 111601ff authored by Takashi Iwai's avatar Takashi Iwai

ALSA: sc6000: Allocate resources with device-managed APIs

This patch converts the resource management in ISA als100 driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper.  The cleanup code was moved from
the remove callback to card->private_free, and then the remove
callback became superfluous and dropped.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-70-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 6bf39b5d
...@@ -529,6 +529,14 @@ static int snd_sc6000_match(struct device *devptr, unsigned int dev) ...@@ -529,6 +529,14 @@ static int snd_sc6000_match(struct device *devptr, unsigned int dev)
return 1; return 1;
} }
static void snd_sc6000_free(struct snd_card *card)
{
char __iomem **vport = card->private_data;
if (*vport)
sc6000_setup_board(*vport, 0);
}
static int snd_sc6000_probe(struct device *devptr, unsigned int dev) static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
{ {
static const int possible_irqs[] = { 5, 7, 9, 10, 11, -1 }; static const int possible_irqs[] = { 5, 7, 9, 10, 11, -1 };
...@@ -543,8 +551,8 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev) ...@@ -543,8 +551,8 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
char __iomem *vmss_port; char __iomem *vmss_port;
err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE,
sizeof(vport), &card); sizeof(vport), &card);
if (err < 0) if (err < 0)
return err; return err;
...@@ -553,8 +561,7 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev) ...@@ -553,8 +561,7 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
xirq = snd_legacy_find_free_irq(possible_irqs); xirq = snd_legacy_find_free_irq(possible_irqs);
if (xirq < 0) { if (xirq < 0) {
snd_printk(KERN_ERR PFX "unable to find a free IRQ\n"); snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
err = -EBUSY; return -EBUSY;
goto err_exit;
} }
} }
...@@ -562,38 +569,33 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev) ...@@ -562,38 +569,33 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
xdma = snd_legacy_find_free_dma(possible_dmas); xdma = snd_legacy_find_free_dma(possible_dmas);
if (xdma < 0) { if (xdma < 0) {
snd_printk(KERN_ERR PFX "unable to find a free DMA\n"); snd_printk(KERN_ERR PFX "unable to find a free DMA\n");
err = -EBUSY; return -EBUSY;
goto err_exit;
} }
} }
if (!request_region(port[dev], 0x10, DRV_NAME)) { if (!devm_request_region(devptr, port[dev], 0x10, DRV_NAME)) {
snd_printk(KERN_ERR PFX snd_printk(KERN_ERR PFX
"I/O port region is already in use.\n"); "I/O port region is already in use.\n");
err = -EBUSY; return -EBUSY;
goto err_exit;
} }
*vport = devm_ioport_map(devptr, port[dev], 0x10); *vport = devm_ioport_map(devptr, port[dev], 0x10);
if (*vport == NULL) { if (*vport == NULL) {
snd_printk(KERN_ERR PFX snd_printk(KERN_ERR PFX
"I/O port cannot be iomapped.\n"); "I/O port cannot be iomapped.\n");
err = -EBUSY; return -EBUSY;
goto err_unmap1;
} }
/* to make it marked as used */ /* to make it marked as used */
if (!request_region(mss_port[dev], 4, DRV_NAME)) { if (!devm_request_region(devptr, mss_port[dev], 4, DRV_NAME)) {
snd_printk(KERN_ERR PFX snd_printk(KERN_ERR PFX
"SC-6000 port I/O port region is already in use.\n"); "SC-6000 port I/O port region is already in use.\n");
err = -EBUSY; return -EBUSY;
goto err_unmap1;
} }
vmss_port = devm_ioport_map(devptr, mss_port[dev], 4); vmss_port = devm_ioport_map(devptr, mss_port[dev], 4);
if (!vmss_port) { if (!vmss_port) {
snd_printk(KERN_ERR PFX snd_printk(KERN_ERR PFX
"MSS port I/O cannot be iomapped.\n"); "MSS port I/O cannot be iomapped.\n");
err = -EBUSY; return -EBUSY;
goto err_unmap2;
} }
snd_printd("Initializing BASE[0x%lx] IRQ[%d] DMA[%d] MIRQ[%d]\n", snd_printd("Initializing BASE[0x%lx] IRQ[%d] DMA[%d] MIRQ[%d]\n",
...@@ -602,28 +604,29 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev) ...@@ -602,28 +604,29 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
err = sc6000_init_board(*vport, vmss_port, dev); err = sc6000_init_board(*vport, vmss_port, dev);
if (err < 0) if (err < 0)
goto err_unmap2; return err;
card->private_free = snd_sc6000_free;
err = snd_wss_create(card, mss_port[dev] + 4, -1, xirq, xdma, -1, err = snd_wss_create(card, mss_port[dev] + 4, -1, xirq, xdma, -1,
WSS_HW_DETECT, 0, &chip); WSS_HW_DETECT, 0, &chip);
if (err < 0) if (err < 0)
goto err_unmap2; return err;
err = snd_wss_pcm(chip, 0); err = snd_wss_pcm(chip, 0);
if (err < 0) { if (err < 0) {
snd_printk(KERN_ERR PFX snd_printk(KERN_ERR PFX
"error creating new WSS PCM device\n"); "error creating new WSS PCM device\n");
goto err_unmap2; return err;
} }
err = snd_wss_mixer(chip); err = snd_wss_mixer(chip);
if (err < 0) { if (err < 0) {
snd_printk(KERN_ERR PFX "error creating new WSS mixer\n"); snd_printk(KERN_ERR PFX "error creating new WSS mixer\n");
goto err_unmap2; return err;
} }
err = snd_sc6000_mixer(chip); err = snd_sc6000_mixer(chip);
if (err < 0) { if (err < 0) {
snd_printk(KERN_ERR PFX "the mixer rewrite failed\n"); snd_printk(KERN_ERR PFX "the mixer rewrite failed\n");
goto err_unmap2; return err;
} }
if (snd_opl3_create(card, if (snd_opl3_create(card,
0x388, 0x388 + 2, 0x388, 0x388 + 2,
...@@ -633,7 +636,7 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev) ...@@ -633,7 +636,7 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
} else { } else {
err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
if (err < 0) if (err < 0)
goto err_unmap2; return err;
} }
if (mpu_port[dev] != SNDRV_AUTO_PORT) { if (mpu_port[dev] != SNDRV_AUTO_PORT) {
...@@ -654,39 +657,15 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev) ...@@ -654,39 +657,15 @@ static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
err = snd_card_register(card); err = snd_card_register(card);
if (err < 0) if (err < 0)
goto err_unmap2; return err;
dev_set_drvdata(devptr, card); dev_set_drvdata(devptr, card);
return 0; return 0;
err_unmap2:
sc6000_setup_board(*vport, 0);
release_region(mss_port[dev], 4);
err_unmap1:
release_region(port[dev], 0x10);
err_exit:
snd_card_free(card);
return err;
}
static void snd_sc6000_remove(struct device *devptr, unsigned int dev)
{
struct snd_card *card = dev_get_drvdata(devptr);
char __iomem **vport = card->private_data;
if (sc6000_setup_board(*vport, 0) < 0)
snd_printk(KERN_WARNING "sc6000_setup_board failed on exit!\n");
release_region(port[dev], 0x10);
release_region(mss_port[dev], 4);
snd_card_free(card);
} }
static struct isa_driver snd_sc6000_driver = { static struct isa_driver snd_sc6000_driver = {
.match = snd_sc6000_match, .match = snd_sc6000_match,
.probe = snd_sc6000_probe, .probe = snd_sc6000_probe,
.remove = snd_sc6000_remove,
/* FIXME: suspend/resume */ /* FIXME: suspend/resume */
.driver = { .driver = {
.name = DRV_NAME, .name = DRV_NAME,
......
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