[alsa-devel] ALSA: hda/realtek - Allow NULL bus->pci

Takashi Iwai tiwai at suse.de
Wed Oct 8 12:12:22 CEST 2014


At Wed, 8 Oct 2014 12:32:46 +0300,
Dan Carpenter wrote:
> 
> Hello Takashi Iwai,
> 
> The patch 5100cd07d43a: "ALSA: hda/realtek - Allow NULL bus->pci"
> from Feb 15, 2014, leads to the following static checker warning:
> 
> 	sound/pci/hda/patch_realtek.c:5371 patch_alc269()
> 	warn: variable dereferenced before check 'codec->bus->pci' (see line 5364)
> 
> sound/pci/hda/patch_realtek.c
>   5363          if (has_cdefine_beep(codec))
>                                      ^^^^^
> We actually dereference "codec->bus->pci" inside the call to
> has_cdefine_beep().

Indeed.  I fixed snd_pci_quirk_lookup() itself to accept NULL pointer
as a generic fix in below.


Thanks!

Takashi

-- 8< --
From: Takashi Iwai <tiwai at suse.de>
Subject: [PATCH] ALSA: Allow pass NULL dev for snd_pci_quirk_lookup()

Add a NULL check in snd_pci_quirk_lookup() so that NULL can be passed
as a pci_dev pointer.  This fixes the possible NULL dereferences in
HD-audio drivers.

Reported-by: Dan Carpenter <dan.carpenter at oracle.com>
Signed-off-by: Takashi Iwai <tiwai at suse.de>
---
 sound/core/misc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sound/core/misc.c b/sound/core/misc.c
index 30e027ecf4da..f2e8226c88fb 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -145,6 +145,8 @@ EXPORT_SYMBOL(snd_pci_quirk_lookup_id);
 const struct snd_pci_quirk *
 snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
 {
+	if (!pci)
+		return NULL;
 	return snd_pci_quirk_lookup_id(pci->subsystem_vendor,
 				       pci->subsystem_device,
 				       list);
-- 
2.1.2



More information about the Alsa-devel mailing list