aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/wilc1000/wilc_msgqueue.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/wilc1000/wilc_msgqueue.c')
-rw-r--r--drivers/staging/wilc1000/wilc_msgqueue.c160
1 files changed, 76 insertions, 84 deletions
diff --git a/drivers/staging/wilc1000/wilc_msgqueue.c b/drivers/staging/wilc1000/wilc_msgqueue.c
index 70e4fa6a07a6..0eff121b8291 100644
--- a/drivers/staging/wilc1000/wilc_msgqueue.c
+++ b/drivers/staging/wilc1000/wilc_msgqueue.c
@@ -1,6 +1,9 @@
#include "wilc_msgqueue.h"
#include <linux/spinlock.h>
+#include "linux_wlan_common.h"
+#include <linux/errno.h>
+#include <linux/slab.h>
/*!
* @author syounan
@@ -8,14 +11,14 @@
* @note copied from FLO glue implementatuion
* @version 1.0
*/
-WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle)
+int wilc_mq_create(WILC_MsgQueueHandle *pHandle)
{
spin_lock_init(&pHandle->strCriticalSection);
sema_init(&pHandle->hSem, 0);
pHandle->pstrMessageList = NULL;
pHandle->u32ReceiversCount = 0;
pHandle->bExiting = false;
- return WILC_SUCCESS;
+ return 0;
}
/*!
@@ -24,24 +27,24 @@ WILC_ErrNo WILC_MsgQueueCreate(WILC_MsgQueueHandle *pHandle)
* @note copied from FLO glue implementatuion
* @version 1.0
*/
-WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle)
+int wilc_mq_destroy(WILC_MsgQueueHandle *pHandle)
{
-
pHandle->bExiting = true;
/* Release any waiting receiver thread. */
while (pHandle->u32ReceiversCount > 0) {
- up(&(pHandle->hSem));
+ up(&pHandle->hSem);
pHandle->u32ReceiversCount--;
}
- while (pHandle->pstrMessageList != NULL) {
+ while (pHandle->pstrMessageList) {
Message *pstrMessge = pHandle->pstrMessageList->pstrNext;
+
kfree(pHandle->pstrMessageList);
pHandle->pstrMessageList = pstrMessge;
}
- return WILC_SUCCESS;
+ return 0;
}
/*!
@@ -50,41 +53,47 @@ WILC_ErrNo WILC_MsgQueueDestroy(WILC_MsgQueueHandle *pHandle)
* @note copied from FLO glue implementatuion
* @version 1.0
*/
-WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
+int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
const void *pvSendBuffer, u32 u32SendBufferSize)
{
- WILC_ErrNo s32RetStatus = WILC_SUCCESS;
unsigned long flags;
Message *pstrMessage = NULL;
- if ((pHandle == NULL) || (u32SendBufferSize == 0) || (pvSendBuffer == NULL)) {
- WILC_ERRORREPORT(s32RetStatus, WILC_INVALID_ARGUMENT);
+ if ((!pHandle) || (u32SendBufferSize == 0) || (!pvSendBuffer)) {
+ PRINT_ER("pHandle or pvSendBuffer is null\n");
+ return -EFAULT;
}
- if (pHandle->bExiting == true) {
- WILC_ERRORREPORT(s32RetStatus, WILC_FAIL);
+ if (pHandle->bExiting) {
+ PRINT_ER("pHandle fail\n");
+ return -EFAULT;
}
- spin_lock_irqsave(&pHandle->strCriticalSection, flags);
-
/* construct a new message */
pstrMessage = kmalloc(sizeof(Message), GFP_ATOMIC);
- WILC_NULLCHECK(s32RetStatus, pstrMessage);
+ if (!pstrMessage)
+ return -ENOMEM;
+
pstrMessage->u32Length = u32SendBufferSize;
pstrMessage->pstrNext = NULL;
- pstrMessage->pvBuffer = WILC_MALLOC(u32SendBufferSize);
- WILC_NULLCHECK(s32RetStatus, pstrMessage->pvBuffer);
- memcpy(pstrMessage->pvBuffer, pvSendBuffer, u32SendBufferSize);
+ pstrMessage->pvBuffer = kmemdup(pvSendBuffer, u32SendBufferSize,
+ GFP_ATOMIC);
+ if (!pstrMessage->pvBuffer) {
+ kfree(pstrMessage);
+ return -ENOMEM;
+ }
+ spin_lock_irqsave(&pHandle->strCriticalSection, flags);
/* add it to the message queue */
- if (pHandle->pstrMessageList == NULL) {
+ if (!pHandle->pstrMessageList) {
pHandle->pstrMessageList = pstrMessage;
} else {
Message *pstrTailMsg = pHandle->pstrMessageList;
- while (pstrTailMsg->pstrNext != NULL) {
+
+ while (pstrTailMsg->pstrNext)
pstrTailMsg = pstrTailMsg->pstrNext;
- }
+
pstrTailMsg->pstrNext = pstrMessage;
}
@@ -92,95 +101,78 @@ WILC_ErrNo WILC_MsgQueueSend(WILC_MsgQueueHandle *pHandle,
up(&pHandle->hSem);
- WILC_CATCH(s32RetStatus)
- {
- /* error occured, free any allocations */
- if (pstrMessage != NULL) {
- if (pstrMessage->pvBuffer != NULL) {
- kfree(pstrMessage->pvBuffer);
- }
- kfree(pstrMessage);
- }
- }
-
- return s32RetStatus;
+ return 0;
}
-
-
/*!
* @author syounan
* @date 1 Sep 2010
* @note copied from FLO glue implementatuion
* @version 1.0
*/
-WILC_ErrNo WILC_MsgQueueRecv(WILC_MsgQueueHandle *pHandle,
+int wilc_mq_recv(WILC_MsgQueueHandle *pHandle,
void *pvRecvBuffer, u32 u32RecvBufferSize,
u32 *pu32ReceivedLength)
{
-
Message *pstrMessage;
- WILC_ErrNo s32RetStatus = WILC_SUCCESS;
+ int result = 0;
unsigned long flags;
- if ((pHandle == NULL) || (u32RecvBufferSize == 0)
- || (pvRecvBuffer == NULL) || (pu32ReceivedLength == NULL)) {
- WILC_ERRORREPORT(s32RetStatus, WILC_INVALID_ARGUMENT);
+
+ if ((!pHandle) || (u32RecvBufferSize == 0)
+ || (!pvRecvBuffer) || (!pu32ReceivedLength)) {
+ PRINT_ER("pHandle or pvRecvBuffer is null\n");
+ return -EINVAL;
}
- if (pHandle->bExiting == true) {
- WILC_ERRORREPORT(s32RetStatus, WILC_FAIL);
+ if (pHandle->bExiting) {
+ PRINT_ER("pHandle fail\n");
+ return -EFAULT;
}
spin_lock_irqsave(&pHandle->strCriticalSection, flags);
pHandle->u32ReceiversCount++;
spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
- down(&(pHandle->hSem));
+ down(&pHandle->hSem);
- if (s32RetStatus == WILC_TIMEOUT) {
- /* timed out, just exit without consumeing the message */
- spin_lock_irqsave(&pHandle->strCriticalSection, flags);
- pHandle->u32ReceiversCount--;
- spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
- } else {
- /* other non-timeout scenarios */
- WILC_ERRORCHECK(s32RetStatus);
-
- if (pHandle->bExiting) {
- WILC_ERRORREPORT(s32RetStatus, WILC_FAIL);
- }
-
- spin_lock_irqsave(&pHandle->strCriticalSection, flags);
-
- pstrMessage = pHandle->pstrMessageList;
- if (pstrMessage == NULL) {
- spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
- WILC_ERRORREPORT(s32RetStatus, WILC_FAIL);
- }
- /* check buffer size */
- if (u32RecvBufferSize < pstrMessage->u32Length) {
- spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
- up(&pHandle->hSem);
- WILC_ERRORREPORT(s32RetStatus, WILC_BUFFER_OVERFLOW);
- }
-
- /* consume the message */
- pHandle->u32ReceiversCount--;
- memcpy(pvRecvBuffer, pstrMessage->pvBuffer, pstrMessage->u32Length);
- *pu32ReceivedLength = pstrMessage->u32Length;
+ /* other non-timeout scenarios */
+ if (result) {
+ PRINT_ER("Non-timeout\n");
+ return result;
+ }
- pHandle->pstrMessageList = pstrMessage->pstrNext;
+ if (pHandle->bExiting) {
+ PRINT_ER("pHandle fail\n");
+ return -EFAULT;
+ }
- kfree(pstrMessage->pvBuffer);
- kfree(pstrMessage);
+ spin_lock_irqsave(&pHandle->strCriticalSection, flags);
+ pstrMessage = pHandle->pstrMessageList;
+ if (!pstrMessage) {
spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
-
+ PRINT_ER("pstrMessage is null\n");
+ return -EFAULT;
}
-
- WILC_CATCH(s32RetStatus)
- {
+ /* check buffer size */
+ if (u32RecvBufferSize < pstrMessage->u32Length) {
+ spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
+ up(&pHandle->hSem);
+ PRINT_ER("u32RecvBufferSize overflow\n");
+ return -EOVERFLOW;
}
- return s32RetStatus;
+ /* consume the message */
+ pHandle->u32ReceiversCount--;
+ memcpy(pvRecvBuffer, pstrMessage->pvBuffer, pstrMessage->u32Length);
+ *pu32ReceivedLength = pstrMessage->u32Length;
+
+ pHandle->pstrMessageList = pstrMessage->pstrNext;
+
+ kfree(pstrMessage->pvBuffer);
+ kfree(pstrMessage);
+
+ spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
+
+ return result;
}