ALSA: cs423x: Allocate resources with device-managed APIs
authorTakashi Iwai <tiwai@suse.de>
Thu, 15 Jul 2021 07:59:23 +0000 (09:59 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 19 Jul 2021 14:17:19 +0000 (16:17 +0200)
This patch converts the resource management in ISA cs423x drivers with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper.  The remove callback became
superfluous and dropped.

This should give no user-visible functional changes.

Link: https://lore.kernel.org/r/20210715075941.23332-62-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/isa/cs423x/cs4231.c
sound/isa/cs423x/cs4236.c

index ec054b929214e55324ce775f3402236b685567b8..1e89233853662046f4161a767877ad87f67a8967 100644 (file)
@@ -79,20 +79,20 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n)
        struct snd_wss *chip;
        int error;
 
-       error = snd_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
+       error = snd_devm_card_new(dev, index[n], id[n], THIS_MODULE, 0, &card);
        if (error < 0)
                return error;
 
        error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], dma2[n],
                        WSS_HW_DETECT, 0, &chip);
        if (error < 0)
-               goto out;
+               return error;
 
        card->private_data = chip;
 
        error = snd_wss_pcm(chip, 0);
        if (error < 0)
-               goto out;
+               return error;
 
        strscpy(card->driver, "CS4231", sizeof(card->driver));
        strscpy(card->shortname, chip->pcm->name, sizeof(card->shortname));
@@ -108,11 +108,11 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n)
 
        error = snd_wss_mixer(chip);
        if (error < 0)
-               goto out;
+               return error;
 
        error = snd_wss_timer(chip, 0);
        if (error < 0)
-               goto out;
+               return error;
 
        if (mpu_port[n] > 0 && mpu_port[n] != SNDRV_AUTO_PORT) {
                if (mpu_irq[n] == SNDRV_AUTO_IRQ)
@@ -125,18 +125,10 @@ static int snd_cs4231_probe(struct device *dev, unsigned int n)
 
        error = snd_card_register(card);
        if (error < 0)
-               goto out;
+               return error;
 
        dev_set_drvdata(dev, card);
        return 0;
-
-out:   snd_card_free(card);
-       return error;
-}
-
-static void snd_cs4231_remove(struct device *dev, unsigned int n)
-{
-       snd_card_free(dev_get_drvdata(dev));
 }
 
 #ifdef CONFIG_PM
@@ -164,7 +156,6 @@ static int snd_cs4231_resume(struct device *dev, unsigned int n)
 static struct isa_driver snd_cs4231_driver = {
        .match          = snd_cs4231_match,
        .probe          = snd_cs4231_probe,
-       .remove         = snd_cs4231_remove,
 #ifdef CONFIG_PM
        .suspend        = snd_cs4231_suspend,
        .resume         = snd_cs4231_resume,
index 0b7fd17f8ecca6cc59fe306c6f1cc5298e952ed9..b6bdebd9ef27577618d94ee59433de9cdb777a08 100644 (file)
@@ -76,7 +76,6 @@ static int pnp_registered;
 
 struct snd_card_cs4236 {
        struct snd_wss *chip;
-       struct resource *res_sb_port;
 #ifdef CONFIG_PNP
        struct pnp_dev *wss;
        struct pnp_dev *ctrl;
@@ -309,24 +308,16 @@ static int snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
 #define is_isapnp_selected(dev)                0
 #endif
 
-static void snd_card_cs4236_free(struct snd_card *card)
-{
-       struct snd_card_cs4236 *acard = card->private_data;
-
-       release_and_free_resource(acard->res_sb_port);
-}
-
 static int snd_cs423x_card_new(struct device *pdev, int dev,
                               struct snd_card **cardp)
 {
        struct snd_card *card;
        int err;
 
-       err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
-                          sizeof(struct snd_card_cs4236), &card);
+       err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
+                               sizeof(struct snd_card_cs4236), &card);
        if (err < 0)
                return err;
-       card->private_free = snd_card_cs4236_free;
        *cardp = card;
        return 0;
 }
@@ -340,8 +331,8 @@ static int snd_cs423x_probe(struct snd_card *card, int dev)
 
        acard = card->private_data;
        if (sb_port[dev] > 0 && sb_port[dev] != SNDRV_AUTO_PORT) {
-               acard->res_sb_port = request_region(sb_port[dev], 16, IDENT " SB");
-               if (!acard->res_sb_port) {
+               if (!devm_request_region(card->dev, sb_port[dev], 16,
+                                        IDENT " SB")) {
                        printk(KERN_ERR IDENT ": unable to register SB port at 0x%lx\n", sb_port[dev]);
                        return -EBUSY;
                }
@@ -448,21 +439,12 @@ static int snd_cs423x_isa_probe(struct device *pdev,
        if (err < 0)
                return err;
        err = snd_cs423x_probe(card, dev);
-       if (err < 0) {
-               snd_card_free(card);
+       if (err < 0)
                return err;
-       }
-
        dev_set_drvdata(pdev, card);
        return 0;
 }
 
-static void snd_cs423x_isa_remove(struct device *pdev,
-                                unsigned int dev)
-{
-       snd_card_free(dev_get_drvdata(pdev));
-}
-
 #ifdef CONFIG_PM
 static int snd_cs423x_suspend(struct snd_card *card)
 {
@@ -495,7 +477,6 @@ static int snd_cs423x_isa_resume(struct device *dev, unsigned int n)
 static struct isa_driver cs423x_isa_driver = {
        .match          = snd_cs423x_isa_match,
        .probe          = snd_cs423x_isa_probe,
-       .remove         = snd_cs423x_isa_remove,
 #ifdef CONFIG_PM
        .suspend        = snd_cs423x_isa_suspend,
        .resume         = snd_cs423x_isa_resume,
@@ -539,24 +520,16 @@ static int snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
        err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
        if (err < 0) {
                printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
-               snd_card_free(card);
                return err;
        }
        err = snd_cs423x_probe(card, dev);
-       if (err < 0) {
-               snd_card_free(card);
+       if (err < 0)
                return err;
-       }
        pnp_set_drvdata(pdev, card);
        dev++;
        return 0;
 }
 
-static void snd_cs423x_pnp_remove(struct pnp_dev *pdev)
-{
-       snd_card_free(pnp_get_drvdata(pdev));
-}
-
 #ifdef CONFIG_PM
 static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
 {
@@ -573,7 +546,6 @@ static struct pnp_driver cs423x_pnp_driver = {
        .name = "cs423x-pnpbios",
        .id_table = snd_cs423x_pnpbiosids,
        .probe = snd_cs423x_pnpbios_detect,
-       .remove = snd_cs423x_pnp_remove,
 #ifdef CONFIG_PM
        .suspend        = snd_cs423x_pnp_suspend,
        .resume         = snd_cs423x_pnp_resume,
@@ -601,25 +573,16 @@ static int snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
        if (res < 0) {
                printk(KERN_ERR "isapnp detection failed and probing for " IDENT
                       " is not supported\n");
-               snd_card_free(card);
                return res;
        }
        res = snd_cs423x_probe(card, dev);
-       if (res < 0) {
-               snd_card_free(card);
+       if (res < 0)
                return res;
-       }
        pnp_set_card_drvdata(pcard, card);
        dev++;
        return 0;
 }
 
-static void snd_cs423x_pnpc_remove(struct pnp_card_link *pcard)
-{
-       snd_card_free(pnp_get_card_drvdata(pcard));
-       pnp_set_card_drvdata(pcard, NULL);
-}
-
 #ifdef CONFIG_PM
 static int snd_cs423x_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
 {
@@ -637,7 +600,6 @@ static struct pnp_card_driver cs423x_pnpc_driver = {
        .name = CS423X_ISAPNP_DRIVER,
        .id_table = snd_cs423x_pnpids,
        .probe = snd_cs423x_pnpc_detect,
-       .remove = snd_cs423x_pnpc_remove,
 #ifdef CONFIG_PM
        .suspend        = snd_cs423x_pnpc_suspend,
        .resume         = snd_cs423x_pnpc_resume,