wireless: used kzalloc instead of kmalloc & memset
PATCH 1/1 wireless: used kzalloc instead of kmalloc & memset
Use kcalloc or kzalloc rather than the combination of kmalloc and memset.
The semantic patch that makes this change is as follows:
(http://coccinelle.lip6.fr/)
// <smpl>
@@
expression x,y,flags;
statement S;
type T;
@@
x =
- kmalloc
+ kcalloc
(
- y * sizeof(T),
+ y, sizeof(T),
flags); if (x == NULL) S
-memset(x, 0, y * sizeof(T));
@@
expression x,size,flags;
statement S;
@@
-x = kmalloc(size,flags);
+x = kzalloc(size,flags);
if (x == NULL) S
-memset(x, 0, size);
// </smpl>
--- drivers/net/wireless/mwl8k.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/wireless/mwl8k.c +2 -4
@@ -1056,13 +1056,12 @@ static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index) }memset (rxq->rxd,0 , size); - rxq->buf =kmalloc (MWL8K_RX_DESCS *sizeof (*rxq->buf),GFP_KERNEL ); + rxq->buf =kzalloc (MWL8K_RX_DESCS *sizeof (*rxq->buf),GFP_KERNEL );if (rxq->buf ==NULL ) {wiphy_err (hw->wiphy,"failed to alloc RX skbuff list\n" );pci_free_consistent (priv->pdev, size, rxq->rxd, rxq->rxd_dma);return -ENOMEM ; } -memset (rxq->buf,0 ,MWL8K_RX_DESCS *sizeof (*rxq->buf));for (i =0 ; i <MWL8K_RX_DESCS ; i++) {int desc_size;
@@ -1347,13 +1346,12 @@ static int mwl8k_txq_init(struct ieee80211_hw *hw, int index) }memset (txq->txd,0 , size); - txq->skb =kmalloc (MWL8K_TX_DESCS *sizeof (*txq->skb),GFP_KERNEL ); + txq->skb =kzalloc (MWL8K_TX_DESCS *sizeof (*txq->skb),GFP_KERNEL );if (txq->skb ==NULL ) {wiphy_err (hw->wiphy,"failed to alloc TX skbuff list\n" );pci_free_consistent (priv->pdev, size, txq->txd, txq->txd_dma);return -ENOMEM ; } -memset (txq->skb,0 ,MWL8K_TX_DESCS *sizeof (*txq->skb));for (i =0 ; i <MWL8K_TX_DESCS ; i++) {struct mwl8k_tx_desc *tx_desc;
Signature · 1 line
1.6.3.3
Quoted 1 line · Shan Wei
Use kcalloc or kzalloc rather than the combination of kmalloc and memset.
[snip]
Quoted 10 lines
Signed-off-by Shan Wei <[email protected]>---
drivers/net/wireless/mwl8k.c | 6 ++----1 files changed, 2 insertions(+), 4 deletions(-)drivers/net/wireless/mwl8k.c +0
-0
drivers/net/wireless/mwl8k.c static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index) · line 1059
Quoted 5 lines
drivers/net/wireless/mwl8k.c +1
-1@@ -1056,13 +1056,12 @@ static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index) } memset(rxq->rxd, 0, size); - rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL); + rxq->buf = kzalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);
Random nit, you're changing this from kmalloc to kzalloc when it would be trivial to change it to kcalloc instead if you don't restrict the T variable in your semantic patch to a type.
Thanks,
Signature · 5 lines
Julian Calaby Email: [email protected] Profile: http://www.google.com/profiles/julian.calaby/ .Plan: http://sites.google.com/site/juliancalaby/
Julian Calaby wrote, at 03/07/2011 09:30 PM:
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- rxq->buf = kmalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL); + rxq->buf = kzalloc(MWL8K_RX_DESCS * sizeof(*rxq->buf), GFP_KERNEL);Random nit, you're changing this from kmalloc to kzalloc when it would be trivial to change it to kcalloc instead if you don't restrict the T variable in your semantic patch to a type.
Thanks for your review.
here patch-v2.
==========================================
[PATCH v2] wireless: use kcalloc instead of kmalloc & memset
Use kcalloc or kzalloc rather than the combination of kmalloc and memset.
Thanks coccicheck for detecting this.
(http://coccinelle.lip6.fr/)
--- drivers/net/wireless/mwl8k.c | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-)
drivers/net/wireless/mwl8k.c +2 -4
@@ -1056,13 +1056,12 @@ static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index) }memset (rxq->rxd,0 , size); - rxq->buf =kmalloc (MWL8K_RX_DESCS *sizeof (*rxq->buf),GFP_KERNEL ); + rxq->buf =kcalloc (MWL8K_RX_DESCS ,sizeof (*rxq->buf),GFP_KERNEL );if (rxq->buf ==NULL ) {wiphy_err (hw->wiphy,"failed to alloc RX skbuff list\n" );pci_free_consistent (priv->pdev, size, rxq->rxd, rxq->rxd_dma);return -ENOMEM ; } -memset (rxq->buf,0 ,MWL8K_RX_DESCS *sizeof (*rxq->buf));for (i =0 ; i <MWL8K_RX_DESCS ; i++) {int desc_size;
@@ -1347,13 +1346,12 @@ static int mwl8k_txq_init(struct ieee80211_hw *hw, int index) }memset (txq->txd,0 , size); - txq->skb =kmalloc (MWL8K_TX_DESCS *sizeof (*txq->skb),GFP_KERNEL ); + txq->skb =kcalloc (MWL8K_TX_DESCS ,sizeof (*txq->skb),GFP_KERNEL );if (txq->skb ==NULL ) {wiphy_err (hw->wiphy,"failed to alloc TX skbuff list\n" );pci_free_consistent (priv->pdev, size, txq->txd, txq->txd_dma);return -ENOMEM ; } -memset (txq->skb,0 ,MWL8K_TX_DESCS *sizeof (*txq->skb));for (i =0 ; i <MWL8K_TX_DESCS ; i++) {struct mwl8k_tx_desc *tx_desc;
Signature · 1 line
1.6.3.3