[PATCH 04/13] staging: wilc1000: wilc_mq_send: refactor allocation errors handling

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



In case the first allocation fails, we can return directly, and if the
second allocation fails we can goto to the end of the function where we
free the memory and return error.

Signed-off-by: Mike Rapoport <mike.rapoport@xxxxxxxxx>
---
 drivers/staging/wilc1000/wilc_msgqueue.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_msgqueue.c b/drivers/staging/wilc1000/wilc_msgqueue.c
index 127b3e5..6e032b8 100644
--- a/drivers/staging/wilc1000/wilc_msgqueue.c
+++ b/drivers/staging/wilc1000/wilc_msgqueue.c
@@ -65,11 +65,13 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
 
 	/* construct a new message */
 	pstrMessage = kmalloc(sizeof(Message), GFP_ATOMIC);
-	WILC_NULLCHECK(s32RetStatus, pstrMessage);
+	if (!pstrMessage)
+		return WILC_NULL_PTR;
 	pstrMessage->u32Length = u32SendBufferSize;
 	pstrMessage->pstrNext = NULL;
 	pstrMessage->pvBuffer = kmalloc(u32SendBufferSize, GFP_ATOMIC);
-	WILC_NULLCHECK(s32RetStatus, pstrMessage->pvBuffer);
+	if (!pstrMessage->pvBuffer)
+		goto err_alloc_buffer;
 	memcpy(pstrMessage->pvBuffer, pvSendBuffer, u32SendBufferSize);
 
 	/* add it to the message queue */
@@ -90,16 +92,13 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
 
 	up(&pHandle->hSem);
 
-	WILC_CATCH(s32RetStatus)
-	{
-		/* error occured, free any allocations */
-		if (pstrMessage) {
-			kfree(pstrMessage->pvBuffer);
-			kfree(pstrMessage);
-		}
-	}
-
 	return s32RetStatus;
+
+err_alloc_buffer:
+	/* error occurred, free any allocations */
+	kfree(pstrMessage);
+
+	return WILC_NULL_PTR;
 }
 
 /*!
-- 
2.1.0

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux