From patchwork Sun Nov 19 09:56:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 10065113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 15745602B7 for ; Sun, 19 Nov 2017 10:05:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11C9029222 for ; Sun, 19 Nov 2017 10:05:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E954129339; Sun, 19 Nov 2017 10:05:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FE6429222 for ; Sun, 19 Nov 2017 10:05:52 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id DC2F1266E3A; Sun, 19 Nov 2017 10:57:49 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id A4755266E3E; Sun, 19 Nov 2017 10:57:48 +0100 (CET) Received: from mout.web.de (mout.web.de [212.227.15.3]) by alsa0.perex.cz (Postfix) with ESMTP id 14EF1266DE0 for ; Sun, 19 Nov 2017 10:57:46 +0100 (CET) Received: from [192.168.1.3] ([92.225.173.18]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MBCMP-1eQ0sG2YB3-00AF2K; Sun, 19 Nov 2017 10:57:37 +0100 To: alsa-devel@alsa-project.org, Arnd Bergmann , Colin Ian King , Jaroslav Kysela , Jie Yang , Liam Girdwood , Mark Brown , Takashi Iwai From: SF Markus Elfring Message-ID: <49e56746-f178-d0e1-7b01-c75bde63f72c@users.sourceforge.net> Date: Sun, 19 Nov 2017 10:56:37 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 Content-Language: en-GB X-Provags-ID: V03:K0:OGyGhH2g/qJBAO6Ijo28jHaOl0hFb/eyLbsWMkddI2fDNXj62p7 KUj5pLE/c9BU4nC03pp2fS+86iQdBa0weQlSpD5JXmsv8JHvcM7xceUZ0jTpCO/JlCFxjfb gWLWUDYh2rXAmmpreWennlRKYMAyDbxWxqbkOxj3H6GV5fS3wvtNoHx9kMCIuKW9j9Zl3fS IUE3SpBJGe58TfJzPypHw== X-UI-Out-Filterresults: notjunk:1; V01:K0:cl8WXNqc+k8=:AJmnxn/d26AoJjmzlErsuH vnRoFa3upfGAYKZ/Z2Xw2aN1DjWsglgckCxynNg7XxhAtJKOgxGhTBe2EzqIKDO0++jmwWXbV qyUeVW2wiQyGaA7VMrVC4t0fIS6x+UzWSHHVZp1A7foFtc2V5V+SQ0tuQvH9LD5eDlc4rc7jw VVgMMyuYP1pgJPq3Nty6r7TtaBZb3pLwMPKDTn3KVQOcyLKy3oi/Wz28rMly/SXIjamrhwHay DCb5NEmvjVuO/9uLkSLsuGTuPrvj2NqbDU4VQS9pUvoQSNk4qx0wEqZ/qBxkfR2FjOiwETEin UnvYwf4tix0uPzmhSW516F+B+S9R5pCGTC0L/2KhhYJAdd4AbsXQdDO28gUvsZM5F/Of0lFaH m1T3QFL6y73ZYe1TzIdPf9JJsWJjGH8G+aJn7GugSwnHr4gTuri3Pl0y27a35U2lzJIILwUSq zOsgiFORCeofeUgIO7bdD/IsLKhCYdi30Qg2QeKXHeY3cmzE5slUx1hyMEOVFyL0wh5lsf6pJ 3RCTYoM8Iw3ulbzY4lWS0ioUwln0IwqEhtKqlEUbI3V9MTIl3IN/Oi09HHoSiisH+LaiVtcGJ 4C1wmo9eDKgHIbRIFBoRxvJxeiYoZUkDlH6RiNJrcY4teLby7ddDxCiyHabaVdn4z/p+ErWqM fKVhuC1IAkjPfHn9DTYv/ciFXDwe+w4VvmwakAXqX8Zbpd5NDQUmRHA+zWtplQ65yu+aKodNS vASABRFAYEbvC069E9AwNIDCjlKYeqPR8T12jR8otYcvqTS+dOVWVakmy+YJ98cNWKeZX9Bvj fH+I1yIDQiTbOBGakU74giHR9s1+p6SOQKPYDvqt+BwckBJRctTQZw0h+b+zg4e4KM7S5C8 Cc: kernel-janitors@vger.kernel.org, LKML Subject: [alsa-devel] [PATCH] ASoC: sst-firmware: Improve unlocking of a mutex in sst_block_alloc_scratch() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 19 Nov 2017 10:45:36 +0100 * Add a jump target so that a call of the function "mutex_unlock" is stored only once in this function implementation. * Replace three calls by goto statements. * Increase the lock scope. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- sound/soc/intel/common/sst-firmware.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sound/soc/intel/common/sst-firmware.c b/sound/soc/intel/common/sst-firmware.c index 79a9fdf94d38..665e66670512 100644 --- a/sound/soc/intel/common/sst-firmware.c +++ b/sound/soc/intel/common/sst-firmware.c @@ -1097,8 +1097,8 @@ int sst_block_alloc_scratch(struct sst_dsp *dsp) if (dsp->scratch_size == 0) { dev_info(dsp->dev, "no modules need scratch buffer\n"); - mutex_unlock(&dsp->mutex); - return 0; + ret = 0; + goto unlock; } /* allocate blocks for module scratch buffers */ @@ -1127,21 +1127,21 @@ int sst_block_alloc_scratch(struct sst_dsp *dsp) } if (ret < 0) { dev_err(dsp->dev, "error: can't alloc scratch blocks\n"); - mutex_unlock(&dsp->mutex); - return ret; + goto unlock; } ret = block_list_prepare(dsp, &dsp->scratch_block_list); if (ret < 0) { dev_err(dsp->dev, "error: scratch block prepare failed\n"); - mutex_unlock(&dsp->mutex); - return ret; + goto unlock; } /* assign the same offset of scratch to each module */ dsp->scratch_offset = ba.offset; + ret = dsp->scratch_size; +unlock: mutex_unlock(&dsp->mutex); - return dsp->scratch_size; + return ret; } EXPORT_SYMBOL_GPL(sst_block_alloc_scratch);