From patchwork Fri Nov 3 08:33:57 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: 10039663 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 CFF766032D for ; Fri, 3 Nov 2017 08:34:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCDF729174 for ; Fri, 3 Nov 2017 08:34:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B1801291A8; Fri, 3 Nov 2017 08:34:34 +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 6368529174 for ; Fri, 3 Nov 2017 08:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754141AbdKCIed (ORCPT ); Fri, 3 Nov 2017 04:34:33 -0400 Received: from mout.web.de ([212.227.15.14]:50090 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752465AbdKCIea (ORCPT ); Fri, 3 Nov 2017 04:34:30 -0400 Received: from [192.168.1.3] ([78.49.7.122]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MgO9u-1do4tp0CLG-00NjTG; Fri, 03 Nov 2017 09:34:11 +0100 To: devel@driverdev.osuosl.org, linux-iio@vger.kernel.org, Greg Kroah-Hartman , Hartmut Knaack , Jonathan Cameron , Lars-Peter Clausen , Michael Hennerich , Peter Meerwald-Stadler Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Subject: [PATCH] staging: iio: ad7746: Improve unlocking of a mutex in ad7746_start_calib() Message-ID: <57f5d20b-cc13-07b2-51cf-53704327df27@users.sourceforge.net> Date: Fri, 3 Nov 2017 09:33:57 +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:kJxyeezv43zrIq/yJN1Zkxs5Iab3b5jFVwNiYFU8QaJUMGFHIlP 8ws56H1Ttcl14WaYhQe3ZVF/4AkBpsoymLiFMlpNeuHxuH0BC6YOImzReh9ZJK2PLb2CMsU 0XQMliDYp0DYP5dmq5NWbig4LrCULS1soUJt05sIT8t3CIKkxG6KnTNjVqxJ1vwKLKwEtG3 g8sC69fLTFegATWyShvKA== X-UI-Out-Filterresults: notjunk:1; V01:K0:dLmyfr/x1hk=:nILEPgrIQMgPO3N5xX7jsU Dez0RSwkt4CrxivWtUY2nwq+gUFhWog4R278YhScMOqbLXWxJvUEfCKrj0jx89A4V3u/OPmev sVleq66mxjrSwXIDZhYgDE52mMFvnYwaevYbj1Y4E4I3l6gxODcHP7JwXSB9t8zD45JLBOO46 Bn9itt7t7wWcj+VW/2dXs+6Oh+mfIBf1FIIa4MQETsr5Te0WHVPV0PKKNJgTW/JmpGv58CrUL OSSxdqQcJf6oLi+44Er7l4IXfGbHox0vhdtJC0mc9+uvmf5gv6M282MusgM5RIw4ZnZOipxgB nu8kVLqYkj1vGS3US0RvTr7jARpgt/6EahvbEjByE7ogTuOMlPDOIACizF01Doiy6aRFSHnYG JIKBe6Pg7jZu9XGIbDEdYAsO3MLnCgouAbo8PYx31zdlFdyveobinLDx8GNdlvdi5TMp1UMwx ngVqDxcCvzblMAYw1oDKa7FsaY0GJBKPZkTwYep2wiv+/1o0iwwXVaGSokDNPCE12O8lppORk W9V1aHOXES944frJnCwhjS7/FEyTZRuFBGd9F46qk/8YKGEYEzufquP2P5IsMI4nlw5NWBDqJ qy3Wxk26aPMP7KEx9A2+Dtss7pPDeG1BqMD2n3R8L0kVXnxx08dhyN6kQB2NX4hL6QuzpmK5t bLaHBHeMmNNDd+oByhsKhP+2tU9JJZtZ34Eu/880Zeaes7L6xd5+qUnD8FcB9hMppheo1o/31 8ErzbVKRCUmVCMl6jPzSS2jia1lWztWBmq8xtrX+bQxzdYKOkkWbJIeCAOYHeDepmfH2Aq3cL Q1O0veVrlGvWVv/QGehTKlrh8pEzbHc70WfHN0W7nouXBb1czQ= 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: Fri, 3 Nov 2017 09:26:28 +0100 * Add a jump target so that a call of the function "mutex_unlock" is stored only twice in this function implementation. * Replace two calls by goto statements. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- drivers/staging/iio/cdc/ad7746.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c index a124853a05f0..c4a864725376 100644 --- a/drivers/staging/iio/cdc/ad7746.c +++ b/drivers/staging/iio/cdc/ad7746.c @@ -302,23 +302,24 @@ static inline ssize_t ad7746_start_calib(struct device *dev, mutex_lock(&chip->lock); regval |= chip->config; ret = i2c_smbus_write_byte_data(chip->client, AD7746_REG_CFG, regval); - if (ret < 0) { - mutex_unlock(&chip->lock); - return ret; - } + if (ret < 0) + goto unlock; do { msleep(20); ret = i2c_smbus_read_byte_data(chip->client, AD7746_REG_CFG); - if (ret < 0) { - mutex_unlock(&chip->lock); - return ret; - } + if (ret < 0) + goto unlock; + } while ((ret == regval) && timeout--); mutex_unlock(&chip->lock); return len; + +unlock: + mutex_unlock(&chip->lock); + return ret; } static ssize_t ad7746_start_offset_calib(struct device *dev,