From patchwork Mon Oct 23 19:46:40 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: 10023001 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 E238460245 for ; Mon, 23 Oct 2017 19:46:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CA10228584 for ; Mon, 23 Oct 2017 19:46:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCB402891E; Mon, 23 Oct 2017 19:46:56 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5F88728584 for ; Mon, 23 Oct 2017 19:46:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D957A6E06F; Mon, 23 Oct 2017 19:46:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.web.de (mout.web.de [212.227.15.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5B41D6E06F for ; Mon, 23 Oct 2017 19:46:50 +0000 (UTC) Received: from [192.168.1.2] ([92.225.242.157]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0LjaR6-1dVT7h1qNk-00bZHT; Mon, 23 Oct 2017 21:46:41 +0200 To: etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Chris Wilson , Christian Gmeiner , David Airlie , Lucas Stach , Russell King From: SF Markus Elfring Subject: [PATCH] drm/etnaviv: Improve unlocking of a mutex in etnaviv_iommu_map_gem() Message-ID: <5a6c753f-d822-fb9e-0ea4-054754bdf4cc@users.sourceforge.net> Date: Mon, 23 Oct 2017 21:46:40 +0200 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:L9R6qgQeGtZjYDmi/oSRO46svRiPVcEHzwKJGWSU4TuXxHpwzmi RIlAEJADqJQ/T1jnG6OjuvIMma8kTGJ1aI/3jT7r2IV9h9WqAuawGuc+3eApRgkxGsZEPAS afWCDejoEpuGa1U4qFNtWGgAu/0uIBZz9M2T8zdD+kDAGL8zATHqTpJH28wjbVgwxEWHDTE iZLLV9uQBz4HBLLCj/+Iw== X-UI-Out-Filterresults: notjunk:1; V01:K0:4zDuMjytHG0=:cBX5exEB432q3f4Pa5OEpL gHCvwuruJ5G/kwEsKD9bM0P9a4JnUviFkG6mHaI1iw495tN1/okLpgcgCW4PAWDzpJ98S8Zno T92VWeF7YeAQtLxaey0ybohOIpNuRPg8Jtq0jT/WbqNGRpx2ZFdqeaIsTY1/ivVFIB4xcFa8B UX3865Aoxafw5KHVjECCwx1flwJfRp1sBQ9N+TmUQumju+thyNjkaA5WB0W/F1yQl4h+wOMCr pl4MI0q0GN6zhUkLHFzY2d2TpZdH1XYh1M5LPXoGBoUfz2HvQ4cD0pWvOY2oIhaNVrCRrE8Z8 DmlpbJlCSzgV6XPA4Pzdp75mBpifQ1qlBN4p+UH27v8rxxgRc974Ehf72SrBlg1wKFpTEqYMB g843rvbcs8+EMd0bk5/nBkkk6e23jb59HgzpnauFzXTxW4UuTj/JcvBCPvfEYeAVdRcaeXoyp Obj1y8zAfrw4ad/xfnub8EZeWjoCx11Z6av/ObIaxrz9UA7dHEc40FMd4Koxk6JQ6c27+cYMI u8gp+/UYN8/g0A/HZvSw/tiGfKKsHIuvbcuzjRsLDsLc1Xn+xb9D6EBkfcdrOoF52LZeKhkB2 lDcpmC4CKzvr0hfY9ysZHuH5SIwq8QzSIXl8781BOyqkyyalY4B48GasGpbSA0WSbYG/6z80E 05NZ72iNUwig3ARGibrzGpMxcXod77zKmvMV9zeIAxw2wGOAWlUaQ7NcJsffq5jB9UR0VRxbH ztYEd/rhSP/dM9H9KvxRsrzj0VgtK73q9LTmeEPNgI7IfgMRZZ9XC6m8TzEr4L6EbOwm+N/YI 0oOf/0e7/1qE45OFWarTnhxMcJY+tfS6yOD5Uhnc9sIBnkn8RI= Cc: kernel-janitors@vger.kernel.org, LKML X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Mon, 23 Oct 2017 21:27:30 +0200 Add a jump target so that a call of the function "mutex_unlock" is stored only once at the end of this function implementation. Replace three calls by goto statements. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/gpu/drm/etnaviv/etnaviv_mmu.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c index f103e787de94..9b0d797349d4 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_mmu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_mmu.c @@ -221,18 +221,16 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu, if (iova < 0x80000000 - sg_dma_len(sgt->sgl)) { mapping->iova = iova; list_add_tail(&mapping->mmu_node, &mmu->mappings); - mutex_unlock(&mmu->lock); - return 0; + ret = 0; + goto unlock; } } node = &mapping->vram_node; ret = etnaviv_iommu_find_iova(mmu, node, etnaviv_obj->base.size); - if (ret < 0) { - mutex_unlock(&mmu->lock); - return ret; - } + if (ret < 0) + goto unlock; mmu->last_iova = node->start + etnaviv_obj->base.size; mapping->iova = node->start; @@ -242,13 +240,12 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu, if (ret < 0) { drm_mm_remove_node(node); - mutex_unlock(&mmu->lock); - return ret; + goto unlock; } list_add_tail(&mapping->mmu_node, &mmu->mappings); mmu->need_flush = true; +unlock: mutex_unlock(&mmu->lock); - return ret; }