]> git.karo-electronics.de Git - linux-beck.git/commitdiff
Staging: wilc1000: Use kmemdup instead of kmalloc and memcpy
authorShraddha Barke <shraddha.6596@gmail.com>
Fri, 16 Oct 2015 05:17:11 +0000 (10:47 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 17 Oct 2015 04:59:35 +0000 (21:59 -0700)
Replace kmalloc followed by memcpy with kmemdup
Problem found using coccicheck

Signed-off-by: Shraddha Barke <shraddha.6596@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/wilc1000/host_interface.c

index 3dbb74ebafa046e8e34d696e1b0463dbb4630082..38fead44cce00e820a355a6bd655203b2c3296d5 100644 (file)
@@ -1750,16 +1750,15 @@ static int Handle_Key(struct host_if_drv *hif_drv,
                        strWIDList[2].val = (s8 *)(&(pstrHostIFkeyAttr->attr.wep.index));
                        strWIDList[2].size = sizeof(char);
 
-                       pu8keybuf = kmalloc(pstrHostIFkeyAttr->attr.wep.key_len, GFP_KERNEL);
+                       pu8keybuf = kmemdup(pstrHostIFkeyAttr->attr.wep.key,
+                                           pstrHostIFkeyAttr->attr.wep.key_len,
+                                           GFP_KERNEL);
 
                        if (pu8keybuf == NULL) {
                                PRINT_ER("No buffer to send Key\n");
                                return -1;
                        }
 
-                       memcpy(pu8keybuf, pstrHostIFkeyAttr->attr.wep.key,
-                                   pstrHostIFkeyAttr->attr.wep.key_len);
-
                        kfree(pstrHostIFkeyAttr->attr.wep.key);
 
                        strWIDList[3].id = (u16)WID_WEP_KEY_VALUE;
@@ -4579,21 +4578,20 @@ s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval,
        pstrSetBeaconParam->interval = u32Interval;
        pstrSetBeaconParam->dtim_period = u32DTIMPeriod;
        pstrSetBeaconParam->head_len = u32HeadLen;
-       pstrSetBeaconParam->head = kmalloc(u32HeadLen, GFP_KERNEL);
+       pstrSetBeaconParam->head = kmemdup(pu8Head, u32HeadLen, GFP_KERNEL);
        if (pstrSetBeaconParam->head == NULL) {
                s32Error = -ENOMEM;
                goto ERRORHANDLER;
        }
-       memcpy(pstrSetBeaconParam->head, pu8Head, u32HeadLen);
        pstrSetBeaconParam->tail_len = u32TailLen;
 
        if (u32TailLen > 0) {
-               pstrSetBeaconParam->tail = kmalloc(u32TailLen, GFP_KERNEL);
+               pstrSetBeaconParam->tail = kmemdup(pu8Tail, u32TailLen,
+                                                  GFP_KERNEL);
                if (pstrSetBeaconParam->tail == NULL) {
                        s32Error = -ENOMEM;
                        goto ERRORHANDLER;
                }
-               memcpy(pstrSetBeaconParam->tail, pu8Tail, u32TailLen);
        } else {
                pstrSetBeaconParam->tail = NULL;
        }