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_modem.c | |
parent | ALSA: intel8x0: Allocate resources with device-managed APIs (diff) | |
download | linux-86bde74dbf0944444aea43eb9e647f1ce16c7ade.tar.xz linux-86bde74dbf0944444aea43eb9e647f1ce16c7ade.zip |
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_modem.c')
-rw-r--r-- | sound/pci/atiixp_modem.c | 92 |
1 files changed, 20 insertions, 72 deletions
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c index 9739c3a82777..178dce8ef1e9 100644 --- a/sound/pci/atiixp_modem.c +++ b/sound/pci/atiixp_modem.c @@ -1159,87 +1159,44 @@ static void snd_atiixp_proc_init(struct atiixp_modem *chip) * destructor */ -static int snd_atiixp_free(struct atiixp_modem *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_modem *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_modem **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_modem *chip; + struct atiixp_modem *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 MC97"); - if (err < 0) { - kfree(chip); - pci_disable_device(pci); + err = pcim_iomap_regions(pci, 1 << 0, "ATI IXP MC97"); + 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; } @@ -1251,28 +1208,29 @@ static int snd_atiixp_probe(struct pci_dev *pci, struct atiixp_modem *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, "ATIIXP-MODEM"); strcpy(card->shortname, "ATI IXP Modem"); - 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; err = snd_atiixp_mixer_new(chip, ac97_clock); 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); @@ -1283,26 +1241,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_modem_driver = { .name = KBUILD_MODNAME, .id_table = snd_atiixp_ids, .probe = snd_atiixp_probe, - .remove = snd_atiixp_remove, .driver = { .pm = SND_ATIIXP_PM_OPS, }, |