staging: rtl8192u: ieee80211: Prefer kmalloc_array over kmalloc
PATCH 1/1 staging: rtl8192u: ieee80211: Prefer kmalloc_array over kmalloc
Use kmalloc_array instead of kmalloc for arrays to prevent integer overflows.
This was done using Coccinelle:
@@
expression e1, e2;
constant C;
type t;
@@
(
- kmalloc(sizeof(e1)*e2, C)
+ kmalloc_array(e2, sizeof(e1), C)
|
- kmalloc(e2*sizeof(e1), C)
+ kmalloc_array(e2, sizeof(e1), C)
|
- kmalloc(e2*sizeof(t), C)
+ kmalloc_array(e2, sizeof(t), C)
|
- kmalloc(sizeof(t)*e2, C)
+ kmalloc_array(e2, sizeof(t), C)
)
--- drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +3 -2
@@ -601,8 +601,9 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,bool bMatchWinStart = false, bPktInBuf = false;IEEE80211_DEBUG (IEEE80211_DL_REORDER ,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n" ,__func__,SeqNum,pTS->RxIndicateSeq,WinSize); - prxbIndicateArray =kmalloc (sizeof (struct ieee80211_rxb *) * -REORDER_WIN_SIZE ,GFP_KERNEL ); + prxbIndicateArray =kmalloc_array (REORDER_WIN_SIZE , +sizeof (struct ieee80211_rxb *), +GFP_KERNEL );if (!prxbIndicateArray)return ;
--
2.1.4
Quoted 32 lines · Bhaktipriya Shridhar
Use
kmalloc_arrayinstead of kmalloc for arrays to prevent integer overflows.
This was done using Coccinelle:
@@
expression e1, e2;
constant C;
type t;
@@
(
-kmalloc(sizeof(e1)*e2, C)
+kmalloc_array(e2, sizeof(e1), C)
|
-kmalloc(e2*sizeof(e1), C)
+kmalloc_array(e2, sizeof(e1), C)
|
-kmalloc(e2*sizeof(t), C)
+kmalloc_array(e2, sizeof(t), C)
|
-kmalloc(sizeof(t)*e2, C)
+kmalloc_array(e2, sizeof(t), C)
)Signed-off-by Bhaktipriya Shridhar <[email protected]>--- drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +0
-0
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c static void RxReorderIndicatePacket(struct ieee80211_device *ieee, · line 606
Quoted 8 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +3
-2@@ -601,8 +601,9 @@ static void RxReorderIndicatePacket(struct ieee80211_device *ieee,bool bMatchWinStart = false, bPktInBuf = false;IEEE80211_DEBUG (IEEE80211_DL_REORDER ,"%s(): Seq is %d,pTS->RxIndicateSeq is %d, WinSize is %d\n" ,__func__,SeqNum,pTS->RxIndicateSeq,WinSize); - prxbIndicateArray =kmalloc (sizeof (struct ieee80211_rxb *) * -REORDER_WIN_SIZE ,GFP_KERNEL ); + prxbIndicateArray =kmalloc_array (REORDER_WIN_SIZE , +sizeof (struct ieee80211_rxb *), +GFP_KERNEL );
This is again a small value.
julia
Quoted 13 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +0
-1if (!prxbIndicateArray)return ; --2.1.4
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160221112752.GA28003%40Karyakshetra.
For more options, visit https://groups.google.com/d/optout.