From patchwork Mon Oct 19 09:03:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Cho X-Patchwork-Id: 7434601 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BEAA89F302 for ; Mon, 19 Oct 2015 09:03:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D6F7920712 for ; Mon, 19 Oct 2015 09:03:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 611F920709 for ; Mon, 19 Oct 2015 09:03:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752654AbbJSJDc (ORCPT ); Mon, 19 Oct 2015 05:03:32 -0400 Received: from eusmtp01.atmel.com ([212.144.249.242]:5495 "EHLO eusmtp01.atmel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750876AbbJSJDb (ORCPT ); Mon, 19 Oct 2015 05:03:31 -0400 Received: from tony-itx.corp.atmel.com (10.161.101.13) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server id 14.3.235.1; Mon, 19 Oct 2015 11:03:28 +0200 From: Tony Cho To: CC: , , , , , , , , Subject: [PATCH V3] staging: wilc1000: wilc_msgqueue.c : add goto statement Date: Mon, 19 Oct 2015 18:03:15 +0900 Message-ID: <1445245395-9976-1-git-send-email-tony.cho@atmel.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Leo Kim 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 Signed-off-by: Tony Cho --- 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; }