Commit 4287864e authored by Takashi Iwai's avatar Takashi Iwai

ALSA: cs423x: Allocate resources with device-managed APIs

This patch converts the resource management in ISA cs423x drivers 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-62-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 45782ce0
...@@ -79,20 +79,20 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n) ...@@ -79,20 +79,20 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n)
struct snd_wss *chip; struct snd_wss *chip;
int error; int error;
error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card); error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
if (error < 0) if (error < 0)
return error; return error;
error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], dma2[n], error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], dma2[n],
WSS_HW_DETECT, 0, &chip); WSS_HW_DETECT, 0, &chip);
if (error < 0) if (error < 0)
goto out; return error;
card->private_data = chip; card->private_data = chip;
error = snd_wss_pcm(chip, 0); error = snd_wss_pcm(chip, 0);
if (error < 0) if (error < 0)
goto out; return error;
strscpy(card->driver, "CS4231", sizeof(card->driver)); strscpy(card->driver, "CS4231", sizeof(card->driver));
strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname)); strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
...@@ -108,11 +108,11 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n) ...@@ -108,11 +108,11 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n)
error = snd_wss_mixer(chip); error = snd_wss_mixer(chip);
if (error < 0) if (error < 0)
goto out; return error;
error = snd_wss_timer(chip, 0); error = snd_wss_timer(chip, 0);
if (error < 0) if (error < 0)
goto out; return error;
if (mpu_port[n] > 0 && mpu_port[n] != SNDRV_AUTO_PORT) { if (mpu_port[n] > 0 && mpu_port[n] != SNDRV_AUTO_PORT) {
if (mpu_irq[n] == SNDRV_AUTO_IRQ) if (mpu_irq[n] == SNDRV_AUTO_IRQ)
...@@ -125,18 +125,10 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n) ...@@ -125,18 +125,10 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n)
error = snd_card_register(card); error = snd_card_register(card);
if (error < 0) if (error < 0)
goto out; return error;
dev_set_drvdata(dev, card); dev_set_drvdata(dev, card);
return 0; return 0;
out: snd_card_free(card);
return error;
}
static void snd_cs4231_remove(struct device *dev, unsigned int n)
{
snd_card_free(dev_get_drvdata(dev));
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
...@@ -164,7 +156,6 @@ static int snd_cs4231_resume(struct device *dev, unsigned int n) ...@@ -164,7 +156,6 @@ static int snd_cs4231_resume(struct device *dev, unsigned int n)
static struct isa_driver snd_cs4231_driver = { static struct isa_driver snd_cs4231_driver = {
.match = snd_cs4231_match, .match = snd_cs4231_match,
.probe = snd_cs4231_probe, .probe = snd_cs4231_probe,
.remove = snd_cs4231_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_cs4231_suspend, .suspend = snd_cs4231_suspend,
.resume = snd_cs4231_resume, .resume = snd_cs4231_resume,
......
...@@ -76,7 +76,6 @@ static int pnp_registered; ...@@ -76,7 +76,6 @@ static int pnp_registered;
struct snd_card_cs4236 { struct snd_card_cs4236 {
struct snd_wss *chip; struct snd_wss *chip;
struct resource *res_sb_port;
#ifdef CONFIG_PNP #ifdef CONFIG_PNP
struct pnp_dev *wss; struct pnp_dev *wss;
struct pnp_dev *ctrl; struct pnp_dev *ctrl;
...@@ -309,24 +308,16 @@ static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard, ...@@ -309,24 +308,16 @@ static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
#define is_isapnp_selected(dev) 0 #define is_isapnp_selected(dev) 0
#endif #endif
static void snd_card_cs4236_free(struct snd_card *card)
{
struct snd_card_cs4236 *acard = card->private_data;
release_and_free_resource(acard->res_sb_port);
}
static int snd_cs423x_card_new(struct device *pdev, int dev, static int snd_cs423x_card_new(struct device *pdev, int dev,
struct snd_card **cardp) struct snd_card **cardp)
{ {
struct snd_card *card; struct snd_card *card;
int err; int err;
err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
sizeof(struct snd_card_cs4236), &card); sizeof(struct snd_card_cs4236), &card);
if (err < 0) if (err < 0)
return err; return err;
card->private_free = snd_card_cs4236_free;
*cardp = card; *cardp = card;
return 0; return 0;
} }
...@@ -340,8 +331,8 @@ static int snd_cs423x_probe(struct snd_card *card, int dev) ...@@ -340,8 +331,8 @@ static int snd_cs423x_probe(struct snd_card *card, int dev)
acard = card->private_data; acard = card->private_data;
if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) { if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) {
acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB"); if (!devm_request_region(card->dev, sb_port[dev], 16,
if (!acard->res_sb_port) { IDENT " SB")) {
printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]); printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
return -EBUSY; return -EBUSY;
} }
...@@ -448,21 +439,12 @@ static int snd_cs423x_isa_probe(struct device *pdev, ...@@ -448,21 +439,12 @@ static int snd_cs423x_isa_probe(struct device *pdev,
if (err < 0) if (err < 0)
return err; return err;
err = snd_cs423x_probe(card, dev); err = snd_cs423x_probe(card, dev);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
dev_set_drvdata(pdev, card); dev_set_drvdata(pdev, card);
return 0; return 0;
} }
static void snd_cs423x_isa_remove(struct device *pdev,
unsigned int dev)
{
snd_card_free(dev_get_drvdata(pdev));
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int snd_cs423x_suspend(struct snd_card *card) static int snd_cs423x_suspend(struct snd_card *card)
{ {
...@@ -495,7 +477,6 @@ static int snd_cs423x_isa_resume(struct device *dev, unsigned int n) ...@@ -495,7 +477,6 @@ static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
static struct isa_driver cs423x_isa_driver = { static struct isa_driver cs423x_isa_driver = {
.match = snd_cs423x_isa_match, .match = snd_cs423x_isa_match,
.probe = snd_cs423x_isa_probe, .probe = snd_cs423x_isa_probe,
.remove = snd_cs423x_isa_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_cs423x_isa_suspend, .suspend = snd_cs423x_isa_suspend,
.resume = snd_cs423x_isa_resume, .resume = snd_cs423x_isa_resume,
...@@ -539,24 +520,16 @@ static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev, ...@@ -539,24 +520,16 @@ static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev); err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
if (err < 0) { if (err < 0) {
printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n"); printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
snd_card_free(card);
return err; return err;
} }
err = snd_cs423x_probe(card, dev); err = snd_cs423x_probe(card, dev);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
pnp_set_drvdata(pdev, card); pnp_set_drvdata(pdev, card);
dev++; dev++;
return 0; return 0;
} }
static void snd_cs423x_pnp_remove(struct pnp_dev *pdev)
{
snd_card_free(pnp_get_drvdata(pdev));
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
{ {
...@@ -573,7 +546,6 @@ static struct pnp_driver cs423x_pnp_driver = { ...@@ -573,7 +546,6 @@ static struct pnp_driver cs423x_pnp_driver = {
.name = "cs423x-pnpbios", .name = "cs423x-pnpbios",
.id_table = snd_cs423x_pnpbiosids, .id_table = snd_cs423x_pnpbiosids,
.probe = snd_cs423x_pnpbios_detect, .probe = snd_cs423x_pnpbios_detect,
.remove = snd_cs423x_pnp_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_cs423x_pnp_suspend, .suspend = snd_cs423x_pnp_suspend,
.resume = snd_cs423x_pnp_resume, .resume = snd_cs423x_pnp_resume,
...@@ -601,25 +573,16 @@ static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard, ...@@ -601,25 +573,16 @@ static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
if (res < 0) { if (res < 0) {
printk(KERN_ERR "isapnp detection failed and probing for " IDENT printk(KERN_ERR "isapnp detection failed and probing for " IDENT
" is not supported\n"); " is not supported\n");
snd_card_free(card);
return res; return res;
} }
res = snd_cs423x_probe(card, dev); res = snd_cs423x_probe(card, dev);
if (res < 0) { if (res < 0)
snd_card_free(card);
return res; return res;
}
pnp_set_card_drvdata(pcard, card); pnp_set_card_drvdata(pcard, card);
dev++; dev++;
return 0; return 0;
} }
static void snd_cs423x_pnpc_remove(struct pnp_card_link *pcard)
{
snd_card_free(pnp_get_card_drvdata(pcard));
pnp_set_card_drvdata(pcard, NULL);
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state) static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
{ {
...@@ -637,7 +600,6 @@ static struct pnp_card_driver cs423x_pnpc_driver = { ...@@ -637,7 +600,6 @@ static struct pnp_card_driver cs423x_pnpc_driver = {
.name = CS423X_ISAPNP_DRIVER, .name = CS423X_ISAPNP_DRIVER,
.id_table = snd_cs423x_pnpids, .id_table = snd_cs423x_pnpids,
.probe = snd_cs423x_pnpc_detect, .probe = snd_cs423x_pnpc_detect,
.remove = snd_cs423x_pnpc_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_cs423x_pnpc_suspend, .suspend = snd_cs423x_pnpc_suspend,
.resume = snd_cs423x_pnpc_resume, .resume = snd_cs423x_pnpc_resume,
......
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