Linux wireless drivers development
 help / color / mirror / Atom feed
From: Tony Cho <tony.cho@atmel.com>
To: <gregkh@linuxfoundation.org>
Cc: <devel@driverdev.osuosl.org>, <linux-wireless@vger.kernel.org>,
	<tony.cho@atmel.com>, <glen.lee@atmel.com>, <leo.kim@atmel.com>,
	<austin.shin@atmel.com>, <adel.noureldin@atmel.com>,
	<adham.abozaeid@atmel.com>, <Nicolas.FERRE@atmel.com>
Subject: [PATCH V3] staging: wilc1000: wilc_msgqueue.c : add goto statement
Date: Mon, 19 Oct 2015 18:03:15 +0900	[thread overview]
Message-ID: <1445245395-9976-1-git-send-email-tony.cho@atmel.com> (raw)

From: Leo Kim <leo.kim@atmel.com>

This patch uses goto statement to separet error conditionals into release_lock
and mem_free in wilc_mq_send. If unexpected errors happen, this function
cannot up the semaphore, otherwise, if no errors, the semaphore should be
released, but freeing memory is not needed in this function.

Signed-off-by: Leo Kim <leo.kim@atmel.com>
Signed-off-by: Tony Cho <tony.cho@atmel.com>
---
V3: use goto statement to seperate error types into release_lock and mem_free
---
 drivers/staging/wilc1000/wilc_msgqueue.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_msgqueue.c b/drivers/staging/wilc1000/wilc_msgqueue.c
index b13809a..bb4e93c 100644
--- a/drivers/staging/wilc1000/wilc_msgqueue.c
+++ b/drivers/staging/wilc1000/wilc_msgqueue.c
@@ -63,28 +63,31 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
 	if ((!pHandle) || (u32SendBufferSize == 0) || (!pvSendBuffer)) {
 		PRINT_ER("pHandle or pvSendBuffer is null\n");
 		result = -EFAULT;
-		goto ERRORHANDLER;
+		goto out;
 	}
 
 	if (pHandle->bExiting) {
 		PRINT_ER("pHandle fail\n");
 		result = -EFAULT;
-		goto ERRORHANDLER;
+		goto out;
 	}
 
 	spin_lock_irqsave(&pHandle->strCriticalSection, flags);
 
 	/* construct a new message */
 	pstrMessage = kmalloc(sizeof(Message), GFP_ATOMIC);
-	if (!pstrMessage)
-		return -ENOMEM;
+	if (!pstrMessage) {
+		result = -ENOMEM;
+		goto release_lock;
+	}
+
 	pstrMessage->u32Length = u32SendBufferSize;
 	pstrMessage->pstrNext = NULL;
 	pstrMessage->pvBuffer = kmemdup(pvSendBuffer, u32SendBufferSize,
 					GFP_ATOMIC);
 	if (!pstrMessage->pvBuffer) {
 		result = -ENOMEM;
-		goto ERRORHANDLER;
+		goto mem_free;
 	}
 
 	/* add it to the message queue */
@@ -103,13 +106,13 @@ int wilc_mq_send(WILC_MsgQueueHandle *pHandle,
 
 	up(&pHandle->hSem);
 
-ERRORHANDLER:
-	/* error occured, free any allocations */
-	if (pstrMessage) {
-		kfree(pstrMessage->pvBuffer);
-		kfree(pstrMessage);
-	}
+	return 0;
 
+mem_free:
+	kfree(pstrMessage);
+release_lock:
+	spin_unlock_irqrestore(&pHandle->strCriticalSection, flags);
+out:
 	return result;
 }
 
-- 
1.9.1


             reply	other threads:[~2015-10-19  9:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-19  9:03 Tony Cho [this message]
2015-10-19 11:42 ` [PATCH V3] staging: wilc1000: wilc_msgqueue.c : add goto statement Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445245395-9976-1-git-send-email-tony.cho@atmel.com \
    --to=tony.cho@atmel.com \
    --cc=Nicolas.FERRE@atmel.com \
    --cc=adel.noureldin@atmel.com \
    --cc=adham.abozaeid@atmel.com \
    --cc=austin.shin@atmel.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=glen.lee@atmel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=leo.kim@atmel.com \
    --cc=linux-wireless@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox