From patchwork Thu Oct 26 15:00:07 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: 10028483 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 185C160375 for ; Thu, 26 Oct 2017 15:00:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 08EEE28E8F for ; Thu, 26 Oct 2017 15:00:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1BD628E86; Thu, 26 Oct 2017 15:00:39 +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 A144628E8B for ; Thu, 26 Oct 2017 15:00:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932331AbdJZPA0 (ORCPT ); Thu, 26 Oct 2017 11:00:26 -0400 Received: from mout.web.de ([212.227.17.11]:56248 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932246AbdJZPAZ (ORCPT ); Thu, 26 Oct 2017 11:00:25 -0400 Received: from [192.168.1.2] ([78.48.35.118]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MWS3S-1dfYlE3JU2-00XfYA; Thu, 26 Oct 2017 17:00:10 +0200 To: linux-iio@vger.kernel.org, Andreas Klinger , Hartmut Knaack , Jonathan Cameron , Lars-Peter Clausen , Peter Meerwald-Stadler Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] iio/proximity/srf08: Improve unlocking of a mutex in srf08_read_ranging() Message-ID: <62f61dbd-b106-1d3f-fb75-3fa87251e6ef@users.sourceforge.net> Date: Thu, 26 Oct 2017 17:00:07 +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:tQn5nNYyLiRQbyR1NLolrl1u0Ec4juUz/RILQ5goRD/w9acvA9A SGia/4fBs/7uIKcs16Tgx3Nkdc9xS06ykIfpzE+55hKwaohe8OPZUfKVX5J3t0jYqG0WkDt loFOmw6LPH2vrHbo4caDH/Qge6CJ8Xbt+QqcgluoloBh7meJ/M1fshEdeTpcPUEoSDklp9P kI8Oe73OkrJ2tu9wcFQbA== X-UI-Out-Filterresults: notjunk:1; V01:K0:NQMTNDlH/70=:OI9d6D366yM+ijP5cD2Wnm ueEWCbDeJwfboQbG3vQMu7uFJfCh3DlXYIn7Mxj7chhTMsHipSmQtNAFP0xEzyWlFFkA54sV1 6/xxzL6R5I/8sY+wZBcRA2eS/SwYPpFQRMfu3mgcvSC/htWAoUXSoUvpkDTwRgrkwfX7SgTX7 NzMVQMtcEGRJ1mNMMgsupZZU6yxgOsDcuEjNkVQtR7TatWdicQhuWoBO/tQZuT909hKnjmWl3 JTxb6IVD7bIs7qzi8QlJn7O00Itskru04Nkod4qJi48UIF/kgjFiTL40JZExA0UxMFmatnFCj y7kifAuebA3DGvRChuwkVQL/oLKLciPHzNMKjNoRxG+qq+8uAtzuAbqU6Xr4M9addcLz7757M hKMdEgdUvzj2BTX9mNKShI3cSc68/UE9LOww/8O/OO2MfFACsW8Ei/9mEH343CbrWLHO6nQT7 F7DPOqKdR+bLy4hUtloHHLufDtatQl3hOrShRwNOmxQYnrubiyizniZgSqmhDSAe+8dWDtmpN I3MIGE4usAknJWsAJwNGKt+acr//RXzFulFD6hFIkfYLfjxOLJlnqUkABB/O6cW7KwvuFpMYu wsldKf1oMKj9qpaWUJ8kPL/h/5ssKxfsISA2gtCimBCHrEDkVpxlIEG1m4C28DA64wNzcSxKV oPAncRlhtVHsztJqkomP7kZVXyR03VioSb1i6jkTCAuBTfpSR6fJhJru5fStjotVN3NMCLtjQ FIvexrxfRZHy3kEqxEi0TljINUqX6526PPqjFG6eGDTVp9YXB+kPnz8nSYDCeShA8pT+ZzFtu vVKI5p7gxeo5oL/JTjBlRw/qC//3Gmcki9ZaLcLG9W9jjLd+UQ= 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: Thu, 26 Oct 2017 16:51:08 +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 two calls by goto statements. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/iio/proximity/srf08.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/iio/proximity/srf08.c b/drivers/iio/proximity/srf08.c index f2bf783f829a..85957550195b 100644 --- a/drivers/iio/proximity/srf08.c +++ b/drivers/iio/proximity/srf08.c @@ -135,8 +135,7 @@ static int srf08_read_ranging(struct srf08_data *data) SRF08_WRITE_COMMAND, SRF08_CMD_RANGING_CM); if (ret < 0) { dev_err(&client->dev, "write command - err: %d\n", ret); - mutex_unlock(&data->lock); - return ret; + goto unlock; } /* @@ -163,20 +162,17 @@ static int srf08_read_ranging(struct srf08_data *data) if (ret >= 255 || ret <= 0) { dev_err(&client->dev, "device not ready\n"); - mutex_unlock(&data->lock); - return -EIO; + ret = -EIO; + goto unlock; } ret = i2c_smbus_read_word_swapped(data->client, SRF08_READ_ECHO_1_HIGH); - if (ret < 0) { + if (ret < 0) dev_err(&client->dev, "cannot read distance: ret=%d\n", ret); - mutex_unlock(&data->lock); - return ret; - } +unlock: mutex_unlock(&data->lock); - return ret; }