From patchwork Wed Oct 25 20:17:29 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: 10027215 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 B1E3A601E8 for ; Wed, 25 Oct 2017 20:17:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A37E828C45 for ; Wed, 25 Oct 2017 20:17:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 986B028C54; Wed, 25 Oct 2017 20:17:50 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A1AB28C45 for ; Wed, 25 Oct 2017 20:17:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932194AbdJYURs (ORCPT ); Wed, 25 Oct 2017 16:17:48 -0400 Received: from mout.web.de ([212.227.15.3]:57590 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932162AbdJYURr (ORCPT ); Wed, 25 Oct 2017 16:17:47 -0400 Received: from [192.168.1.2] ([77.181.217.114]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0M8oFY-1e1voV2ltk-00C8Vg; Wed, 25 Oct 2017 22:17:32 +0200 Subject: [PATCH 2/2] iio/accel/stk8ba50: Improve unlocking of a mutex in stk8ba50_read_raw() From: SF Markus Elfring To: linux-iio@vger.kernel.org, Hartmut Knaack , Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler , Tiberiu Breana Cc: LKML , kernel-janitors@vger.kernel.org References: <5ab7e200-2dea-63e2-06db-0e185f563d16@users.sourceforge.net> Message-ID: <8e9436af-440e-b4a8-5024-1f2a51c41b6b@users.sourceforge.net> Date: Wed, 25 Oct 2017 22:17:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <5ab7e200-2dea-63e2-06db-0e185f563d16@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:kh38EoXeQE9GBKnBsnJciY057394orCabaXrQanNrYgtZi//pe4 wCmUAUSotwgj8crdt823h5qXkoB2ExDwmFL9M57SNC67cIVRO9dXE6x5jwv8BhAulnZm4W4 cZ7kWnBAKuZxEHO8ieszldxcJF7+yvXL4EM4no0aYxwozOEy9bxNy3SC1H2gzP1pKdtvqfN nlMXo6Tnx7m72DgRi7pPg== X-UI-Out-Filterresults: notjunk:1; V01:K0:wnZG3CAXfsY=:rLdfWkQgQkRCcX/0uQCKLK 2kTtxnvE6N2gsU5fkl+5F01qlUUtYK6EhbIoO159ZLNAfPwId5t9xgVwFokES+XwD5JfPic36 vGmFdGOpJCrA7MA4DQX8+3Y27n2KZD3dXoCTk6mauacxA+Dn8VtrxrxFaUc+nGWEi2xnnuPIB fnPWaUh1myXzwO+cAh6DYz+z+DanQ8dDSuesKNqdf/MzPotLtyPCbq1BQT1FHnFXPYIVyPb2n X/F8PSNEWzPQAv/D+aKQC1REPVWVsK8X6/uH9u07D1uqDdDb6cKVJdisN9kdD1vlnF4bkQMbf NogzF4uVYb8VVBVqmGEy0exzQIZexqK0oR5nTONbLBwFlgVZvj9FuTI6Jeb5ubg9JlVaHdwqY nRpLy96B/VZqf9P/jJ5/zIVctyfY83+2+6BxtqqLouByy5y24nyztoaJHIrDTe/YDRysISZa5 9vBZFhqvowdkjWZ06Uf5hK52mwbhMA6pcATBFwjlJpANtdtlmh0nDXbNwr607Yt7C3V28vnoQ dbGPS5dvSC7UurnSrCQjnnhcX+7Dz5Ye1kEtyahR0A3BRmgZdveKikO5PCsae2N2oDrAsu5Ye McO1P+CthjVnECUcXW64KOu0Z9aNGxSM4UvSgNSLmNTFghyDv5XgEclxXcLJhwreqpCxSzvqD 8Uorwcuttx6XEet141srA29vRqQ+96WZk4mCQl7hRk20kNuksoePV42c+cOqT150eMChZEpRT yBDOiGaloGp9VOZft4ozw1cPwiBCmwUvdyPrHqO6wjecQs4zPfZPtcLE43UR/zF07wlaMi3DW cBAFqTgNjCxKFKu8KPMLjmqVQOILYMHENAz+4lcPXi9UGHXFhM= Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Wed, 25 Oct 2017 22:00:42 +0200 Adjust jump targets so that a call of the function "mutex_unlock" is stored only once in a case branch of this function implementation. Replace two calls by goto statements. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/iio/accel/stk8ba50.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/drivers/iio/accel/stk8ba50.c b/drivers/iio/accel/stk8ba50.c index afe90567ad37..ffc26b5d1fad 100644 --- a/drivers/iio/accel/stk8ba50.c +++ b/drivers/iio/accel/stk8ba50.c @@ -221,20 +221,24 @@ static int stk8ba50_read_raw(struct iio_dev *indio_dev, return -EBUSY; mutex_lock(&data->lock); ret = stk8ba50_set_power(data, STK8BA50_MODE_NORMAL); - if (ret < 0) { - mutex_unlock(&data->lock); - return -EINVAL; - } + if (ret < 0) + goto e_inval; + ret = stk8ba50_read_accel(data, chan->address); if (ret < 0) { stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); - mutex_unlock(&data->lock); - return -EINVAL; +e_inval: + ret = -EINVAL; + goto unlock; } *val = sign_extend32(ret >> STK8BA50_DATA_SHIFT, 9); - stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); + ret = stk8ba50_set_power(data, STK8BA50_MODE_SUSPEND); +unlock: mutex_unlock(&data->lock); - return IIO_VAL_INT; + if (ret >= 0) + ret = IIO_VAL_INT; + + return ret; case IIO_CHAN_INFO_SCALE: *val = 0; *val2 = stk8ba50_scale_table[data->range].scale_val;