ALSA: mpu401: Allocate resources with device-managed APIs
authorTakashi Iwai <tiwai@suse.de>
Thu, 15 Jul 2021 07:59:38 +0000 (09:59 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 19 Jul 2021 14:17:30 +0000 (16:17 +0200)
This patch converts the card object management with devres as a clean
up.  The remove callback gets reduced by that.

This should give no user-visible functional changes.

Note that this converts only the mpu401 card driver.  The mpu401_uart
component is still managed with snd_device.  It's for the case where
the mpu401_uart component may be removed dynamically without the
actual device unbind.

Link: https://lore.kernel.org/r/20210715075941.23332-77-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/drivers/mpu401/mpu401.c

index d0b55dbb411a16ce63e5cab6cdf417873ebd593d..3398aee33baad0a64aadf92b29d2e3dc2da3527c 100644 (file)
@@ -59,8 +59,8 @@ static int snd_mpu401_create(struct device *devptr, int dev,
                snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n");
 
        *rcard = NULL;
-       err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
-                          0, &card);
+       err = snd_devm_card_new(devptr, index[dev], id[dev], THIS_MODULE,
+                               0, &card);
        if (err < 0)
                return err;
        strcpy(card->driver, "MPU-401 UART");
@@ -76,15 +76,11 @@ static int snd_mpu401_create(struct device *devptr, int dev,
                                  irq[dev], NULL);
        if (err < 0) {
                printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
-               goto _err;
+               return err;
        }
 
        *rcard = card;
        return 0;
-
- _err:
-       snd_card_free(card);
-       return err;
 }
 
 static int snd_mpu401_probe(struct platform_device *devptr)
@@ -105,25 +101,16 @@ static int snd_mpu401_probe(struct platform_device *devptr)
        if (err < 0)
                return err;
        err = snd_card_register(card);
-       if (err < 0) {
-               snd_card_free(card);
+       if (err < 0)
                return err;
-       }
        platform_set_drvdata(devptr, card);
        return 0;
 }
 
-static int snd_mpu401_remove(struct platform_device *devptr)
-{
-       snd_card_free(platform_get_drvdata(devptr));
-       return 0;
-}
-
 #define SND_MPU401_DRIVER      "snd_mpu401"
 
 static struct platform_driver snd_mpu401_driver = {
        .probe          = snd_mpu401_probe,
-       .remove         = snd_mpu401_remove,
        .driver         = {
                .name   = SND_MPU401_DRIVER,
        },
@@ -184,10 +171,8 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
                if (err < 0)
                        return err;
                err = snd_card_register(card);
-               if (err < 0) {
-                       snd_card_free(card);
+               if (err < 0)
                        return err;
-               }
                pnp_set_drvdata(pnp_dev, card);
                snd_mpu401_devices++;
                ++dev;
@@ -196,19 +181,10 @@ static int snd_mpu401_pnp_probe(struct pnp_dev *pnp_dev,
        return -ENODEV;
 }
 
-static void snd_mpu401_pnp_remove(struct pnp_dev *dev)
-{
-       struct snd_card *card = (struct snd_card *) pnp_get_drvdata(dev);
-
-       snd_card_disconnect(card);
-       snd_card_free_when_closed(card);
-}
-
 static struct pnp_driver snd_mpu401_pnp_driver = {
        .name = "mpu401",
        .id_table = snd_mpu401_pnpids,
        .probe = snd_mpu401_pnp_probe,
-       .remove = snd_mpu401_pnp_remove,
 };
 #else
 static struct pnp_driver snd_mpu401_pnp_driver;