diff mbox

ALSA: hda/realtek - Allow NULL bus->pci

Message ID s5ha956vpix.wl-tiwai@suse.de (mailing list archive)
State Accepted
Commit e5b50ada76f44c8742a123813689bff4db062a5a
Headers show

Commit Message

Takashi Iwai Oct. 8, 2014, 10:12 a.m. UTC
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@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@oracle.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/core/misc.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox

Patch

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);