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 26/79] ALSA: ali5451: Allocate resources with device-managed APIs
Date: Thu, 15 Jul 2021 09:58:48 +0200	[thread overview]
Message-ID: <20210715075941.23332-27-tiwai@suse.de> (raw)
In-Reply-To: <20210715075941.23332-1-tiwai@suse.de>

This patch converts the resource management in PCI ali5451 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/ali5451/ali5451.c | 88 +++++++++----------------------------
 1 file changed, 20 insertions(+), 68 deletions(-)

diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index 0d66b92466d5..ccbf9e2c72d6 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -1914,22 +1914,14 @@ static SIMPLE_DEV_PM_OPS(ali_pm, ali_suspend, ali_resume);
 #define ALI_PM_OPS	NULL
 #endif /* CONFIG_PM_SLEEP */
 
-static int snd_ali_free(struct snd_ali * codec)
+static void snd_ali_free(struct snd_card *card)
 {
+	struct snd_ali *codec = card->private_data;
+
 	if (codec->hw_initialized)
 		snd_ali_disable_address_interrupt(codec);
-	if (codec->irq >= 0)
-		free_irq(codec->irq, codec);
-	if (codec->port)
-		pci_release_regions(codec->pci);
-	pci_disable_device(codec->pci);
-#ifdef CONFIG_PM_SLEEP
-	kfree(codec->image);
-#endif
 	pci_dev_put(codec->pci_m1533);
 	pci_dev_put(codec->pci_m7101);
-	kfree(codec);
-	return 0;
 }
 
 static int snd_ali_chip_init(struct snd_ali *codec)
@@ -2017,8 +2009,9 @@ static int snd_ali_resources(struct snd_ali *codec)
 		return err;
 	codec->port = pci_resource_start(codec->pci, 0);
 
-	if (request_irq(codec->pci->irq, snd_ali_card_interrupt,
-			IRQF_SHARED, KBUILD_MODNAME, codec)) {
+	if (devm_request_irq(&codec->pci->dev, codec->pci->irq,
+			     snd_ali_card_interrupt,
+			     IRQF_SHARED, KBUILD_MODNAME, codec)) {
 		dev_err(codec->card->dev, "Unable to request irq.\n");
 		return -EBUSY;
 	}
@@ -2027,48 +2020,29 @@ static int snd_ali_resources(struct snd_ali *codec)
 	dev_dbg(codec->card->dev, "resources allocated.\n");
 	return 0;
 }
-static int snd_ali_dev_free(struct snd_device *device)
-{
-	struct snd_ali *codec = device->device_data;
-	snd_ali_free(codec);
-	return 0;
-}
 
 static int snd_ali_create(struct snd_card *card,
 			  struct pci_dev *pci,
 			  int pcm_streams,
-			  int spdif_support,
-			  struct snd_ali **r_ali)
+			  int spdif_support)
 {
 	struct snd_ali *codec;
 	int i, err;
 	unsigned short cmdw;
-	static const struct snd_device_ops ops = {
-		.dev_free = snd_ali_dev_free,
-        };
-
-	*r_ali = NULL;
 
 	dev_dbg(card->dev, "creating ...\n");
 
 	/* 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 31 bits */
 	if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(31))) {
 		dev_err(card->dev,
 			"architecture does not support 31bit PCI busmaster DMA\n");
-		pci_disable_device(pci);
 		return -ENXIO;
 	}
 
-	codec = kzalloc(sizeof(*codec), GFP_KERNEL);
-	if (!codec) {
-		pci_disable_device(pci);
-		return -ENOMEM;
-	}
-
 	spin_lock_init(&codec->reg_lock);
 	spin_lock_init(&codec->voice_alloc);
 
@@ -2089,12 +2063,10 @@ static int snd_ali_create(struct snd_card *card,
 		cmdw |= PCI_COMMAND_IO;
 		pci_write_config_word(pci, PCI_COMMAND, cmdw);
 	}
-	pci_set_master(pci);
 	
-	if (snd_ali_resources(codec)) {
-		snd_ali_free(codec);
+	if (snd_ali_resources(codec))
 		return -EBUSY;
-	}
+	card->private_free = snd_ali_free;
 
 	codec->synth.chmap = 0;
 	codec->synth.chcnt = 0;
@@ -2121,24 +2093,15 @@ static int snd_ali_create(struct snd_card *card,
 	codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL);
 	if (!codec->pci_m1533) {
 		dev_err(card->dev, "cannot find ALi 1533 chip.\n");
-		snd_ali_free(codec);
 		return -ENODEV;
 	}
 	/* M7101: power management */
 	codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL);
 	if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) {
 		dev_err(card->dev, "cannot find ALi 7101 chip.\n");
-		snd_ali_free(codec);
 		return -ENODEV;
 	}
 
-	dev_dbg(card->dev, "snd_device_new is called.\n");
-	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops);
-	if (err < 0) {
-		snd_ali_free(codec);
-		return err;
-	}
-
 	/* initialise synth voices*/
 	for (i = 0; i < ALI_CHANNELS; i++)
 		codec->synth.voices[i].number = i;
@@ -2150,16 +2113,14 @@ static int snd_ali_create(struct snd_card *card,
 	}
 
 #ifdef CONFIG_PM_SLEEP
-	codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL);
+	codec->image = devm_kmalloc(&pci->dev, sizeof(*codec->image),
+				    GFP_KERNEL);
 	if (!codec->image)
 		dev_warn(card->dev, "can't allocate apm buffer\n");
 #endif
 
 	snd_ali_enable_address_interrupt(codec);
 	codec->hw_initialized = 1;
-
-	*r_ali = codec;
-	dev_dbg(card->dev, "created.\n");
 	return 0;
 }
 
@@ -2172,24 +2133,25 @@ static int snd_ali_probe(struct pci_dev *pci,
 
 	dev_dbg(&pci->dev, "probe ...\n");
 
-	err = snd_card_new(&pci->dev, index, id, THIS_MODULE, 0, &card);
+	err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE,
+				sizeof(*codec), &card);
 	if (err < 0)
 		return err;
+	codec = card->private_data;
 
-	err = snd_ali_create(card, pci, pcm_channels, spdif, &codec);
+	err = snd_ali_create(card, pci, pcm_channels, spdif);
 	if (err < 0)
-		goto error;
-	card->private_data = codec;
+		return err;
 
 	dev_dbg(&pci->dev, "mixer building ...\n");
 	err = snd_ali_mixer(codec);
 	if (err < 0)
-		goto error;
+		return err;
 	
 	dev_dbg(&pci->dev, "pcm building ...\n");
 	err = snd_ali_build_pcms(codec);
 	if (err < 0)
-		goto error;
+		return err;
 
 	snd_ali_proc_init(codec);
 
@@ -2202,26 +2164,16 @@ static int snd_ali_probe(struct pci_dev *pci,
 	dev_dbg(&pci->dev, "register card.\n");
 	err = snd_card_register(card);
 	if (err < 0)
-		goto error;
+		return err;
 
 	pci_set_drvdata(pci, card);
 	return 0;
-
- error:
-	snd_card_free(card);
-	return err;
-}
-
-static void snd_ali_remove(struct pci_dev *pci)
-{
-	snd_card_free(pci_get_drvdata(pci));
 }
 
 static struct pci_driver ali5451_driver = {
 	.name = KBUILD_MODNAME,
 	.id_table = snd_ali_ids,
 	.probe = snd_ali_probe,
-	.remove = snd_ali_remove,
 	.driver = {
 		.pm = ALI_PM_OPS,
 	},
-- 
2.26.2


  parent reply	other threads:[~2021-07-15  8:11 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 ` Takashi Iwai [this message]
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 ` [PATCH v2 68/79] ALSA: opl3sa2: " Takashi Iwai
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-27-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.