All of lore.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: alsa-devel@alsa-project.org
Subject: [PATCH 09/51] ALSA: als4000: Allocate resources with device-managed APIs
Date: Tue, 13 Jul 2021 16:28:15 +0200	[thread overview]
Message-ID: <20210713142857.19654-10-tiwai@suse.de> (raw)
In-Reply-To: <20210713142857.19654-1-tiwai@suse.de>

This patch converts the resource management in PCI als4000 driver with
devres as a clean up.  Each manual resource management is converted
with the corresponding devres helper, and the card object release is
managed now via card->private_free instead of a lowlevel snd_device.

This should give no user-visible functional changes.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/als4000.c | 59 +++++++++++++--------------------------------
 1 file changed, 17 insertions(+), 42 deletions(-)

diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index 509f317ee682..535eccd124be 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -746,13 +746,15 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
 
 	if (joystick_port[dev] == 1) { /* auto-detect */
 		for (io_port = 0x200; io_port <= 0x218; io_port += 8) {
-			r = request_region(io_port, 8, "ALS4000 gameport");
+			r = devm_request_region(&acard->pci->dev, io_port, 8,
+						"ALS4000 gameport");
 			if (r)
 				break;
 		}
 	} else {
 		io_port = joystick_port[dev];
-		r = request_region(io_port, 8, "ALS4000 gameport");
+		r = devm_request_region(&acard->pci->dev, io_port, 8,
+					"ALS4000 gameport");
 	}
 
 	if (!r) {
@@ -763,7 +765,6 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
 	acard->gameport = gp = gameport_allocate_port();
 	if (!gp) {
 		dev_err(&acard->pci->dev, "cannot allocate memory for gameport\n");
-		release_and_free_resource(r);
 		return -ENOMEM;
 	}
 
@@ -771,7 +772,6 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
 	gameport_set_phys(gp, "pci%s/gameport0", pci_name(acard->pci));
 	gameport_set_dev_parent(gp, &acard->pci->dev);
 	gp->io = io_port;
-	gameport_set_port_data(gp, r);
 
 	/* Enable legacy joystick port */
 	snd_als4000_set_addr(acard->iobase, 0, 0, 0, 1);
@@ -784,15 +784,11 @@ static int snd_als4000_create_gameport(struct snd_card_als4000 *acard, int dev)
 static void snd_als4000_free_gameport(struct snd_card_als4000 *acard)
 {
 	if (acard->gameport) {
-		struct resource *r = gameport_get_port_data(acard->gameport);
-
 		gameport_unregister_port(acard->gameport);
 		acard->gameport = NULL;
 
 		/* disable joystick */
 		snd_als4000_set_addr(acard->iobase, 0, 0, 0, 0);
-
-		release_and_free_resource(r);
 	}
 }
 #else
@@ -808,8 +804,6 @@ static void snd_card_als4000_free( struct snd_card *card )
 	snd_als4k_gcr_write_addr(acard->iobase, ALS4K_GCR8C_MISC_CTRL, 0);
 	/* free resources */
 	snd_als4000_free_gameport(acard);
-	pci_release_regions(acard->pci);
-	pci_disable_device(acard->pci);
 }
 
 static int snd_card_als4000_probe(struct pci_dev *pci,
@@ -832,36 +826,30 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
 	}
 
 	/* enable PCI device */
-	err = pci_enable_device(pci);
+	err = pcim_enable_device(pci);
 	if (err < 0)
 		return err;
 
 	/* check, if we can restrict PCI DMA transfers to 24 bits */
 	if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) {
 		dev_err(&pci->dev, "architecture does not support 24bit PCI busmaster DMA\n");
-		pci_disable_device(pci);
 		return -ENXIO;
 	}
 
 	err = pci_request_regions(pci, "ALS4000");
-	if (err < 0) {
-		pci_disable_device(pci);
+	if (err < 0)
 		return err;
-	}
 	iobase = pci_resource_start(pci, 0);
 
 	pci_read_config_word(pci, PCI_COMMAND, &word);
 	pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO);
 	pci_set_master(pci);
 	
-	err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
-			   sizeof(*acard) /* private_data: acard */,
-			   &card);
-	if (err < 0) {
-		pci_release_regions(pci);
-		pci_disable_device(pci);
+	err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
+				sizeof(*acard) /* private_data: acard */,
+				&card);
+	if (err < 0)
 		return err;
-	}
 
 	acard = card->private_data;
 	acard->pci = pci;
@@ -881,7 +869,7 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
 			       SB_HW_ALS4000,
 			       &chip);
 	if (err < 0)
-		goto out_err;
+		return err;
 	acard->chip = chip;
 
 	chip->pci = pci;
@@ -902,7 +890,7 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
 	if (err < 0) {
 		dev_err(&pci->dev, "no MPU-401 device at 0x%lx?\n",
 				iobase + ALS4K_IOB_30_MIDI_DATA);
-		goto out_err;
+		return err;
 	}
 	/* FIXME: ALS4000 has interesting MPU401 configuration features
 	 * at ALS4K_CR1A_MPU401_UART_MODE_CONTROL
@@ -912,11 +900,11 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
 
 	err = snd_als4000_pcm(chip, 0);
 	if (err < 0)
-		goto out_err;
+		return err;
 
 	err = snd_sbmixer_new(chip);
 	if (err < 0)
-		goto out_err;
+		return err;
 
 	if (snd_opl3_create(card,
 				iobase + ALS4K_IOB_10_ADLIB_ADDR0,
@@ -928,30 +916,18 @@ static int snd_card_als4000_probe(struct pci_dev *pci,
 	} else {
 		err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
 		if (err < 0)
-			goto out_err;
+			return err;
 	}
 
 	snd_als4000_create_gameport(acard, dev);
 
 	err = snd_card_register(card);
 	if (err < 0)
-		goto out_err;
+		return err;
 
 	pci_set_drvdata(pci, card);
 	dev++;
-	err = 0;
-	goto out;
-
-out_err:
-	snd_card_free(card);
-	
-out:
-	return err;
-}
-
-static void snd_card_als4000_remove(struct pci_dev *pci)
-{
-	snd_card_free(pci_get_drvdata(pci));
+	return 0;
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -996,7 +972,6 @@ static struct pci_driver als4000_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = snd_als4000_ids,
 	.probe = snd_card_als4000_probe,
-	.remove = snd_card_als4000_remove,
 	.driver = {
 		.pm = SND_ALS4000_PM_OPS,
 	},
-- 
2.26.2


  parent reply	other threads:[~2021-07-13 14:34 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-13 14:28 [PATCH resent 00/51] ALSA: More devres usages Takashi Iwai
2021-07-13 14:28 ` [PATCH 01/51] ALSA: core: Add device-managed page allocator helper Takashi Iwai
2021-07-13 14:28 ` [PATCH 02/51] ALSA: core: Add managed card creation Takashi Iwai
2021-07-13 15:23   ` Amadeusz Sławiński
2021-07-13 16:05     ` Takashi Iwai
2021-07-13 16:15       ` Takashi Iwai
2021-07-13 14:28 ` [PATCH 03/51] ALSA: intel8x0: Allocate resources with device-managed APIs Takashi Iwai
2021-07-13 14:28 ` [PATCH 04/51] ALSA: atiixp: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 05/51] ALSA: hda: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 06/51] ALSA: doc: Add device-managed resource section Takashi Iwai
2021-07-13 14:28 ` [PATCH 07/51] ALSA: ad1889: Allocate resources with device-managed APIs Takashi Iwai
2021-07-13 14:28 ` [PATCH 08/51] ALSA: als300: " Takashi Iwai
2021-07-13 14:28 ` Takashi Iwai [this message]
2021-07-13 14:28 ` [PATCH 10/51] ALSA: azt3328: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 11/51] ALSA: bt87x: " Takashi Iwai
2021-07-13 17:10   ` kernel test robot
2021-07-13 14:28 ` [PATCH 12/51] ALSA: cmipci: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 13/51] ALSA: cs4281: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 14/51] ALSA: cs5530: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 15/51] ALSA: ens137x: " Takashi Iwai
2021-07-13 15:23   ` Amadeusz Sławiński
2021-07-13 16:07     ` Takashi Iwai
2021-07-13 14:28 ` [PATCH 16/51] ALSA: es1938: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 17/51] ALSA: es1968: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 18/51] ALSA: fm801: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 19/51] ALSA: maestro3: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 20/51] ALSA: rme32: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 21/51] ALSA: rme96: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 22/51] ALSA: sis7019: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 23/51] ALSA: sonicvibes: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 24/51] ALSA: via82xx: " Takashi Iwai
2021-07-13 18:40   ` kernel test robot
2021-07-13 14:28 ` [PATCH 25/51] ALSA: ali5451: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 26/51] ALSA: au88x0: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 27/51] ALSA: aw2: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 28/51] ALSA: ca0106: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 29/51] ALSA: cs46xx: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 30/51] ALSA: cs5535audio: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 31/51] ALSA: echoaudio: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 32/51] ALSA: emu10k1: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 33/51] ALSA: emu10k1x: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 34/51] ALSA: ice1712: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 35/51] ALSA: ice1724: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 36/51] ALSA: korg1212: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 37/51] ALSA: lola: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 38/51] ALSA: oxygen: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 39/51] ALSA: riptide: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 40/51] ALSA: hdsp: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 41/51] ALSA: hdspm: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 42/51] ALSA: rme9652: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 43/51] ALSA: trident: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 44/51] ALSA: vx: Manage vx_core object with devres Takashi Iwai
2021-07-13 14:28 ` [PATCH 45/51] ALSA: vx222: Allocate resources with device-managed APIs Takashi Iwai
2021-07-13 14:28 ` [PATCH 46/51] ALSA: ymfpci: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 47/51] ALSA: x86: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 48/51] ALSA: virmidi: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 49/51] ALSA: mtpav: " Takashi Iwai
2021-07-13 14:28 ` [PATCH 50/51] ALSA: serial-u16550: " Takashi Iwai
2021-07-13 16:08   ` Takashi Iwai
2021-07-13 18:39   ` kernel test robot
2021-07-13 14:28 ` [PATCH 51/51] ALSA: mpu401: " Takashi Iwai
  -- strict thread matches above, loose matches on Subject: below --
2021-07-13 14:24 [PATCH 00/51] ALSA: More devres usages Takashi Iwai
2021-07-13 14:24 ` [PATCH 09/51] ALSA: als4000: Allocate resources with device-managed APIs 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=20210713142857.19654-10-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.