From patchwork Wed Oct 25 14:33:12 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: 10026787 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 58B5660375 for ; Wed, 25 Oct 2017 14:33:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47DD828B0A for ; Wed, 25 Oct 2017 14:33:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C4F128BB5; Wed, 25 Oct 2017 14:33:40 +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 C214628B0A for ; Wed, 25 Oct 2017 14:33:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751725AbdJYOdj (ORCPT ); Wed, 25 Oct 2017 10:33:39 -0400 Received: from mout.web.de ([212.227.15.3]:60087 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751289AbdJYOdi (ORCPT ); Wed, 25 Oct 2017 10:33:38 -0400 Received: from [192.168.1.2] ([77.181.217.114]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MLxrY-1e6IPh0ftc-007hir; Wed, 25 Oct 2017 16:33:17 +0200 To: linux-iio@vger.kernel.org, Hans de Goede , Hartmut Knaack , Jonathan Cameron , Lars-Peter Clausen , Srinivas Pandruvada Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] iio/accel/bmc150: Improve unlocking of a mutex in two functions Message-ID: <66d582a4-a77e-cd78-4215-49587ec2259e@users.sourceforge.net> Date: Wed, 25 Oct 2017 16:33:12 +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:41e4dlmNbwSRFxRHjc9EoYRmo5JBfRzXAPPo79eFHWju/qH24NT mk8DL0o8viZ+tyhXvQXF110sJf4StDrLCRoxUTp65YUBiFIc8J3YqyRNHUj0Hn/6Ah7LkGU vv66p8sf0Bth4G0lWaiEFKEfmKqSGPo1sbCuhh2UAIwiDw7Xpw8p4U1J8Rkaf4Hdh9prDSQ PfFMEC1OPgj1/PR5zAuqA== X-UI-Out-Filterresults: notjunk:1; V01:K0:NhFdEV2OyWU=:J4EMy7/YhcHCI22N5jy7o+ /FvUeOC8Dlyto24Dk7dp/0dHuGFHkF4R4iSsdedvPRNFyTQihwz9vPMDrorAO/Vn82rfP6tfL 7XWCATtG8jEe9VuY3jvzmrFeI3uMBrfVWJVS1/MKlkryoIp9vAFDSEjSJhRKJXLA5nFh1xkua worp6Xn23c+NJaLy3CVEQ3S3/rMqUNpw19Wwu8z79wEje6mMyYIzmly43Qt6grULPB6Jj8Zt9 kmu1bQ+Rus7BXg64CU6HzpbebP0Ph3pFDbwngwlVb+75t/49HTaEP3mjMctcJWgAmR8izItav 1VmUElyRFNG+CBZblY3fqLeRxUIPJwTTIgfm0lj9K+1Bg5lLeferdxT//eBNNBrKxIlOL1NXJ UBoUBADOFntFyuabnT217VOzzcMZZfbOOdXjiCIKMjYg6uDGnuRI+RtX0UHyaWdmo6lebNRpy 9aHTQm8z0Tn/SbMK8RyeLzhbyOs7AJD+66SSW1zdgJ/sAniW6uUXNPg51Xhp/+uzlG4ueoNTa geKJZ+rZyZ55uOFGtBGeMw8A16pYcEnqjNGem4IuGwfqQGcFj/4YK1Y0VGYYlX4t0ouy5mVNd 7/WuAoY7j7jFyOM4uTFSQkqeCliBgA+PIJzWO0VP4bNYE5trjvoth33JX6SSevXqU7zS5wkfr pIMvyPumd0chMM/fIz94XBMfuXLn8u59GQMj+blkFoQ2wXyMsmj5NAHCGGktuYLDSgb3kr0Lh 8cJ1d4Fv/koAACJ7pknAh9SYEnjlNbR9+ZFRnOOLMFqS7MtMbmq1suXJv1VmWf92Cy4pzSH8/ A3q4EXZUqhmrO1ZBBATT8ZBYgzIbZrA4Gs1KoeOoEltRTD7K6I= 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 16:26:29 +0200 Add a jump target so that a call of the function "mutex_unlock" is mostly stored at the end of these function implementations. Replace five calls by goto statements. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/iio/accel/bmc150-accel-core.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 870f92ef61c2..f2a85a11a5e4 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -554,18 +554,15 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data, mutex_lock(&data->mutex); ret = bmc150_accel_set_power_state(data, true); - if (ret < 0) { - mutex_unlock(&data->mutex); - return ret; - } + if (ret < 0) + goto unlock_after_failure; ret = regmap_bulk_read(data->regmap, BMC150_ACCEL_AXIS_TO_REG(axis), &raw_val, sizeof(raw_val)); if (ret < 0) { dev_err(dev, "Error reading axis %d\n", axis); bmc150_accel_set_power_state(data, false); - mutex_unlock(&data->mutex); - return ret; + goto unlock_after_failure; } *val = sign_extend32(le16_to_cpu(raw_val) >> chan->scan_type.shift, chan->scan_type.realbits - 1); @@ -575,6 +572,10 @@ static int bmc150_accel_get_axis(struct bmc150_accel_data *data, return ret; return IIO_VAL_INT; + +unlock_after_failure: + mutex_unlock(&data->mutex); + return ret; } static int bmc150_accel_read_raw(struct iio_dev *indio_dev, @@ -1170,28 +1171,23 @@ static int bmc150_accel_trigger_set_state(struct iio_trigger *trig, mutex_lock(&data->mutex); if (t->enabled == state) { - mutex_unlock(&data->mutex); - return 0; + ret = 0; + goto unlock; } if (t->setup) { ret = t->setup(t, state); - if (ret < 0) { - mutex_unlock(&data->mutex); - return ret; - } + if (ret < 0) + goto unlock; } ret = bmc150_accel_set_interrupt(data, t->intr, state); - if (ret < 0) { - mutex_unlock(&data->mutex); - return ret; - } + if (ret < 0) + goto unlock; t->enabled = state; - +unlock: mutex_unlock(&data->mutex); - return ret; }