From 543f5b1313b758d38f8ac9c2492a36400a0f0966 Mon Sep 17 00:00:00 2001 From: Shraddha Barke Date: Fri, 16 Oct 2015 10:47:11 +0530 Subject: [PATCH] Staging: wilc1000: Use kmemdup instead of kmalloc and memcpy Replace kmalloc followed by memcpy with kmemdup Problem found using coccicheck Signed-off-by: Shraddha Barke Signed-off-by: Greg Kroah-Hartman --- drivers/staging/wilc1000/host_interface.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/drivers/staging/wilc1000/host_interface.c b/drivers/staging/wilc1000/host_interface.c index 3dbb74ebafa0..38fead44cce0 100644 --- a/drivers/staging/wilc1000/host_interface.c +++ b/drivers/staging/wilc1000/host_interface.c @@ -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; } -- 2.30.2