All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH v2 68/79] ALSA: opl3sa2: Allocate resources with device-managed APIs
Date: Thu, 15 Jul 2021 09:59:30 +0200	[thread overview]
Message-ID: <20210715075941.23332-69-tiwai@suse.de> (raw)
In-Reply-To: <20210715075941.23332-1-tiwai@suse.de>

This patch converts the resource management in ISA opl3sa2 driver 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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/isa/opl3sa2.c | 60 +++++++++------------------------------------
 1 file changed, 11 insertions(+), 49 deletions(-)

diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c
index 6f42f869928c..bad1490a66a0 100644
--- a/sound/isa/opl3sa2.c
+++ b/sound/isa/opl3sa2.c
@@ -208,7 +208,8 @@ static int snd_opl3sa2_detect(struct snd_card *card)
 	char str[2];
 
 	port = chip->port;
-	chip->res_port = request_region(port, 2, "OPL3-SA control");
+	chip->res_port = devm_request_region(card->dev, port, 2,
+					     "OPL3-SA control");
 	if (!chip->res_port) {
 		snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port);
 		return -EBUSY;
@@ -609,14 +610,6 @@ static int snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip,
 }
 #endif /* CONFIG_PNP */
 
-static void snd_opl3sa2_free(struct snd_card *card)
-{
-	struct snd_opl3sa2 *chip = card->private_data;
-	if (chip->irq >= 0)
-		free_irq(chip->irq, card);
-	release_and_free_resource(chip->res_port);
-}
-
 static int snd_opl3sa2_card_new(struct device *pdev, int dev,
 				struct snd_card **cardp)
 {
@@ -624,8 +617,8 @@ static int snd_opl3sa2_card_new(struct device *pdev, int dev,
 	struct snd_opl3sa2 *chip;
 	int err;
 
-	err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
-			   sizeof(struct snd_opl3sa2), &card);
+	err = snd_devm_card_new(pdev, index[dev], id[dev], THIS_MODULE,
+				sizeof(struct snd_opl3sa2), &card);
 	if (err < 0)
 		return err;
 	strcpy(card->driver, "OPL3SA2");
@@ -633,7 +626,6 @@ static int snd_opl3sa2_card_new(struct device *pdev, int dev,
 	chip = card->private_data;
 	spin_lock_init(&chip->reg_lock);
 	chip->irq = -1;
-	card->private_free = snd_opl3sa2_free;
 	*cardp = card;
 	return 0;
 }
@@ -658,8 +650,8 @@ static int snd_opl3sa2_probe(struct snd_card *card, int dev)
 	err = snd_opl3sa2_detect(card);
 	if (err < 0)
 		return err;
-	err = request_irq(xirq, snd_opl3sa2_interrupt, 0,
-			  "OPL3-SA2", card);
+	err = devm_request_irq(card->dev, xirq, snd_opl3sa2_interrupt, 0,
+			       "OPL3-SA2", card);
 	if (err) {
 		snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq);
 		return -ENODEV;
@@ -737,25 +729,16 @@ static int snd_opl3sa2_pnp_detect(struct pnp_dev *pdev,
 	if (err < 0)
 		return err;
 	err = snd_opl3sa2_pnp(dev, card->private_data, pdev);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 	err = snd_opl3sa2_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_opl3sa2_pnp_remove(struct pnp_dev *pdev)
-{
-	snd_card_free(pnp_get_drvdata(pdev));
-}
-
 #ifdef CONFIG_PM
 static int snd_opl3sa2_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
 {
@@ -771,7 +754,6 @@ static struct pnp_driver opl3sa2_pnp_driver = {
 	.name = "snd-opl3sa2-pnpbios",
 	.id_table = snd_opl3sa2_pnpbiosids,
 	.probe = snd_opl3sa2_pnp_detect,
-	.remove = snd_opl3sa2_pnp_remove,
 #ifdef CONFIG_PM
 	.suspend = snd_opl3sa2_pnp_suspend,
 	.resume = snd_opl3sa2_pnp_resume,
@@ -803,26 +785,16 @@ static int snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard,
 	if (err < 0)
 		return err;
 	err = snd_opl3sa2_pnp(dev, card->private_data, pdev);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 	err = snd_opl3sa2_probe(card, dev);
-	if (err < 0) {
-		snd_card_free(card);
+	if (err < 0)
 		return err;
-	}
 	pnp_set_card_drvdata(pcard, card);
 	dev++;
 	return 0;
 }
 
-static void snd_opl3sa2_pnp_cremove(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_opl3sa2_pnp_csuspend(struct pnp_card_link *pcard, pm_message_t state)
 {
@@ -839,7 +811,6 @@ static struct pnp_card_driver opl3sa2_pnpc_driver = {
 	.name = "snd-opl3sa2-cpnp",
 	.id_table = snd_opl3sa2_pnpids,
 	.probe = snd_opl3sa2_pnp_cdetect,
-	.remove = snd_opl3sa2_pnp_cremove,
 #ifdef CONFIG_PM
 	.suspend = snd_opl3sa2_pnp_csuspend,
 	.resume = snd_opl3sa2_pnp_cresume,
@@ -885,20 +856,12 @@ static int snd_opl3sa2_isa_probe(struct device *pdev,
 	if (err < 0)
 		return err;
 	err = snd_opl3sa2_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_opl3sa2_isa_remove(struct device *devptr,
-				  unsigned int dev)
-{
-	snd_card_free(dev_get_drvdata(devptr));
-}
-
 #ifdef CONFIG_PM
 static int snd_opl3sa2_isa_suspend(struct device *dev, unsigned int n,
 				   pm_message_t state)
@@ -917,7 +880,6 @@ static int snd_opl3sa2_isa_resume(struct device *dev, unsigned int n)
 static struct isa_driver snd_opl3sa2_isa_driver = {
 	.match		= snd_opl3sa2_isa_match,
 	.probe		= snd_opl3sa2_isa_probe,
-	.remove		= snd_opl3sa2_isa_remove,
 #ifdef CONFIG_PM
 	.suspend	= snd_opl3sa2_isa_suspend,
 	.resume		= snd_opl3sa2_isa_resume,
-- 
2.26.2


  parent reply	other threads:[~2021-07-15  8:26 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15  7:58 [PATCH v2 00/79] ALSA: More devres usages Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 01/79] ALSA: core: Add device-managed page allocator helper Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 02/79] ALSA: core: Add managed card creation Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 03/79] ALSA: core: Add device-managed request_dma() Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 04/79] ALSA: doc: Add device-managed resource section Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 05/79] ALSA: intel8x0: Allocate resources with device-managed APIs Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 06/79] ALSA: atiixp: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 07/79] ALSA: hda: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 08/79] ALSA: ad1889: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 09/79] ALSA: als300: " Takashi Iwai
2021-07-20 19:45   ` Nathan Chancellor
2021-07-20 22:18     ` Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 10/79] ALSA: als4000: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 11/79] ALSA: azt3328: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 12/79] ALSA: bt87x: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 13/79] ALSA: cmipci: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 14/79] ALSA: cs4281: " Takashi Iwai
2021-07-20 19:46   ` Nathan Chancellor
2021-07-20 22:17     ` Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 15/79] ALSA: cs5530: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 16/79] ALSA: ens137x: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 17/79] ALSA: es1938: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 18/79] ALSA: es1968: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 19/79] ALSA: fm801: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 20/79] ALSA: maestro3: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 21/79] ALSA: rme32: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 22/79] ALSA: rme96: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 23/79] ALSA: sis7019: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 24/79] ALSA: sonicvibes: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 25/79] ALSA: via82xx: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 26/79] ALSA: ali5451: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 27/79] ALSA: au88x0: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 28/79] ALSA: aw2: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 29/79] ALSA: ca0106: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 30/79] ALSA: cs46xx: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 31/79] ALSA: cs5535audio: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 32/79] ALSA: echoaudio: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 33/79] ALSA: emu10k1: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 34/79] ALSA: emu10k1x: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 35/79] ALSA: ice1712: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 36/79] ALSA: ice1724: " Takashi Iwai
2021-07-15  7:58 ` [PATCH v2 37/79] ALSA: ali5451: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 38/79] ALSA: ice1724: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 39/79] ALSA: korg1212: " Takashi Iwai
2021-07-20 19:41   ` Nathan Chancellor
2021-07-20 22:28     ` Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 40/79] ALSA: lola: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 41/79] ALSA: lx6464es: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 42/79] ALSA: nm256: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 43/79] ALSA: oxygen: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 44/79] ALSA: riptide: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 45/79] ALSA: hdsp: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 46/79] ALSA: hdspm: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 47/79] ALSA: rme9652: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 48/79] ALSA: trident: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 49/79] ALSA: vx: Manage vx_core object with devres Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 50/79] ALSA: vx222: Allocate resources with device-managed APIs Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 51/79] ALSA: ymfpci: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 52/79] ALSA: ad1816a: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 53/79] ALSA: wss: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 54/79] ALSA: sb: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 55/79] ALSA: ad1848: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 56/79] ALSA: adlib: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 57/79] ALSA: als100: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 58/79] ALSA: azt2320: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 59/79] ALSA: cmi8328: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 60/79] ALSA: cmi8330: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 61/79] ALSA: cs423x: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 62/79] ALSA: es1688: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 63/79] ALSA: es18xx: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 64/79] ALSA: galaxy: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 65/79] ALSA: gus: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 66/79] ALSA: msnd: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 67/79] ALSA: opti9xx: " Takashi Iwai
2021-07-15  7:59 ` Takashi Iwai [this message]
2021-07-15  7:59 ` [PATCH v2 69/79] ALSA: sc6000: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 70/79] ALSA: sscape: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 71/79] ALSA: wavefront: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 72/79] ALSA: x86: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 73/79] ALSA: virmidi: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 74/79] ALSA: mtpav: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 75/79] ALSA: serial-u16550: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 76/79] ALSA: mpu401: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 77/79] ALSA: aloop: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 78/79] ALSA: dummy: " Takashi Iwai
2021-07-15  7:59 ` [PATCH v2 79/79] ALSA: pcsp: " Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210715075941.23332-69-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.