Skip to contentSkip to conversation

Use kmemdup

PATCH In review Shraddha Barke 2 participants 4 messages Oct 11, 2015 – Oct 13, 2015 Staging

lore
Share & tools
lore
#0 lore raw

cover Use kmemdup

Replace kmalloc and memcpy with kmemdup

Shraddha Barke (2):
Staging: wilc1000: host_interface: Use kmemdup instead of kmalloc and
memcpy
Staging: wilc1000: wilc_msgqueue: Use kmemdup instead of kmalloc and
memcpy

 drivers/staging/wilc1000/host_interface.c | 14 ++++++--------
 drivers/staging/wilc1000/wilc_msgqueue.c  |  4 ++--
 2 files changed, 8 insertions(+), 10 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

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

Replace kmalloc followed by memcpy with kmemdup

---
 drivers/staging/wilc1000/host_interface.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/staging/wilc1000/host_interface.c +6 -8
index bb833d3..f92ec7d 100644
@@ -2444,7 +2444,9 @@ static int Handle_Key(tstrWILC_WFIDrv *drvHandler,
 			strWIDList[2].s32ValueSize = sizeof(char);
 
 
-			pu8keybuf = kmalloc(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen, GFP_KERNEL);
+			pu8keybuf = kmemdup(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
+					    pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen,
+					    GFP_KERNEL);
 
 
 			if (pu8keybuf == NULL) {
@@ -2452,9 +2454,6 @@ static int Handle_Key(tstrWILC_WFIDrv *drvHandler,
 				return -1;
 			}
 
-			memcpy(pu8keybuf, pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey,
-				    pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.u8WepKeylen);
-
 
 			kfree(pstrHostIFkeyAttr->uniHostIFkeyAttr.strHostIFwepAttr.pu8WepKey);
 
@@ -6389,21 +6388,20 @@ s32 host_int_add_beacon(tstrWILC_WFIDrv *hWFIDrv, 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
maintainer
#2 lore raw

Re: [Outreachy kernel] [PATCH 1/2] Staging: wilc1000: host_interface: Use kmemdup instead of kmalloc and memcpy

Quoted 6 lines · Shraddha Barke

Replace kmalloc followed by memcpy with kmemdup

---
 drivers/staging/wilc1000/host_interface.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

This patch no longer applies to my staging-testing branch :(

#3 lore raw

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

In reply to Shraddha Barke

Replace kmalloc and memcpy with kmemdup.
Problem found using coccicheck

---
 drivers/staging/wilc1000/wilc_msgqueue.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/wilc1000/wilc_msgqueue.c +2 -2
index d5ebd6d..b13809a 100644
@@ -80,12 +80,12 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
 		return -ENOMEM;
 	pstrMessage->u32Length = u32SendBufferSize;
 	pstrMessage->pstrNext = NULL;
-	pstrMessage->pvBuffer = kmalloc(u32SendBufferSize, GFP_ATOMIC);
+	pstrMessage->pvBuffer = kmemdup(pvSendBuffer, u32SendBufferSize,
+					GFP_ATOMIC);
 	if (!pstrMessage->pvBuffer) {
 		result = -ENOMEM;
 		goto ERRORHANDLER;
 	}
-	memcpy(pstrMessage->pvBuffer, pvSendBuffer, u32SendBufferSize);
 
 	/* add it to the message queue */
 	if (!pHandle->pstrMessageList) {
Signature · 1 line
2.1.4