Skip to contentSkip to conversation

staging: rtl8192u: Use kmalloc_array instead of kmalloc

PATCH In review Janani Ravichandran 2 participants 2 messages Feb 10, 2016 – Feb 12, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 staging: rtl8192u: Use kmalloc_array instead of kmalloc

Use kmalloc_array instead of kmalloc for arrays. The Coccinelle patch for this conversion is:

@@
type T;
expression F;
constant FLAG;
@@

- kmalloc(sizeof(T)*F, FLAG)
+ kmalloc_array(F, sizeof(T), FLAG)

---
Changes since v3:
* Changed RECORDER_WIN_SIZE to REORDER_WIN_SIZE as the former was incorrect.

 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +2 -2
index 28ad63a..fb344d1 100644
@@ -601,8 +601,8 @@ 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;
 
Signature · 1 line
2.5.0
maintainer
#1 lore raw
Quoted 26 lines · Janani Ravichandran

Use kmalloc_array instead of kmalloc for arrays. The Coccinelle patch for this conversion is:

@@
type T;
expression F;
constant FLAG;
@@

- kmalloc(sizeof(T)*F, FLAG)
+ kmalloc_array(F, sizeof(T), FLAG)

---
Changes since v3:
* Changed RECORDER_WIN_SIZE to REORDER_WIN_SIZE as the former was incorrect.

 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +0 -0
index 28ad63a..fb344d1 100644

drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c static void RxReorderIndicatePacket(struct ieee80211_device *ieee, · line 605

Quoted 7 lines
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +2 -2
@@ -601,8 +601,8 @@ 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);

For "static" allocations like this, where we know the size at compile time, it doesn't make any sense to call kmalloc_array(), in fact, it just adds complexity.

sorry,

greg k-h