Commit bddc2ef1 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: sscape: Allocate resources with device-managed APIs

This patch converts the resource management in ISA sscape driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper.  The remove callback became
superfluous and dropped.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-71-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 111601ff
...@@ -327,17 +327,6 @@ static void activate_ad1845_unsafe(unsigned io_base) ...@@ -327,17 +327,6 @@ static void activate_ad1845_unsafe(unsigned io_base)
sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80); sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80);
} }
/*
* Do the necessary ALSA-level cleanup to deallocate our driver ...
*/
static void soundscape_free(struct snd_card *c)
{
struct soundscape *sscape = get_card_soundscape(c);
release_and_free_resource(sscape->io_res);
release_and_free_resource(sscape->wss_res);
free_dma(sscape->chip->dma1);
}
/* /*
* Tell the SoundScape to begin a DMA transfer using the given channel. * Tell the SoundScape to begin a DMA transfer using the given channel.
* All locking issues are left to the caller. * All locking issues are left to the caller.
...@@ -941,7 +930,7 @@ static int create_sscape(int dev, struct snd_card *card) ...@@ -941,7 +930,7 @@ static int create_sscape(int dev, struct snd_card *card)
* Grab IO ports that we will need to probe so that we * Grab IO ports that we will need to probe so that we
* can detect and control this hardware ... * can detect and control this hardware ...
*/ */
io_res = request_region(port[dev], 8, "SoundScape"); io_res = devm_request_region(card->dev, port[dev], 8, "SoundScape");
if (!io_res) { if (!io_res) {
snd_printk(KERN_ERR snd_printk(KERN_ERR
"sscape: can't grab port 0x%lx\n", port[dev]); "sscape: can't grab port 0x%lx\n", port[dev]);
...@@ -949,22 +938,22 @@ static int create_sscape(int dev, struct snd_card *card) ...@@ -949,22 +938,22 @@ static int create_sscape(int dev, struct snd_card *card)
} }
wss_res = NULL; wss_res = NULL;
if (sscape->type == SSCAPE_VIVO) { if (sscape->type == SSCAPE_VIVO) {
wss_res = request_region(wss_port[dev], 4, "SoundScape"); wss_res = devm_request_region(card->dev, wss_port[dev], 4,
"SoundScape");
if (!wss_res) { if (!wss_res) {
snd_printk(KERN_ERR "sscape: can't grab port 0x%lx\n", snd_printk(KERN_ERR "sscape: can't grab port 0x%lx\n",
wss_port[dev]); wss_port[dev]);
err = -EBUSY; return -EBUSY;
goto _release_region;
} }
} }
/* /*
* Grab one DMA channel ... * Grab one DMA channel ...
*/ */
err = request_dma(dma[dev], "SoundScape"); err = snd_devm_request_dma(card->dev, dma[dev], "SoundScape");
if (err < 0) { if (err < 0) {
snd_printk(KERN_ERR "sscape: can't grab DMA %d\n", dma[dev]); snd_printk(KERN_ERR "sscape: can't grab DMA %d\n", dma[dev]);
goto _release_region; return err;
} }
spin_lock_init(&sscape->lock); spin_lock_init(&sscape->lock);
...@@ -975,8 +964,7 @@ static int create_sscape(int dev, struct snd_card *card) ...@@ -975,8 +964,7 @@ static int create_sscape(int dev, struct snd_card *card)
if (!detect_sscape(sscape, wss_port[dev])) { if (!detect_sscape(sscape, wss_port[dev])) {
printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", printk(KERN_ERR "sscape: hardware not detected at 0x%x\n",
sscape->io_base); sscape->io_base);
err = -ENODEV; return -ENODEV;
goto _release_dma;
} }
switch (sscape->type) { switch (sscape->type) {
...@@ -1006,15 +994,13 @@ static int create_sscape(int dev, struct snd_card *card) ...@@ -1006,15 +994,13 @@ static int create_sscape(int dev, struct snd_card *card)
irq_cfg = get_irq_config(sscape->type, irq[dev]); irq_cfg = get_irq_config(sscape->type, irq[dev]);
if (irq_cfg == INVALID_IRQ) { if (irq_cfg == INVALID_IRQ) {
snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]); snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
err = -ENXIO; return -ENXIO;
goto _release_dma;
} }
mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]); mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]);
if (mpu_irq_cfg == INVALID_IRQ) { if (mpu_irq_cfg == INVALID_IRQ) {
snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]); snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
err = -ENXIO; return -ENXIO;
goto _release_dma;
} }
/* /*
...@@ -1060,7 +1046,7 @@ static int create_sscape(int dev, struct snd_card *card) ...@@ -1060,7 +1046,7 @@ static int create_sscape(int dev, struct snd_card *card)
snd_printk(KERN_ERR snd_printk(KERN_ERR
"sscape: No AD1845 device at 0x%lx, IRQ %d\n", "sscape: No AD1845 device at 0x%lx, IRQ %d\n",
wss_port[dev], irq[dev]); wss_port[dev], irq[dev]);
goto _release_dma; return err;
} }
strcpy(card->driver, "SoundScape"); strcpy(card->driver, "SoundScape");
strcpy(card->shortname, name); strcpy(card->shortname, name);
...@@ -1082,7 +1068,7 @@ static int create_sscape(int dev, struct snd_card *card) ...@@ -1082,7 +1068,7 @@ static int create_sscape(int dev, struct snd_card *card)
snd_printk(KERN_ERR "sscape: Failed to create " snd_printk(KERN_ERR "sscape: Failed to create "
"MPU-401 device at 0x%lx\n", "MPU-401 device at 0x%lx\n",
port[dev]); port[dev]);
goto _release_dma; return err;
} }
/* /*
...@@ -1109,24 +1095,7 @@ static int create_sscape(int dev, struct snd_card *card) ...@@ -1109,24 +1095,7 @@ static int create_sscape(int dev, struct snd_card *card)
} }
} }
/*
* Now that we have successfully created this sound card,
* it is safe to store the pointer.
* NOTE: we only register the sound card's "destructor"
* function now that our "constructor" has completed.
*/
card->private_free = soundscape_free;
return 0; return 0;
_release_dma:
free_dma(dma[dev]);
_release_region:
release_and_free_resource(wss_res);
release_and_free_resource(io_res);
return err;
} }
...@@ -1156,8 +1125,8 @@ static int snd_sscape_probe(struct device *pdev, unsigned int dev) ...@@ -1156,8 +1125,8 @@ static int snd_sscape_probe(struct device *pdev, unsigned int dev)
struct soundscape *sscape; struct soundscape *sscape;
int ret; int ret;
ret = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, ret = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
sizeof(struct soundscape), &card); sizeof(struct soundscape), &card);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -1168,24 +1137,15 @@ static int snd_sscape_probe(struct device *pdev, unsigned int dev) ...@@ -1168,24 +1137,15 @@ static int snd_sscape_probe(struct device *pdev, unsigned int dev)
ret = create_sscape(dev, card); ret = create_sscape(dev, card);
if (ret < 0) if (ret < 0)
goto _release_card; return ret;
ret = snd_card_register(card); ret = snd_card_register(card);
if (ret < 0) { if (ret < 0) {
snd_printk(KERN_ERR "sscape: Failed to register sound card\n"); snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
goto _release_card; return ret;
} }
dev_set_drvdata(pdev, card); dev_set_drvdata(pdev, card);
return 0; return 0;
_release_card:
snd_card_free(card);
return ret;
}
static void snd_sscape_remove(struct device *devptr, unsigned int dev)
{
snd_card_free(dev_get_drvdata(devptr));
} }
#define DEV_NAME "sscape" #define DEV_NAME "sscape"
...@@ -1193,7 +1153,6 @@ static void snd_sscape_remove(struct device *devptr, unsigned int dev) ...@@ -1193,7 +1153,6 @@ static void snd_sscape_remove(struct device *devptr, unsigned int dev)
static struct isa_driver snd_sscape_driver = { static struct isa_driver snd_sscape_driver = {
.match = snd_sscape_match, .match = snd_sscape_match,
.probe = snd_sscape_probe, .probe = snd_sscape_probe,
.remove = snd_sscape_remove,
/* FIXME: suspend/resume */ /* FIXME: suspend/resume */
.driver = { .driver = {
.name = DEV_NAME .name = DEV_NAME
...@@ -1244,9 +1203,9 @@ static int sscape_pnp_detect(struct pnp_card_link *pcard, ...@@ -1244,9 +1203,9 @@ static int sscape_pnp_detect(struct pnp_card_link *pcard,
* Create a new ALSA sound card entry, in anticipation * Create a new ALSA sound card entry, in anticipation
* of detecting our hardware ... * of detecting our hardware ...
*/ */
ret = snd_card_new(&pcard->card->dev, ret = snd_devm_card_new(&pcard->card->dev,
index[idx], id[idx], THIS_MODULE, index[idx], id[idx], THIS_MODULE,
sizeof(struct soundscape), &card); sizeof(struct soundscape), &card);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -1277,27 +1236,17 @@ static int sscape_pnp_detect(struct pnp_card_link *pcard, ...@@ -1277,27 +1236,17 @@ static int sscape_pnp_detect(struct pnp_card_link *pcard,
ret = create_sscape(idx, card); ret = create_sscape(idx, card);
if (ret < 0) if (ret < 0)
goto _release_card; return ret;
ret = snd_card_register(card); ret = snd_card_register(card);
if (ret < 0) { if (ret < 0) {
snd_printk(KERN_ERR "sscape: Failed to register sound card\n"); snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
goto _release_card; return ret;
} }
pnp_set_card_drvdata(pcard, card); pnp_set_card_drvdata(pcard, card);
++idx; ++idx;
return 0; return 0;
_release_card:
snd_card_free(card);
return ret;
}
static void sscape_pnp_remove(struct pnp_card_link *pcard)
{
snd_card_free(pnp_get_card_drvdata(pcard));
pnp_set_card_drvdata(pcard, NULL);
} }
static struct pnp_card_driver sscape_pnpc_driver = { static struct pnp_card_driver sscape_pnpc_driver = {
...@@ -1305,7 +1254,6 @@ static struct pnp_card_driver sscape_pnpc_driver = { ...@@ -1305,7 +1254,6 @@ static struct pnp_card_driver sscape_pnpc_driver = {
.name = "sscape", .name = "sscape",
.id_table = sscape_pnpids, .id_table = sscape_pnpids,
.probe = sscape_pnp_detect, .probe = sscape_pnp_detect,
.remove = sscape_pnp_remove,
}; };
#endif /* CONFIG_PNP */ #endif /* CONFIG_PNP */
......
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