Commit ea2bfa29 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: wss: Allocate resources with device-managed APIs

This patch converts the resource management in ISA wss driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper.  Since the whole destructor code
could be removed by the conversion, the lowlevel snd_device was
dropped as well.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-54-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent d6fb54e8
...@@ -298,7 +298,6 @@ int snd_cs4236_create(struct snd_card *card, ...@@ -298,7 +298,6 @@ int snd_cs4236_create(struct snd_card *card,
if (cport < 0x100 || cport == SNDRV_AUTO_PORT) { if (cport < 0x100 || cport == SNDRV_AUTO_PORT) {
snd_printk(KERN_ERR "please, specify control port " snd_printk(KERN_ERR "please, specify control port "
"for CS4236+ chips\n"); "for CS4236+ chips\n");
snd_device_free(card, chip);
return -ENODEV; return -ENODEV;
} }
ver1 = snd_cs4236_ctrl_in(chip, 1); ver1 = snd_cs4236_ctrl_in(chip, 1);
...@@ -308,7 +307,6 @@ int snd_cs4236_create(struct snd_card *card, ...@@ -308,7 +307,6 @@ int snd_cs4236_create(struct snd_card *card,
if (ver1 != ver2) { if (ver1 != ver2) {
snd_printk(KERN_ERR "CS4236+ chip detected, but " snd_printk(KERN_ERR "CS4236+ chip detected, but "
"control port 0x%lx is not valid\n", cport); "control port 0x%lx is not valid\n", cport);
snd_device_free(card, chip);
return -ENODEV; return -ENODEV;
} }
snd_cs4236_ctrl_out(chip, 0, 0x00); snd_cs4236_ctrl_out(chip, 0, 0x00);
......
...@@ -1655,36 +1655,6 @@ static void snd_wss_resume(struct snd_wss *chip) ...@@ -1655,36 +1655,6 @@ static void snd_wss_resume(struct snd_wss *chip)
} }
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
static int snd_wss_free(struct snd_wss *chip)
{
release_and_free_resource(chip->res_port);
release_and_free_resource(chip->res_cport);
if (chip->irq >= 0) {
disable_irq(chip->irq);
if (!(chip->hwshare & WSS_HWSHARE_IRQ))
free_irq(chip->irq, (void *) chip);
}
if (!(chip->hwshare & WSS_HWSHARE_DMA1) && chip->dma1 >= 0) {
snd_dma_disable(chip->dma1);
free_dma(chip->dma1);
}
if (!(chip->hwshare & WSS_HWSHARE_DMA2) &&
chip->dma2 >= 0 && chip->dma2 != chip->dma1) {
snd_dma_disable(chip->dma2);
free_dma(chip->dma2);
}
if (chip->timer)
snd_device_free(chip->card, chip->timer);
kfree(chip);
return 0;
}
static int snd_wss_dev_free(struct snd_device *device)
{
struct snd_wss *chip = device->device_data;
return snd_wss_free(chip);
}
const char *snd_wss_chip_id(struct snd_wss *chip) const char *snd_wss_chip_id(struct snd_wss *chip)
{ {
switch (chip->hardware) { switch (chip->hardware) {
...@@ -1738,7 +1708,7 @@ static int snd_wss_new(struct snd_card *card, ...@@ -1738,7 +1708,7 @@ static int snd_wss_new(struct snd_card *card,
struct snd_wss *chip; struct snd_wss *chip;
*rchip = NULL; *rchip = NULL;
chip = kzalloc(sizeof(*chip), GFP_KERNEL); chip = devm_kzalloc(card->dev, sizeof(*chip), GFP_KERNEL);
if (chip == NULL) if (chip == NULL)
return -ENOMEM; return -ENOMEM;
chip->hardware = hardware; chip->hardware = hardware;
...@@ -1774,9 +1744,6 @@ int snd_wss_create(struct snd_card *card, ...@@ -1774,9 +1744,6 @@ int snd_wss_create(struct snd_card *card,
unsigned short hwshare, unsigned short hwshare,
struct snd_wss **rchip) struct snd_wss **rchip)
{ {
static const struct snd_device_ops ops = {
.dev_free = snd_wss_dev_free,
};
struct snd_wss *chip; struct snd_wss *chip;
int err; int err;
...@@ -1788,42 +1755,39 @@ int snd_wss_create(struct snd_card *card, ...@@ -1788,42 +1755,39 @@ int snd_wss_create(struct snd_card *card,
chip->dma1 = -1; chip->dma1 = -1;
chip->dma2 = -1; chip->dma2 = -1;
chip->res_port = request_region(port, 4, "WSS"); chip->res_port = devm_request_region(card->dev, port, 4, "WSS");
if (!chip->res_port) { if (!chip->res_port) {
snd_printk(KERN_ERR "wss: can't grab port 0x%lx\n", port); snd_printk(KERN_ERR "wss: can't grab port 0x%lx\n", port);
snd_wss_free(chip);
return -EBUSY; return -EBUSY;
} }
chip->port = port; chip->port = port;
if ((long)cport >= 0) { if ((long)cport >= 0) {
chip->res_cport = request_region(cport, 8, "CS4232 Control"); chip->res_cport = devm_request_region(card->dev, cport, 8,
"CS4232 Control");
if (!chip->res_cport) { if (!chip->res_cport) {
snd_printk(KERN_ERR snd_printk(KERN_ERR
"wss: can't grab control port 0x%lx\n", cport); "wss: can't grab control port 0x%lx\n", cport);
snd_wss_free(chip);
return -ENODEV; return -ENODEV;
} }
} }
chip->cport = cport; chip->cport = cport;
if (!(hwshare & WSS_HWSHARE_IRQ)) if (!(hwshare & WSS_HWSHARE_IRQ))
if (request_irq(irq, snd_wss_interrupt, 0, if (devm_request_irq(card->dev, irq, snd_wss_interrupt, 0,
"WSS", (void *) chip)) { "WSS", (void *) chip)) {
snd_printk(KERN_ERR "wss: can't grab IRQ %d\n", irq); snd_printk(KERN_ERR "wss: can't grab IRQ %d\n", irq);
snd_wss_free(chip);
return -EBUSY; return -EBUSY;
} }
chip->irq = irq; chip->irq = irq;
card->sync_irq = chip->irq; card->sync_irq = chip->irq;
if (!(hwshare & WSS_HWSHARE_DMA1) && request_dma(dma1, "WSS - 1")) { if (!(hwshare & WSS_HWSHARE_DMA1) &&
snd_devm_request_dma(card->dev, dma1, "WSS - 1")) {
snd_printk(KERN_ERR "wss: can't grab DMA1 %d\n", dma1); snd_printk(KERN_ERR "wss: can't grab DMA1 %d\n", dma1);
snd_wss_free(chip);
return -EBUSY; return -EBUSY;
} }
chip->dma1 = dma1; chip->dma1 = dma1;
if (!(hwshare & WSS_HWSHARE_DMA2) && dma1 != dma2 && if (!(hwshare & WSS_HWSHARE_DMA2) && dma1 != dma2 && dma2 >= 0 &&
dma2 >= 0 && request_dma(dma2, "WSS - 2")) { snd_devm_request_dma(card->dev, dma2, "WSS - 2")) {
snd_printk(KERN_ERR "wss: can't grab DMA2 %d\n", dma2); snd_printk(KERN_ERR "wss: can't grab DMA2 %d\n", dma2);
snd_wss_free(chip);
return -EBUSY; return -EBUSY;
} }
if (dma1 == dma2 || dma2 < 0) { if (dma1 == dma2 || dma2 < 0) {
...@@ -1839,10 +1803,8 @@ int snd_wss_create(struct snd_card *card, ...@@ -1839,10 +1803,8 @@ int snd_wss_create(struct snd_card *card,
} }
/* global setup */ /* global setup */
if (snd_wss_probe(chip) < 0) { if (snd_wss_probe(chip) < 0)
snd_wss_free(chip);
return -ENODEV; return -ENODEV;
}
snd_wss_init(chip); snd_wss_init(chip);
#if 0 #if 0
...@@ -1853,13 +1815,6 @@ int snd_wss_create(struct snd_card *card, ...@@ -1853,13 +1815,6 @@ int snd_wss_create(struct snd_card *card,
} }
#endif #endif
/* Register device */
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
if (err < 0) {
snd_wss_free(chip);
return err;
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
/* Power Management */ /* Power Management */
chip->suspend = snd_wss_suspend; chip->suspend = snd_wss_suspend;
......
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