All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH v2 09/79] ALSA: als300: Allocate resources with device-managed APIs
Date: Tue, 20 Jul 2021 12:45:17 -0700	[thread overview]
Message-ID: <YPcnzVns1kz7wtxd@Ryzen-9-3900X.localdomain> (raw)
In-Reply-To: <20210715075941.23332-10-tiwai@suse.de>

On Thu, Jul 15, 2021 at 09:58:31AM +0200, Takashi Iwai wrote:
> This patch converts the resource management in PCI als300 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/als300.c | 79 ++++++++++------------------------------------
>  1 file changed, 17 insertions(+), 62 deletions(-)
> 
> diff --git a/sound/pci/als300.c b/sound/pci/als300.c
> index 668008fc21f7..9c94072572a5 100644
> --- a/sound/pci/als300.c
> +++ b/sound/pci/als300.c
> @@ -163,21 +163,11 @@ static void snd_als300_set_irq_flag(struct snd_als300 *chip, int cmd)
>  	snd_als300_gcr_write(chip->port, MISC_CONTROL, tmp);
>  }
>  
> -static int snd_als300_free(struct snd_als300 *chip)
> +static void snd_als300_free(struct snd_card *card)
>  {
> -	snd_als300_set_irq_flag(chip, IRQ_DISABLE);
> -	if (chip->irq >= 0)
> -		free_irq(chip->irq, chip);
> -	pci_release_regions(chip->pci);
> -	pci_disable_device(chip->pci);
> -	kfree(chip);
> -	return 0;
> -}
> +	struct snd_als300 *chip = card->private_data;
>  
> -static int snd_als300_dev_free(struct snd_device *device)
> -{
> -	struct snd_als300 *chip = device->device_data;
> -	return snd_als300_free(chip);
> +	snd_als300_set_irq_flag(chip, IRQ_DISABLE);
>  }
>  
>  static irqreturn_t snd_als300_interrupt(int irq, void *dev_id)
> @@ -248,11 +238,6 @@ static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id)
>  	return IRQ_HANDLED;
>  }
>  
> -static void snd_als300_remove(struct pci_dev *pci)
> -{
> -	snd_card_free(pci_get_drvdata(pci));
> -}
> -
>  static unsigned short snd_als300_ac97_read(struct snd_ac97 *ac97,
>  							unsigned short reg)
>  {
> @@ -610,35 +595,22 @@ static void snd_als300_init(struct snd_als300 *chip)
>  }
>  
>  static int snd_als300_create(struct snd_card *card,
> -			     struct pci_dev *pci, int chip_type,
> -			     struct snd_als300 **rchip)
> +			     struct pci_dev *pci, int chip_type)
>  {
> -	struct snd_als300 *chip;
> +	struct snd_als300 *chip = card->private_data;
>  	void *irq_handler;
>  	int err;
>  
> -	static const struct snd_device_ops ops = {
> -		.dev_free = snd_als300_dev_free,
> -	};
> -	*rchip = NULL;
> -
> -	err = pci_enable_device(pci);
> +	err = pcim_enable_device(pci);
>  	if (err < 0)
>  		return err;
>  
>  	if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(28))) {
>  		dev_err(card->dev, "error setting 28bit DMA mask\n");
> -		pci_disable_device(pci);
>  		return -ENXIO;
>  	}
>  	pci_set_master(pci);
>  
> -	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
> -	if (chip == NULL) {
> -		pci_disable_device(pci);
> -		return -ENOMEM;
> -	}
> -
>  	chip->card = card;
>  	chip->pci = pci;
>  	chip->irq = -1;
> @@ -646,11 +618,9 @@ static int snd_als300_create(struct snd_card *card,
>  	spin_lock_init(&chip->reg_lock);
>  
>  	err = pci_request_regions(pci, "ALS300");
> -	if (err < 0) {
> -		kfree(chip);
> -		pci_disable_device(pci);
> +	if (err < 0)
>  		return err;
> -	}
> +
>  	chip->port = pci_resource_start(pci, 0);
>  
>  	if (chip->chip_type == DEVICE_ALS300_PLUS)
> @@ -658,38 +628,29 @@ static int snd_als300_create(struct snd_card *card,
>  	else
>  		irq_handler = snd_als300_interrupt;
>  
> -	if (request_irq(pci->irq, irq_handler, IRQF_SHARED,
> -			KBUILD_MODNAME, chip)) {
> +	if (devm_request_irq(&pci->dev, pci->irq, irq_handler, IRQF_SHARED,
> +			     KBUILD_MODNAME, chip)) {
>  		dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
> -		snd_als300_free(chip);
>  		return -EBUSY;
>  	}
>  	chip->irq = pci->irq;
>  	card->sync_irq = chip->irq;
> +	card->private_free = snd_als300_free;
>  
>  	snd_als300_init(chip);
>  
>  	err = snd_als300_ac97(chip);
>  	if (err < 0) {
>  		dev_err(card->dev, "Could not create ac97\n");
> -		snd_als300_free(chip);
>  		return err;
>  	}
>  
>  	err = snd_als300_new_pcm(chip);
>  	if (err < 0) {
>  		dev_err(card->dev, "Could not create PCM\n");
> -		snd_als300_free(chip);
> -		return err;
> -	}
> -
> -	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
> -	if (err < 0) {
> -		snd_als300_free(chip);
>  		return err;
>  	}
>  
> -	*rchip = chip;
>  	return 0;
>  }
>  
> @@ -737,20 +698,16 @@ static int snd_als300_probe(struct pci_dev *pci,
>  		return -ENOENT;
>  	}
>  
> -	err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
> -			   0, &card);
> -
> +	err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
> +				sizeof(*chip), &card);
>  	if (err < 0)
>  		return err;
>  
>  	chip_type = pci_id->driver_data;
>  
> -	err = snd_als300_create(card, pci, chip_type, &chip);
> -	if (err < 0) {
> -		snd_card_free(card);
> +	err = snd_als300_create(card, pci, chip_type);
> +	if (err < 0)
>  		return err;
> -	}
> -	card->private_data = chip;
>  
>  	strcpy(card->driver, "ALS300");
>  	if (chip->chip_type == DEVICE_ALS300_PLUS)

clang warns:

sound/pci/als300.c:713:6: error: variable 'chip' is uninitialized when used here [-Werror,-Wuninitialized]
        if (chip->chip_type == DEVICE_ALS300_PLUS)
            ^~~~
sound/pci/als300.c:691:25: note: initialize the variable 'chip' to silence this warning
        struct snd_als300 *chip;
                               ^
                                = NULL
1 error generated.

> @@ -764,10 +721,9 @@ static int snd_als300_probe(struct pci_dev *pci,
>  				card->shortname, chip->port, chip->irq);
>  
>  	err = snd_card_register(card);
> -	if (err < 0) {
> -		snd_card_free(card);
> +	if (err < 0)
>  		return err;
> -	}
> +
>  	pci_set_drvdata(pci, card);
>  	dev++;
>  	return 0;
> @@ -777,7 +733,6 @@ static struct pci_driver als300_driver = {
>  	.name = KBUILD_MODNAME,
>  	.id_table = snd_als300_ids,
>  	.probe = snd_als300_probe,
> -	.remove = snd_als300_remove,
>  	.driver = {
>  		.pm = SND_ALS300_PM_OPS,
>  	},
> -- 
> 2.26.2

  reply	other threads:[~2021-07-20 19:46 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 [this message]
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 ` [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=YPcnzVns1kz7wtxd@Ryzen-9-3900X.localdomain \
    --to=nathan@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /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.