ALSA: hda: Allocate resources with device-managed APIs
authorTakashi Iwai <tiwai@suse.de>
Thu, 15 Jul 2021 07:58:29 +0000 (09:58 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 19 Jul 2021 14:16:37 +0000 (16:16 +0200)
This patch is an attempt to slightly simplify the resource management
in HD-audio code, by using some device-managed APIs.  Only a few
resources like PCI enablement and PCI resources managed via devres,
but most of the rest code dealing with HD-audio core stuff couldn't be
changed so much, hence the changes in this patch are pretty small in
the end.  A special caveat is needed for the card object: we can't
move the card object release into devres, because the driver is
involved with the component stuff and its unregistiration doesn't work
well from devres release at all.

Link: https://lore.kernel.org/r/20210715075941.23332-8-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_controller.h
sound/pci/hda/hda_intel.c

index 68f9668788ea2d469041390d79f9c5d1d52e895d..e4b290de81de92ef10f3a887c0ee70ba48360537 100644 (file)
@@ -141,7 +141,6 @@ struct azx {
        unsigned int snoop:1;
        unsigned int uc_buffer:1; /* non-cached pages for stream buffers */
        unsigned int align_buffer_size:1;
-       unsigned int region_requested:1;
        unsigned int disabled:1; /* disabled by vga_switcheroo */
        unsigned int pm_prepared:1;
 
index 0322b289505e7f89196932a2d064a7ed32bdb4b7..4d64f2ce30dc3c9b1ef39b3ba24eabf08ccfaca0 100644 (file)
@@ -1367,18 +1367,11 @@ static void azx_free(struct azx *chip)
 
        if (bus->irq >= 0)
                free_irq(bus->irq, (void*)chip);
-       if (chip->msi)
-               pci_disable_msi(chip->pci);
-       iounmap(bus->remap_addr);
 
        azx_free_stream_pages(chip);
        azx_free_streams(chip);
        snd_hdac_bus_exit(bus);
 
-       if (chip->region_requested)
-               pci_release_regions(chip->pci);
-
-       pci_disable_device(chip->pci);
 #ifdef CONFIG_SND_HDA_PATCH_LOADER
        release_firmware(chip->fw);
 #endif
@@ -1767,15 +1760,13 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
 
        *rchip = NULL;
 
-       err = pci_enable_device(pci);
+       err = pcim_enable_device(pci);
        if (err < 0)
                return err;
 
        hda = devm_kzalloc(&pci->dev, sizeof(*hda), GFP_KERNEL);
-       if (!hda) {
-               pci_disable_device(pci);
+       if (!hda)
                return -ENOMEM;
-       }
 
        chip = &hda->chip;
        mutex_init(&chip->open_mutex);
@@ -1811,10 +1802,8 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
                chip->bdl_pos_adj = bdl_pos_adj[dev];
 
        err = azx_bus_init(chip, model[dev]);
-       if (err < 0) {
-               pci_disable_device(pci);
+       if (err < 0)
                return err;
-       }
 
        /* use the non-cached pages in non-snoop mode */
        if (!azx_snoop(chip))
@@ -1860,17 +1849,12 @@ static int azx_first_init(struct azx *chip)
        }
 #endif
 
-       err = pci_request_regions(pci, "ICH HD audio");
+       err = pcim_iomap_regions(pci, 1 << 0, "ICH HD audio");
        if (err < 0)
                return err;
-       chip->region_requested = 1;
 
        bus->addr = pci_resource_start(pci, 0);
-       bus->remap_addr = pci_ioremap_bar(pci, 0);
-       if (bus->remap_addr == NULL) {
-               dev_err(card->dev, "ioremap error\n");
-               return -ENXIO;
-       }
+       bus->remap_addr = pcim_iomap_table(pci)[0];
 
        if (chip->driver_type == AZX_DRIVER_SKL)
                snd_hdac_bus_parse_capabilities(bus);