Skip to contentSkip to conversation

Staging: wilc1000: Use kmemdup instead of kmalloc and memcpy

PATCH New Shraddha Barke 1 participant 1 message Oct 13, 2015 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: wilc1000: Use kmemdup instead of kmalloc and memcpy

Replace kmalloc and memcpy with kmemdup.
Problem found using coccicheck

---
 drivers/staging/wilc1000/host_interface.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/staging/wilc1000/host_interface.c +6 -8
index ec04aec..9bc221c 100644
@@ -2367,7 +2367,9 @@ static int Handle_Key(struct host_if_drv *hif_drv,
 			strWIDList[2].size = sizeof(char);
 
 
-			pu8keybuf = kmalloc(pstrHostIFkeyAttr->uniHostIFkeyAttr.wep.key_len, GFP_KERNEL);
+			pu8keybuf = kmemdup(pstrHostIFkeyAttr->uniHostIFkeyAttr.wep.key,
+					    pstrHostIFkeyAttr->uniHostIFkeyAttr.wep.key_len,
+					    GFP_KERNEL);
 
 
 			if (pu8keybuf == NULL) {
@@ -2375,9 +2377,6 @@ static int Handle_Key(struct host_if_drv *hif_drv,
 				return -1;
 			}
 
-			memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.wep.key,
-				    pstrHostIFkeyAttr->uniHostIFkeyAttr.wep.key_len);
-
 
 			kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.wep.key);
 
@@ -6226,21 +6225,20 @@ s32 host_int_add_beacon(struct host_if_drv *hif_drv, u32 u32Interval,
 	pstrSetBeaconParam->u32Interval = u32Interval;
 	pstrSetBeaconParam->u32DTIMPeriod = u32DTIMPeriod;
 	pstrSetBeaconParam->u32HeadLen = u32HeadLen;
-	pstrSetBeaconParam->pu8Head = kmalloc(u32HeadLen, GFP_KERNEL);
+	pstrSetBeaconParam->pu8Head = kmemdup(pu8Head, u32HeadLen, GFP_KERNEL);
 	if (pstrSetBeaconParam->pu8Head == NULL) {
 		s32Error = -ENOMEM;
 		goto ERRORHANDLER;
 	}
-	memcpy(pstrSetBeaconParam->pu8Head, pu8Head, u32HeadLen);
 	pstrSetBeaconParam->u32TailLen = u32TailLen;
 
 	if (u32TailLen > 0) {
-		pstrSetBeaconParam->pu8Tail = kmalloc(u32TailLen, GFP_KERNEL);
+		pstrSetBeaconParam->pu8Tail = kmemdup(pu8Tail, u32TailLen,
+						      GFP_KERNEL);
 		if (pstrSetBeaconParam->pu8Tail == NULL) {
 			s32Error = -ENOMEM;
 			goto ERRORHANDLER;
 		}
-		memcpy(pstrSetBeaconParam->pu8Tail, pu8Tail, u32TailLen);
 	} else {
 		pstrSetBeaconParam->pu8Tail = NULL;
 	}
Signature · 1 line
2.1.4