Staging: wilc1000: Use kmemdup instead of kmalloc and memcpy
PATCH 1/1 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 <[email protected]>
--- drivers/staging/wilc1000/host_interface.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/staging/wilc1000/host_interface.c +6 -8
@@ -1793,16 +1793,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 ;
@@ -4633,21 +4632,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 ; }
Signature · 1 line
2.1.4