diff options
author | Takashi Iwai <tiwai@suse.de> | 2021-07-15 09:59:29 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2021-07-19 16:17:24 +0200 |
commit | 2973ee4a5b5495090af6b24d9adbb765bca04aaf (patch) | |
tree | 426f40ed6f1360810de186412de6d61714f36792 /sound/isa/opti9xx/opti92x-ad1848.c | |
parent | 098493041a2ce8a35eada728e136e5a5edfe24ad (diff) |
ALSA: opti9xx: 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.
This should give no user-visible functional changes.
Link: https://lore.kernel.org/r/20210715075941.23332-68-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/isa/opti9xx/opti92x-ad1848.c')
-rw-r--r-- | sound/isa/opti9xx/opti92x-ad1848.c | 80 |
1 files changed, 23 insertions, 57 deletions
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c index 4bd1dc6707fc..8988de8cca96 100644 --- a/sound/isa/opti9xx/opti92x-ad1848.c +++ b/sound/isa/opti9xx/opti92x-ad1848.c @@ -654,16 +654,18 @@ static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id) #endif /* OPTi93X */ -static int snd_opti9xx_read_check(struct snd_opti9xx *chip) +static int snd_opti9xx_read_check(struct snd_card *card, + struct snd_opti9xx *chip) { unsigned char value; #ifdef OPTi93X unsigned long flags; #endif - chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size, - "OPTi9xx MC"); - if (chip->res_mc_base == NULL) + chip->res_mc_base = + devm_request_region(card->dev, chip->mc_base, + chip->mc_base_size, "OPTi9xx MC"); + if (!chip->res_mc_base) return -EBUSY; #ifndef OPTi93X value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)); @@ -671,9 +673,10 @@ static int snd_opti9xx_read_check(struct snd_opti9xx *chip) if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1))) return 0; #else /* OPTi93X */ - chip->res_mc_indir = request_region(chip->mc_indir_index, 2, - "OPTi93x MC"); - if (chip->res_mc_indir == NULL) + chip->res_mc_indir = + devm_request_region(card->dev, chip->mc_indir_index, 2, + "OPTi93x MC"); + if (!chip->res_mc_indir) return -EBUSY; spin_lock_irqsave(&chip->lock, flags); @@ -686,10 +689,10 @@ static int snd_opti9xx_read_check(struct snd_opti9xx *chip) if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value) return 0; - release_and_free_resource(chip->res_mc_indir); + devm_release_resource(card->dev, chip->res_mc_indir); chip->res_mc_indir = NULL; #endif /* OPTi93X */ - release_and_free_resource(chip->res_mc_base); + devm_release_resource(card->dev, chip->res_mc_base); chip->res_mc_base = NULL; return -ENODEV; @@ -709,7 +712,7 @@ static int snd_card_opti9xx_detect(struct snd_card *card, if (err < 0) return err; - err = snd_opti9xx_read_check(chip); + err = snd_opti9xx_read_check(card, chip); if (err == 0) return 1; #ifdef OPTi93X @@ -789,22 +792,6 @@ static int snd_card_opti9xx_pnp(struct snd_opti9xx *chip, } #endif /* CONFIG_PNP */ -static void snd_card_opti9xx_free(struct snd_card *card) -{ - struct snd_opti9xx *chip = card->private_data; - - if (chip) { -#ifdef OPTi93X - if (chip->irq > 0) { - disable_irq(chip->irq); - free_irq(chip->irq, chip); - } - release_and_free_resource(chip->res_mc_indir); -#endif - release_and_free_resource(chip->res_mc_base); - } -} - static int snd_opti9xx_probe(struct snd_card *card) { static const long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1}; @@ -860,8 +847,8 @@ static int snd_opti9xx_probe(struct snd_card *card) return error; #endif #ifdef OPTi93X - error = request_irq(irq, snd_opti93x_interrupt, - 0, DEV_NAME" - WSS", chip); + error = devm_request_irq(card->dev, irq, snd_opti93x_interrupt, + 0, DEV_NAME" - WSS", chip); if (error < 0) { snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq); return error; @@ -931,11 +918,10 @@ static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp) struct snd_card *card; int err; - err = snd_card_new(pdev, index, id, THIS_MODULE, - sizeof(struct snd_opti9xx), &card); + err = snd_devm_card_new(pdev, index, id, THIS_MODULE, + sizeof(struct snd_opti9xx), &card); if (err < 0) return err; - card->private_free = snd_card_opti9xx_free; *cardp = card; return 0; } @@ -1012,25 +998,15 @@ static int snd_opti9xx_isa_probe(struct device *devptr, return error; error = snd_card_opti9xx_detect(card, card->private_data); - if (error < 0) { - snd_card_free(card); + if (error < 0) return error; - } error = snd_opti9xx_probe(card); - if (error < 0) { - snd_card_free(card); + if (error < 0) return error; - } dev_set_drvdata(devptr, card); return 0; } -static void snd_opti9xx_isa_remove(struct device *devptr, - unsigned int dev) -{ - snd_card_free(dev_get_drvdata(devptr)); -} - #ifdef CONFIG_PM static int snd_opti9xx_suspend(struct snd_card *card) { @@ -1075,7 +1051,6 @@ static int snd_opti9xx_isa_resume(struct device *dev, unsigned int n) static struct isa_driver snd_opti9xx_driver = { .match = snd_opti9xx_isa_match, .probe = snd_opti9xx_isa_probe, - .remove = snd_opti9xx_isa_remove, #ifdef CONFIG_PM .suspend = snd_opti9xx_isa_suspend, .resume = snd_opti9xx_isa_resume, @@ -1114,26 +1089,19 @@ static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard, hw = OPTi9XX_HW_82C931; break; default: - snd_card_free(card); return -ENODEV; } error = snd_opti9xx_init(chip, hw); - if (error) { - snd_card_free(card); + if (error) return error; - } - error = snd_opti9xx_read_check(chip); - if (error) { + error = snd_opti9xx_read_check(card, chip); + if (error) snd_printk(KERN_ERR "OPTI chip not found\n"); - snd_card_free(card); return error; - } error = snd_opti9xx_probe(card); - if (error < 0) { - snd_card_free(card); + if (error < 0) return error; - } pnp_set_card_drvdata(pcard, card); snd_opti9xx_pnp_is_probed = 1; return 0; @@ -1141,8 +1109,6 @@ static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard, static void snd_opti9xx_pnp_remove(struct pnp_card_link *pcard) { - snd_card_free(pnp_get_card_drvdata(pcard)); - pnp_set_card_drvdata(pcard, NULL); snd_opti9xx_pnp_is_probed = 0; } |