Re: [PATCH v2 14/79] ALSA: cs4281: Allocate resources with device-managed APIs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 20 Jul 2021 21:46:47 +0200,
Nathan Chancellor wrote:
> 
> On Thu, Jul 15, 2021 at 09:58:36AM +0200, Takashi Iwai wrote:
> > This patch converts the resource management in PCI cs4281 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@xxxxxxx>
> > ---
> >  sound/pci/cs4281.c | 112 ++++++++++-----------------------------------
> >  1 file changed, 24 insertions(+), 88 deletions(-)
> > 
> > diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
> > index e122a168c148..f338caf98354 100644
> > --- a/sound/pci/cs4281.c
> > +++ b/sound/pci/cs4281.c
> > @@ -1268,8 +1268,10 @@ static inline int snd_cs4281_create_gameport(struct cs4281 *chip) { return -ENOS
> >  static inline void snd_cs4281_free_gameport(struct cs4281 *chip) { }
> >  #endif /* IS_REACHABLE(CONFIG_GAMEPORT) */
> >  
> > -static int snd_cs4281_free(struct cs4281 *chip)
> > +static void snd_cs4281_free(struct snd_card *card)
> >  {
> > +	struct cs4281 *chip = card->private_data;
> > +
> >  	snd_cs4281_free_gameport(chip);
> >  
> >  	/* Mask interrupts */
> > @@ -1278,49 +1280,20 @@ static int snd_cs4281_free(struct cs4281 *chip)
> >  	snd_cs4281_pokeBA0(chip, BA0_CLKCR1, 0);
> >  	/* Sound System Power Management - Turn Everything OFF */
> >  	snd_cs4281_pokeBA0(chip, BA0_SSPM, 0);
> > -	/* PCI interface - D3 state */
> > -	pci_set_power_state(chip->pci, PCI_D3hot);
> > -
> > -	if (chip->irq >= 0)
> > -		free_irq(chip->irq, chip);
> > -	iounmap(chip->ba0);
> > -	iounmap(chip->ba1);
> > -	pci_release_regions(chip->pci);
> > -	pci_disable_device(chip->pci);
> > -
> > -	kfree(chip);
> > -	return 0;
> > -}
> > -
> > -static int snd_cs4281_dev_free(struct snd_device *device)
> > -{
> > -	struct cs4281 *chip = device->device_data;
> > -	return snd_cs4281_free(chip);
> >  }
> >  
> >  static int snd_cs4281_chip_init(struct cs4281 *chip); /* defined below */
> >  
> >  static int snd_cs4281_create(struct snd_card *card,
> >  			     struct pci_dev *pci,
> > -			     struct cs4281 **rchip,
> >  			     int dual_codec)
> >  {
> >  	struct cs4281 *chip;
> > -	unsigned int tmp;
> >  	int err;
> > -	static const struct snd_device_ops ops = {
> > -		.dev_free =	snd_cs4281_dev_free,
> > -	};
> >  
> > -	*rchip = NULL;
> > -	err = pci_enable_device(pci);
> > +	err = pcim_enable_device(pci);
> >  	if (err < 0)
> >  		return err;
> > -	chip = kzalloc(sizeof(*chip), GFP_KERNEL);
> > -	if (chip == NULL) {
> > -		pci_disable_device(pci);
> > -		return -ENOMEM;
> > -	}
> >  	spin_lock_init(&chip->reg_lock);
> >  	chip->card = card;
> 
> clang warns:
> 
> sound/pci/cs4281.c:1298:2: error: variable 'chip' is uninitialized when used here [-Werror,-Wuninitialized]
>         chip->card = card;
>         ^~~~
> sound/pci/cs4281.c:1291:21: note: initialize the variable 'chip' to silence this warning
>         struct cs4281 *chip;
>                            ^
>                             = NULL
> 1 error generated.

Thanks!  The fix patch is below.  I'll queue it up.


Takashi

-- 8< --
From: Takashi Iwai <tiwai@xxxxxxx>
Subject: [PATCH] ALSA: cs4281: Fix missing chip initialization

The chip variable was forgotten to be initialized properly while
changing the object creation from the own malloc to
card->private_data.  This patch fixes it.

Fixes: 99041fea70d0 ("ALSA: cs4281: Allocate resources with device-managed APIs")
Reported-by: Nathan Chancellor <nathan@xxxxxxxxxx>
Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
---
 sound/pci/cs4281.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index f338caf98354..e7367402b84a 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -1288,7 +1288,7 @@ static int snd_cs4281_create(struct snd_card *card,
 			     struct pci_dev *pci,
 			     int dual_codec)
 {
-	struct cs4281 *chip;
+	struct cs4281 *chip = card->private_data;
 	int err;
 
 	err = pcim_enable_device(pci);
-- 
2.26.2




[Index of Archives]     [ALSA User]     [Linux Audio Users]     [Pulse Audio]     [Kernel Archive]     [Asterisk PBX]     [Photo Sharing]     [Linux Sound]     [Video 4 Linux]     [Gimp]     [Yosemite News]

  Powered by Linux