Commit dbef61e7 authored by Leo Kim's avatar Leo Kim Committed by Greg Kroah-Hartman

staging: wilc1000: wilc_msgqueue.c : remove goto statement

This patch removes goto statement and moves the spin lock position.
If a memory allocation fails, directly returns an error.
The spin lock actually protects the pHandle. Therefore, call spin lock just
before pHandle is used.
Signed-off-by: default avatarLeo Kim <leo.kim@atmel.com>
Signed-off-by: default avatarTony Cho <tony.cho@atmel.com>
Signed-off-by: default avatarGlen Lee <glen.lee@atmel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 82bb18e1
...@@ -56,37 +56,35 @@ int wilc_mq_destroy(WILC_MsgQueueHandle *pHandle) ...@@ -56,37 +56,35 @@ int wilc_mq_destroy(WILC_MsgQueueHandle *pHandle)
int wilc_mq_send(WILC_MsgQueueHandle *pHandle, int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
const void *pvSendBuffer, u32 u32SendBufferSize) const void *pvSendBuffer, u32 u32SendBufferSize)
{ {
int result = 0;
unsigned long flags; unsigned long flags;
Message *pstrMessage = NULL; Message *pstrMessage = NULL;
if ((!pHandle) || (u32SendBufferSize == 0) || (!pvSendBuffer)) { if ((!pHandle) || (u32SendBufferSize == 0) || (!pvSendBuffer)) {
PRINT_ER("pHandle or pvSendBuffer is null\n"); PRINT_ER("pHandle or pvSendBuffer is null\n");
result = -EFAULT; return -EFAULT;
goto ERRORHANDLER;
} }
if (pHandle->bExiting) { if (pHandle->bExiting) {
PRINT_ER("pHandle fail\n"); PRINT_ER("pHandle fail\n");
result = -EFAULT; return -EFAULT;
goto ERRORHANDLER;
} }
spin_lock_irqsave(&pHandle->strCriticalSection, flags);
/* construct a new message */ /* construct a new message */
pstrMessage = kmalloc(sizeof(Message), GFP_ATOMIC); pstrMessage = kmalloc(sizeof(Message), GFP_ATOMIC);
if (!pstrMessage) if (!pstrMessage)
return -ENOMEM; return -ENOMEM;
pstrMessage->u32Length = u32SendBufferSize; pstrMessage->u32Length = u32SendBufferSize;
pstrMessage->pstrNext = NULL; pstrMessage->pstrNext = NULL;
pstrMessage->pvBuffer = kmemdup(pvSendBuffer, u32SendBufferSize, pstrMessage->pvBuffer = kmemdup(pvSendBuffer, u32SendBufferSize,
GFP_ATOMIC); GFP_ATOMIC);
if (!pstrMessage->pvBuffer) { if (!pstrMessage->pvBuffer) {
result = -ENOMEM; kfree(pstrMessage);
goto ERRORHANDLER; return -ENOMEM;
} }
spin_lock_irqsave(&pHandle->strCriticalSection, flags);
/* add it to the message queue */ /* add it to the message queue */
if (!pHandle->pstrMessageList) { if (!pHandle->pstrMessageList) {
pHandle->pstrMessageList = pstrMessage; pHandle->pstrMessageList = pstrMessage;
...@@ -103,14 +101,7 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle, ...@@ -103,14 +101,7 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
up(&pHandle->hSem); up(&pHandle->hSem);
ERRORHANDLER: return 0;
/* error occured, free any allocations */
if (pstrMessage) {
kfree(pstrMessage->pvBuffer);
kfree(pstrMessage);
}
return result;
} }
/*! /*!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment