drivers/net/wireless/brcm80211/brcmsmac/dma.c: eliminate a null pointer dereference
PATCH 2/5 drivers/net/wireless/brcm80211/brcmsmac/dma.c: eliminate a null pointer dereference
From: Julia Lawall <[email protected]>
Delete di->name from the error reporting code, as it is meaningless if di is NULL.
The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@r@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@
if (E = NULL)
{
... when != if (E = NULL || ...) S1 else S2
when != E = E1
*E->f
... when any
return ...;
}
else S3
// </smpl>
--- drivers/net/wireless/brcm80211/brcmsmac/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/brcm80211/brcmsmac/dma.c +1 -1
@@ -361,7 +361,7 @@ static uint _dma_ctrlflags(struct dma_info *di, uint mask, uint flags)uint dmactrlflags = di->dma.dmactrlflags;if (di =NULL ) { -DMA_ERROR (("%s: _dma_ctrlflags: NULL dma handle\n" , di->name)); +DMA_ERROR (("_dma_ctrlflags: NULL dma handle\n" ));return 0 ; }
Quoted 37 lines · Julia Lawall
From: Julia Lawall <[email protected]>
Delete
di->namefrom the error reporting code, as it is meaningless if di is NULL.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@if (E = NULL)
{
... when != if (E = NULL || ...) S1 else S2when != E = E1
*E->f
... when any
return ...;
}
else S3
// </smpl>Signed-off-by Julia Lawall <[email protected]>--- drivers/net/wireless/brcm80211/brcmsmac/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/wireless/brcm80211/brcmsmac/dma.c +0
-0
drivers/net/wireless/brcm80211/brcmsmac/dma.c static uint _dma_ctrlflags(struct dma_info *di, uint mask, uint flags) · line 361
Quoted 1 line
drivers/net/wireless/brcm80211/brcmsmac/dma.c +0
-0@@ -361,7 +361,7 @@ static uint _dma_ctrlflags(struct dma_info *di, uint mask, uint flags)uint dmactrlflags = di->dma.dmactrlflags;
If di is null, we've already failed as it's dereferenced here.
drivers/net/wireless/brcm80211/brcmsmac/dma.c static uint _dma_ctrlflags(struct dma_info *di, uint mask, uint flags) · line 365
Quoted 5 lines
drivers/net/wireless/brcm80211/brcmsmac/dma.c +1
-1if (di =NULL ) { -DMA_ERROR (("%s: _dma_ctrlflags: NULL dma handle\n" , di->name)); +DMA_ERROR (("_dma_ctrlflags: NULL dma handle\n" ));return 0 ; }
So, a better patch would be something like this:
(apologies if this doesn't apply - I've pretty much built it manually)
---
Though it's unlikely, di may be null, so we can't dereference di->dma.dmactrlflags until we've checked it.
Move this de-reference after the check, and adjust the error message to not require de-referencing di.
This is based upon Julia's original patch:
<[email protected]>
drivers/net/wireless/brcm80211/brcmsmac/dma.c +3 -2
@@ -358,13 +358,14 @@ static uint nrxdactive(struct dma_info *di, uint h, uint tstatic uint _dma_ctrlflags (struct dma_info *di,uint mask,uint flags) { -uint dmactrlflags = di->dma.dmactrlflags; +uint dmactrlflags;if (di =NULL ) { -DMA_ERROR (("%s: _dma_ctrlflags: NULL dma handle\n" , di->name)); +DMA_ERROR (("_dma_ctrlflags: NULL dma handle\n" ));return 0 ; } + dmactrlflags = di->dma.dmactrlflags; dmactrlflags &= ~mask; dmactrlflags |= flags;
Signature · 5 lines
Julian Calaby Email: [email protected] Profile: http://www.google.com/profiles/julian.calaby/ .Plan: http://sites.google.com/site/juliancalaby
Quoted 82 lines · Julian Calaby
Quoted 37 lines · Julia Lawall
From: Julia Lawall <[email protected]>
Delete
di->namefrom the error reporting code, as it is meaningless if di is NULL.The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)// <smpl>
@r@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@if (E = NULL)
{
... when != if (E = NULL || ...) S1 else S2when != E = E1
*E->f
... when any
return ...;
}
else S3
// </smpl>Signed-off-by Julia Lawall <[email protected]>--- drivers/net/wireless/brcm80211/brcmsmac/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/wireless/brcm80211/brcmsmac/dma.c +0
-0drivers/net/wireless/brcm80211/brcmsmac/dma.c static uint _dma_ctrlflags(struct dma_info *di, uint mask, uint flags) · line 361
Quoted 1 line
drivers/net/wireless/brcm80211/brcmsmac/dma.c +0
-0@@ -361,7 +361,7 @@ static uint _dma_ctrlflags(struct dma_info *di, uint mask, uint flags)uint dmactrlflags = di->dma.dmactrlflags;If di is null, we've already failed as it's dereferenced here.
drivers/net/wireless/brcm80211/brcmsmac/dma.c static uint nrxdactive(struct dma_info *di, uint h, uint t · line 366
Quoted 5 lines
drivers/net/wireless/brcm80211/brcmsmac/dma.c +1
-1if (di =NULL ) { -DMA_ERROR (("%s: _dma_ctrlflags: NULL dma handle\n" , di->name)); +DMA_ERROR (("_dma_ctrlflags: NULL dma handle\n" ));return 0 ; }So, a better patch would be something like this:
(apologies if this doesn't apply - I've pretty much built it manually)
---
Though it's unlikely, di may be null, so we can't dereference
di->dma.dmactrlflagsuntil we've checked it.Move this de-reference after the check, and adjust the error message to not require de-referencing di.
This is based upon Julia's original patch:
<[email protected]>Reported-by Julia Lawall <[email protected]>Signed-off-by Julian Calaby <[email protected]>CC Julia Lawall <[email protected]>drivers/net/wireless/brcm80211/brcmsmac/dma.c +1
-1@@ -358,13 +358,14 @@ static uint nrxdactive(struct dma_info *di, uint h, uint tstatic uint _dma_ctrlflags (struct dma_info *di,uint mask,uint flags) { -uint dmactrlflags = di->dma.dmactrlflags; +uint dmactrlflags;
drivers/net/wireless/brcm80211/brcmsmac/dma.c static uint nrxdactive(struct dma_info *di, uint h, uint t · line 371
Quoted 10 lines
drivers/net/wireless/brcm80211/brcmsmac/dma.c +2
-1if (di =NULL ) { -DMA_ERROR (("%s: _dma_ctrlflags: NULL dma handle\n" , di->name)); +DMA_ERROR (("_dma_ctrlflags: NULL dma handle\n" ));return 0 ; } + dmactrlflags = di->dma.dmactrlflags; dmactrlflags &= ~mask; dmactrlflags |= flags;
Hi Julian, Julia
That change looks good, but it does not apply on top of our pending patches. Probably need to resend those after the merge window. I will create a applying patch and send it to John (and resend later if needed). Thanks for finding this one.
Gr. AvS