ALSA: fm801: move to pcim_* and devm_* functions
authorAndy Shevchenko <andy.shevchenko@gmail.com>
Tue, 6 Jan 2015 23:40:17 +0000 (01:40 +0200)
committerTakashi Iwai <tiwai@suse.de>
Wed, 7 Jan 2015 14:53:55 +0000 (15:53 +0100)
The managed functions allow to get ->probe() and ->remove() simplier.
This patch converts code to use managed functions.

While here remove the dead code and fix the value printed in error
message.

[removed pci_release_regions() as it's managed in pcim_release(), too
  -- tiwai]

Signed-off-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/fm801.c

index d167afffce5fb5dcda4e20abea2df7a8d275682d..dd6f23fbbdf90d36882b501dd2beaac51521bd4a 100644 (file)
@@ -1186,12 +1186,6 @@ static int snd_fm801_free(struct fm801 *chip)
                v4l2_device_unregister(&chip->v4l2_dev);
        }
 #endif
-       if (chip->irq >= 0)
-               free_irq(chip->irq, chip);
-       pci_release_regions(chip->pci);
-       pci_disable_device(chip->pci);
-
-       kfree(chip);
        return 0;
 }
 
@@ -1214,28 +1208,23 @@ static int snd_fm801_create(struct snd_card *card,
        };
 
        *rchip = NULL;
-       if ((err = pci_enable_device(pci)) < 0)
+       if ((err = pcim_enable_device(pci)) < 0)
                return err;
-       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
-       if (chip == NULL) {
-               pci_disable_device(pci);
+       chip = devm_kzalloc(&pci->dev, sizeof(*chip), GFP_KERNEL);
+       if (chip == NULL)
                return -ENOMEM;
-       }
        spin_lock_init(&chip->reg_lock);
        chip->card = card;
        chip->pci = pci;
        chip->irq = -1;
        chip->tea575x_tuner = tea575x_tuner;
-       if ((err = pci_request_regions(pci, "FM801")) < 0) {
-               kfree(chip);
-               pci_disable_device(pci);
+       if ((err = pci_request_regions(pci, "FM801")) < 0)
                return err;
-       }
        chip->port = pci_resource_start(pci, 0);
        if ((tea575x_tuner & TUNER_ONLY) == 0) {
-               if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,
-                               KBUILD_MODNAME, chip)) {
-                       dev_err(card->dev, "unable to grab IRQ %d\n", chip->irq);
+               if (devm_request_irq(&pci->dev, pci->irq, snd_fm801_interrupt,
+                               IRQF_SHARED, KBUILD_MODNAME, chip)) {
+                       dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
                        snd_fm801_free(chip);
                        return -EBUSY;
                }
@@ -1250,12 +1239,6 @@ static int snd_fm801_create(struct snd_card *card,
        /* init might set tuner access method */
        tea575x_tuner = chip->tea575x_tuner;
 
-       if (chip->irq >= 0 && (tea575x_tuner & TUNER_ONLY)) {
-               pci_clear_master(pci);
-               free_irq(chip->irq, chip);
-               chip->irq = -1;
-       }
-
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
                snd_fm801_free(chip);
                return err;