staging: rtl8192e: Use kzalloc rather than kmalloc v2
authorThomas Meyer <thomas@m3y3r.de>
Thu, 10 Nov 2011 18:04:19 +0000 (19:04 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Sun, 27 Nov 2011 01:21:16 +0000 (17:21 -0800)
Use kzalloc rather than kmalloc followed by memset with 0

This considers some simple cases that are common and easy to validate
Note in particular that there are no ...s in the rule, so all of the
matched code has to be contiguous

The semantic patch that makes this change is available
in scripts/coccinelle/api/alloc/kzalloc-simple.cocci.

Signed-off-by: Thomas Meyer <thomas@m3y3r.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/rtl8192e/rtllib_crypt.c
drivers/staging/rtl8192e/rtllib_crypt_ccmp.c
drivers/staging/rtl8192e/rtllib_crypt_tkip.c
drivers/staging/rtl8192e/rtllib_crypt_wep.c
drivers/staging/rtl8192e/rtllib_softmac.c
drivers/staging/rtl8192e/rtllib_wx.c

index acda37b818483b96e565fb1e32c169561edee368..a33bf024c37e138c5021b30db018a91e6d70d939 100644 (file)
@@ -104,11 +104,10 @@ int rtllib_register_crypto_ops(struct rtllib_crypto_ops *ops)
        if (hcrypt == NULL)
                return -1;
 
-       alg = kmalloc(sizeof(*alg), GFP_KERNEL);
+       alg = kzalloc(sizeof(*alg), GFP_KERNEL);
        if (alg == NULL)
                return -ENOMEM;
 
-       memset(alg, 0, sizeof(*alg));
        alg->ops = ops;
 
        spin_lock_irqsave(&hcrypt->lock, flags);
@@ -202,11 +201,10 @@ int __init rtllib_crypto_init(void)
 {
        int ret = -ENOMEM;
 
-       hcrypt = kmalloc(sizeof(*hcrypt), GFP_KERNEL);
+       hcrypt = kzalloc(sizeof(*hcrypt), GFP_KERNEL);
        if (!hcrypt)
                goto out;
 
-       memset(hcrypt, 0, sizeof(*hcrypt));
        INIT_LIST_HEAD(&hcrypt->algs);
        spin_lock_init(&hcrypt->lock);
 
index 6196b9aa3a092130813fc8adfe95e31e25b875be..63b75045aa6b3b32e2f13b42d6757040029f366c 100644 (file)
@@ -63,10 +63,9 @@ static void *rtllib_ccmp_init(int key_idx)
 {
        struct rtllib_ccmp_data *priv;
 
-       priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
+       priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
        if (priv == NULL)
                goto fail;
-       memset(priv, 0, sizeof(*priv));
        priv->key_idx = key_idx;
 
        priv->tfm = (void *)crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
index 6a0c878864220d2637ffef6fbe6cc95060cb76b4..70d5001e64604df25989d03630441c44a909e517 100644 (file)
@@ -60,10 +60,9 @@ static void *rtllib_tkip_init(int key_idx)
 {
        struct rtllib_tkip_data *priv;
 
-       priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
+       priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
        if (priv == NULL)
                goto fail;
-       memset(priv, 0, sizeof(*priv));
        priv->key_idx = key_idx;
        priv->tx_tfm_arc4 = crypto_alloc_blkcipher("ecb(arc4)", 0,
                        CRYPTO_ALG_ASYNC);
index c59bf10fe780437dd10449da7c703b1a5f31b50c..1f1ffb8ea197c0d17224fc1c6658e65f4cf82d76 100644 (file)
@@ -38,10 +38,9 @@ static void *prism2_wep_init(int keyidx)
 {
        struct prism2_wep_data *priv;
 
-       priv = kmalloc(sizeof(*priv), GFP_ATOMIC);
+       priv = kzalloc(sizeof(*priv), GFP_ATOMIC);
        if (priv == NULL)
                goto fail;
-       memset(priv, 0, sizeof(*priv));
        priv->key_idx = keyidx;
 
        priv->tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0, CRYPTO_ALG_ASYNC);
index fa774cf7fc788d7be2eaa03a2d639caf81dd74ad..30c3bca1c368a8dbdd3799e486e81116708747d5 100644 (file)
@@ -3048,10 +3048,9 @@ void rtllib_softmac_init(struct rtllib_device *ieee)
        ieee->state = RTLLIB_NOLINK;
        for (i = 0; i < 5; i++)
                ieee->seq_ctrl[i] = 0;
-       ieee->pDot11dInfo = kmalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
+       ieee->pDot11dInfo = kzalloc(sizeof(struct rt_dot11d_info), GFP_ATOMIC);
        if (!ieee->pDot11dInfo)
                RTLLIB_DEBUG(RTLLIB_DL_ERR, "can't alloc memory for DOT11D\n");
-       memset(ieee->pDot11dInfo, 0, sizeof(struct rt_dot11d_info));
        ieee->LinkDetectInfo.SlotIndex = 0;
        ieee->LinkDetectInfo.SlotNum = 2;
        ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0;
index 8cea4a60e1b3f64619f06beb0e37b04ab857c720..a8fd2e1f4ada28860e82e375c168b19fc7c75be7 100644 (file)
@@ -368,11 +368,10 @@ int rtllib_wx_set_encode(struct rtllib_device *ieee,
                struct rtllib_crypt_data *new_crypt;
 
                /* take WEP into use */
-               new_crypt = kmalloc(sizeof(struct rtllib_crypt_data),
+               new_crypt = kzalloc(sizeof(struct rtllib_crypt_data),
                                    GFP_KERNEL);
                if (new_crypt == NULL)
                        return -ENOMEM;
-               memset(new_crypt, 0, sizeof(struct rtllib_crypt_data));
                new_crypt->ops = rtllib_get_crypto_ops("WEP");
                if (!new_crypt->ops) {
                        request_module("rtllib_crypt_wep");