Commit 6bf39b5d authored by Takashi Iwai's avatar Takashi Iwai

ALSA: opl3sa2: Allocate resources with device-managed APIs

This patch converts the resource management in ISA opl3sa2 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-69-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 2973ee4a
...@@ -208,7 +208,8 @@ static int snd_opl3sa2_detect(struct snd_card *card) ...@@ -208,7 +208,8 @@ static int snd_opl3sa2_detect(struct snd_card *card)
char str[2]; char str[2];
port = chip->port; port = chip->port;
chip->res_port = request_region(port, 2, "OPL3-SA control"); chip->res_port = devm_request_region(card->dev, port, 2,
"OPL3-SA control");
if (!chip->res_port) { if (!chip->res_port) {
snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port); snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port);
return -EBUSY; return -EBUSY;
...@@ -609,14 +610,6 @@ static int snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, ...@@ -609,14 +610,6 @@ static int snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip,
} }
#endif /* CONFIG_PNP */ #endif /* CONFIG_PNP */
static void snd_opl3sa2_free(struct snd_card *card)
{
struct snd_opl3sa2 *chip = card->private_data;
if (chip->irq >= 0)
free_irq(chip->irq, card);
release_and_free_resource(chip->res_port);
}
static int snd_opl3sa2_card_new(struct device *pdev, int dev, static int snd_opl3sa2_card_new(struct device *pdev, int dev,
struct snd_card **cardp) struct snd_card **cardp)
{ {
...@@ -624,7 +617,7 @@ static int snd_opl3sa2_card_new(struct device *pdev, int dev, ...@@ -624,7 +617,7 @@ static int snd_opl3sa2_card_new(struct device *pdev, int dev,
struct snd_opl3sa2 *chip; struct snd_opl3sa2 *chip;
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_opl3sa2), &card); sizeof(struct snd_opl3sa2), &card);
if (err < 0) if (err < 0)
return err; return err;
...@@ -633,7 +626,6 @@ static int snd_opl3sa2_card_new(struct device *pdev, int dev, ...@@ -633,7 +626,6 @@ static int snd_opl3sa2_card_new(struct device *pdev, int dev,
chip = card->private_data; chip = card->private_data;
spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->reg_lock);
chip->irq = -1; chip->irq = -1;
card->private_free = snd_opl3sa2_free;
*cardp = card; *cardp = card;
return 0; return 0;
} }
...@@ -658,7 +650,7 @@ static int snd_opl3sa2_probe(struct snd_card *card, int dev) ...@@ -658,7 +650,7 @@ static int snd_opl3sa2_probe(struct snd_card *card, int dev)
err = snd_opl3sa2_detect(card); err = snd_opl3sa2_detect(card);
if (err < 0) if (err < 0)
return err; return err;
err = request_irq(xirq, snd_opl3sa2_interrupt, 0, err = devm_request_irq(card->dev, xirq, snd_opl3sa2_interrupt, 0,
"OPL3-SA2", card); "OPL3-SA2", card);
if (err) { if (err) {
snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq); snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq);
...@@ -737,25 +729,16 @@ static int snd_opl3sa2_pnp_detect(struct pnp_dev *pdev, ...@@ -737,25 +729,16 @@ static int snd_opl3sa2_pnp_detect(struct pnp_dev *pdev,
if (err < 0) if (err < 0)
return err; return err;
err = snd_opl3sa2_pnp(dev, card->private_data, pdev); err = snd_opl3sa2_pnp(dev, card->private_data, pdev);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
err = snd_opl3sa2_probe(card, dev); err = snd_opl3sa2_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_opl3sa2_pnp_remove(struct pnp_dev *pdev)
{
snd_card_free(pnp_get_drvdata(pdev));
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int snd_opl3sa2_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) static int snd_opl3sa2_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
{ {
...@@ -771,7 +754,6 @@ static struct pnp_driver opl3sa2_pnp_driver = { ...@@ -771,7 +754,6 @@ static struct pnp_driver opl3sa2_pnp_driver = {
.name = "snd-opl3sa2-pnpbios", .name = "snd-opl3sa2-pnpbios",
.id_table = snd_opl3sa2_pnpbiosids, .id_table = snd_opl3sa2_pnpbiosids,
.probe = snd_opl3sa2_pnp_detect, .probe = snd_opl3sa2_pnp_detect,
.remove = snd_opl3sa2_pnp_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_opl3sa2_pnp_suspend, .suspend = snd_opl3sa2_pnp_suspend,
.resume = snd_opl3sa2_pnp_resume, .resume = snd_opl3sa2_pnp_resume,
...@@ -803,26 +785,16 @@ static int snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard, ...@@ -803,26 +785,16 @@ static int snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard,
if (err < 0) if (err < 0)
return err; return err;
err = snd_opl3sa2_pnp(dev, card->private_data, pdev); err = snd_opl3sa2_pnp(dev, card->private_data, pdev);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
err = snd_opl3sa2_probe(card, dev); err = snd_opl3sa2_probe(card, dev);
if (err < 0) { if (err < 0)
snd_card_free(card);
return err; return err;
}
pnp_set_card_drvdata(pcard, card); pnp_set_card_drvdata(pcard, card);
dev++; dev++;
return 0; return 0;
} }
static void snd_opl3sa2_pnp_cremove(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_opl3sa2_pnp_csuspend(struct pnp_card_link *pcard, pm_message_t state) static int snd_opl3sa2_pnp_csuspend(struct pnp_card_link *pcard, pm_message_t state)
{ {
...@@ -839,7 +811,6 @@ static struct pnp_card_driver opl3sa2_pnpc_driver = { ...@@ -839,7 +811,6 @@ static struct pnp_card_driver opl3sa2_pnpc_driver = {
.name = "snd-opl3sa2-cpnp", .name = "snd-opl3sa2-cpnp",
.id_table = snd_opl3sa2_pnpids, .id_table = snd_opl3sa2_pnpids,
.probe = snd_opl3sa2_pnp_cdetect, .probe = snd_opl3sa2_pnp_cdetect,
.remove = snd_opl3sa2_pnp_cremove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_opl3sa2_pnp_csuspend, .suspend = snd_opl3sa2_pnp_csuspend,
.resume = snd_opl3sa2_pnp_cresume, .resume = snd_opl3sa2_pnp_cresume,
...@@ -885,20 +856,12 @@ static int snd_opl3sa2_isa_probe(struct device *pdev, ...@@ -885,20 +856,12 @@ static int snd_opl3sa2_isa_probe(struct device *pdev,
if (err < 0) if (err < 0)
return err; return err;
err = snd_opl3sa2_probe(card, dev); err = snd_opl3sa2_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_opl3sa2_isa_remove(struct device *devptr,
unsigned int dev)
{
snd_card_free(dev_get_drvdata(devptr));
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int snd_opl3sa2_isa_suspend(struct device *dev, unsigned int n, static int snd_opl3sa2_isa_suspend(struct device *dev, unsigned int n,
pm_message_t state) pm_message_t state)
...@@ -917,7 +880,6 @@ static int snd_opl3sa2_isa_resume(struct device *dev, unsigned int n) ...@@ -917,7 +880,6 @@ static int snd_opl3sa2_isa_resume(struct device *dev, unsigned int n)
static struct isa_driver snd_opl3sa2_isa_driver = { static struct isa_driver snd_opl3sa2_isa_driver = {
.match = snd_opl3sa2_isa_match, .match = snd_opl3sa2_isa_match,
.probe = snd_opl3sa2_isa_probe, .probe = snd_opl3sa2_isa_probe,
.remove = snd_opl3sa2_isa_remove,
#ifdef CONFIG_PM #ifdef CONFIG_PM
.suspend = snd_opl3sa2_isa_suspend, .suspend = snd_opl3sa2_isa_suspend,
.resume = snd_opl3sa2_isa_resume, .resume = snd_opl3sa2_isa_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