linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: Intel: Skylake: fix dereference before NULL check on ebus
@ 2017-04-19 12:16 Colin King
  2017-04-19 13:32 ` Dan Carpenter
  0 siblings, 1 reply; 3+ messages in thread
From: Colin King @ 2017-04-19 12:16 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Vinod Koul, Jeeja KP, Jayachandran B, Subhransu S . Prusty,
	Dharageswari R, Pardha Saradhi K, Yong Zhi, alsa-devel
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

ebus is being NULL checked however it is being dereferenced
earlier on the assignment bus = ebus_to_hbus(ebus).  Fix this
by moving the assignment to after the NULL check on ebus to
avoid a NULL pointer dereference error.

Fixes: c5a76a246989c8 ("ASoC: Intel: Skylake: Add shutdown callback")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 sound/soc/intel/skylake/skl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/soc/intel/skylake/skl.c b/sound/soc/intel/skylake/skl.c
index 0c57d4eaae3a..21369f60fbaa 100644
--- a/sound/soc/intel/skylake/skl.c
+++ b/sound/soc/intel/skylake/skl.c
@@ -818,7 +818,7 @@ static int skl_probe(struct pci_dev *pci,
 static void skl_shutdown(struct pci_dev *pci)
 {
 	struct hdac_ext_bus *ebus = pci_get_drvdata(pci);
-	struct hdac_bus *bus = ebus_to_hbus(ebus);
+	struct hdac_bus *bus;
 	struct hdac_stream *s;
 	struct hdac_ext_stream *stream;
 	struct skl *skl;
@@ -826,6 +826,7 @@ static void skl_shutdown(struct pci_dev *pci)
 	if (ebus == NULL)
 		return;
 
+	bus = ebus_to_hbus(ebus);
 	skl = ebus_to_skl(ebus);
 
 	if (skl->init_failed)
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: Intel: Skylake: fix dereference before NULL check on ebus
  2017-04-19 12:16 [PATCH] ASoC: Intel: Skylake: fix dereference before NULL check on ebus Colin King
@ 2017-04-19 13:32 ` Dan Carpenter
  2017-04-19 13:34   ` Colin Ian King
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Carpenter @ 2017-04-19 13:32 UTC (permalink / raw)
  To: Colin King
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Vinod Koul, Jeeja KP, Jayachandran B, Subhransu S . Prusty,
	Dharageswari R, Pardha Saradhi K, Yong Zhi, alsa-devel,
	kernel-janitors, linux-kernel

On Wed, Apr 19, 2017 at 01:16:13PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> ebus is being NULL checked however it is being dereferenced
> earlier on the assignment bus = ebus_to_hbus(ebus).  Fix this
> by moving the assignment to after the NULL check on ebus to
> avoid a NULL pointer dereference error.
> 

ebus_to_hbus() doesn't dereference "ebus" it just uses it for pointer
math.

#define ebus_to_hbus(ebus)      (&(ebus)->bus)

If you pass a NULL to there, it returns an offset starting from NULL but
it doesn't Oops.

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ASoC: Intel: Skylake: fix dereference before NULL check on ebus
  2017-04-19 13:32 ` Dan Carpenter
@ 2017-04-19 13:34   ` Colin Ian King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2017-04-19 13:34 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Vinod Koul, Jeeja KP, Jayachandran B, Subhransu S . Prusty,
	Dharageswari R, Pardha Saradhi K, Yong Zhi, alsa-devel,
	kernel-janitors, linux-kernel

On 19/04/17 14:32, Dan Carpenter wrote:
> On Wed, Apr 19, 2017 at 01:16:13PM +0100, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> ebus is being NULL checked however it is being dereferenced
>> earlier on the assignment bus = ebus_to_hbus(ebus).  Fix this
>> by moving the assignment to after the NULL check on ebus to
>> avoid a NULL pointer dereference error.
>>
> 
> ebus_to_hbus() doesn't dereference "ebus" it just uses it for pointer
> math.
> 
> #define ebus_to_hbus(ebus)      (&(ebus)->bus)
> 
> If you pass a NULL to there, it returns an offset starting from NULL but
> it doesn't Oops.

Doh, brown paper bag moment for me.

> 
> regards,
> dan carpenter
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-04-19 13:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-19 12:16 [PATCH] ASoC: Intel: Skylake: fix dereference before NULL check on ebus Colin King
2017-04-19 13:32 ` Dan Carpenter
2017-04-19 13:34   ` Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).