diff options
author | Takashi Iwai <tiwai@suse.de> | 2021-07-15 09:58:28 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2021-07-19 16:16:37 +0200 |
commit | 86bde74dbf0944444aea43eb9e647f1ce16c7ade (patch) | |
tree | 730fd608611ae9e3e8309753f5b678211a8a9637 /sound/pci/atiixp.c | |
parent | 7835e0901e245aa8b83d7e2964f17088cb2e1f1e (diff) |
ALSA: atiixp: Allocate resources with device-managed APIs
Like the previous patch, this patch converts the resource allocations
with device-managed API calls, so that we can reduce resource-free
calls.
The atiixp drivers are simpler than intel8x0, and even the irq can be
allocated with devres.
The end result is a good amount of code reduction.
Link: https://lore.kernel.org/r/20210715075941.23332-7-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/atiixp.c')
-rw-r--r-- | sound/pci/atiixp.c | 92 |
1 files changed, 20 insertions, 72 deletions
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c index 5f8aa35c4bea..b8e035d5930d 100644 --- a/sound/pci/atiixp.c +++ b/sound/pci/atiixp.c @@ -1530,87 +1530,44 @@ static void snd_atiixp_proc_init(struct atiixp *chip) * destructor */ -static int snd_atiixp_free(struct atiixp *chip) +static void snd_atiixp_free(struct snd_card *card) { - if (chip->irq < 0) - goto __hw_end; - snd_atiixp_chip_stop(chip); - - __hw_end: - if (chip->irq >= 0) - free_irq(chip->irq, chip); - iounmap(chip->remap_addr); - pci_release_regions(chip->pci); - pci_disable_device(chip->pci); - kfree(chip); - return 0; -} - -static int snd_atiixp_dev_free(struct snd_device *device) -{ - struct atiixp *chip = device->device_data; - return snd_atiixp_free(chip); + snd_atiixp_chip_stop(card->private_data); } /* * constructor for chip instance */ -static int snd_atiixp_create(struct snd_card *card, - struct pci_dev *pci, - struct atiixp **r_chip) +static int snd_atiixp_init(struct snd_card *card, struct pci_dev *pci) { - static const struct snd_device_ops ops = { - .dev_free = snd_atiixp_dev_free, - }; - struct atiixp *chip; + struct atiixp *chip = card->private_data; int err; - err = pci_enable_device(pci); + err = pcim_enable_device(pci); if (err < 0) return err; - chip = kzalloc(sizeof(*chip), GFP_KERNEL); - if (chip == NULL) { - pci_disable_device(pci); - return -ENOMEM; - } - spin_lock_init(&chip->reg_lock); mutex_init(&chip->open_mutex); chip->card = card; chip->pci = pci; chip->irq = -1; - err = pci_request_regions(pci, "ATI IXP AC97"); - if (err < 0) { - pci_disable_device(pci); - kfree(chip); + err = pcim_iomap_regions(pci, 1 << 0, "ATI IXP AC97"); + if (err < 0) return err; - } chip->addr = pci_resource_start(pci, 0); - chip->remap_addr = pci_ioremap_bar(pci, 0); - if (chip->remap_addr == NULL) { - dev_err(card->dev, "AC'97 space ioremap problem\n"); - snd_atiixp_free(chip); - return -EIO; - } + chip->remap_addr = pcim_iomap_table(pci)[0]; - if (request_irq(pci->irq, snd_atiixp_interrupt, IRQF_SHARED, - KBUILD_MODNAME, chip)) { + if (devm_request_irq(&pci->dev, pci->irq, snd_atiixp_interrupt, + IRQF_SHARED, KBUILD_MODNAME, chip)) { dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); - snd_atiixp_free(chip); return -EBUSY; } chip->irq = pci->irq; card->sync_irq = chip->irq; + card->private_free = snd_atiixp_free; pci_set_master(pci); - err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); - if (err < 0) { - snd_atiixp_free(chip); - return err; - } - - *r_chip = chip; return 0; } @@ -1622,30 +1579,31 @@ static int snd_atiixp_probe(struct pci_dev *pci, struct atiixp *chip; int err; - err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card); + err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, + sizeof(*chip), &card); if (err < 0) return err; + chip = card->private_data; strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA"); strcpy(card->shortname, "ATI IXP"); - err = snd_atiixp_create(card, pci, &chip); + err = snd_atiixp_init(card, pci); if (err < 0) - goto __error; - card->private_data = chip; + return err; err = snd_atiixp_aclink_reset(chip); if (err < 0) - goto __error; + return err; chip->spdif_over_aclink = spdif_aclink; err = snd_atiixp_mixer_new(chip, ac97_clock, ac97_quirk); if (err < 0) - goto __error; + return err; err = snd_atiixp_pcm_new(chip); if (err < 0) - goto __error; + return err; snd_atiixp_proc_init(chip); @@ -1659,26 +1617,16 @@ static int snd_atiixp_probe(struct pci_dev *pci, err = snd_card_register(card); if (err < 0) - goto __error; + return err; pci_set_drvdata(pci, card); return 0; - - __error: - snd_card_free(card); - return err; -} - -static void snd_atiixp_remove(struct pci_dev *pci) -{ - snd_card_free(pci_get_drvdata(pci)); } static struct pci_driver atiixp_driver = { .name = KBUILD_MODNAME, .id_table = snd_atiixp_ids, .probe = snd_atiixp_probe, - .remove = snd_atiixp_remove, .driver = { .pm = SND_ATIIXP_PM_OPS, }, |