From patchwork Fri Nov 3 08:09:21 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: 10039617 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 60CD9602DA for ; Fri, 3 Nov 2017 08:10:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5155629510 for ; Fri, 3 Nov 2017 08:10:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45C782952B; Fri, 3 Nov 2017 08:10:14 +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 F3DA029510 for ; Fri, 3 Nov 2017 08:10:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752743AbdKCIJv (ORCPT ); Fri, 3 Nov 2017 04:09:51 -0400 Received: from mout.web.de ([212.227.15.14]:54628 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752538AbdKCIJs (ORCPT ); Fri, 3 Nov 2017 04:09:48 -0400 Received: from [192.168.1.3] ([78.49.7.122]) by smtp.web.de (mrweb004 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lx2Wv-1d4oJn2AzR-016jRp; Fri, 03 Nov 2017 09:09:30 +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: ad7152: Improve unlocking of a mutex in ad7152_start_calib() Message-ID: Date: Fri, 3 Nov 2017 09:09:21 +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:eLKzdMUhLuEMlzqdcgX7XLIAXc6OgAUqp6n2mAVWhsXT5a8nn2L Js5LlgH5dd52VwMW2BzFdxEUer+ZxHxj07LHrCEODLcVyVfgUPBVdOnTE7WU49lsfHW1Hle wjvI9sHHe8RxLcYGQf66ZiPQssrqCMeGR0jUZ/uFsgizIOP5CWTEZJQ+70yfbWgQcRyGfJQ mUzfMr6Pp60U/mSjWG3zw== X-UI-Out-Filterresults: notjunk:1; V01:K0:fIZVEWdPhvk=:0n0tkDqAUofT0Uj9IHzToi czZ61vq8DWIOy5qqPe8o4auNaU2WuL1mKmsYovse01hBJsknJrKSmudLZJ7doXXMGetBYJMnD 0mpm4AvmBC0lRI4duQtnSWlC8CdlTbpck4ixrgc9rFhOl7t3s/VLE0Z1RXAQaOjMKhnP3BbET T6isy/g1pzaEqQM3NeHvO0nZ/kMyZth6VjAZ7j4LJ1qYlG/wGfghDIsWaBTVcGol/nKA+L/aJ 9yEZjEqAFFJj6xKxysnRrqAARN4epB2RcP0xI419nFI4o5cJvoAvcIEg+BVg6FbaAUUi7sgYz aYpRTPAZOb5e9cezvMYNMJ2CuWEpJI4OGsk1zc86RQifLYh8ylw78QsPC5l/yqodWZ0qxaxAq 3YTHakO5R8G1A9WlFW/XqAeE9LDz9SGbThrYvwGo4vtz0qwidbLNQinb2iHQyw0gmrBWzMpVM dJCi7+qHgEtfkc99wJdmz5h/ZTSTAbdTvOqW/4ad4b94gvNTd8MJi1V7X93Cb+gBuhZUmVbQA tHUnIUbmbqfOto60oJ468fPXan9+K+8cco2+nSlP/aU4tIJlREr8e+wGmfuEGFMNe2t/+aN8M q23KNkv+Vduz5Ao3dsNvIL8uucGYRJqSrXA5uYpSlrTFcPxRmASPSHgxyfce2gTsuP2axoBRj /iKYGUmQ6DdRRqvO1ZCVil2/1PTrbHeH0SeqbjbVUI/P9e3RuMkSM0zQxNux8ies/8JAAXbCQ GEtE+TJJwiho/j0fEs4S/3fg8lkTlw2c/qFYe3bZGujRNJj4t1FIqrPHPYMXN0k9CwdVLwkvk vDW17D7/Ljc01L4Rjr6HhgoFtTLp8MtqvgQFsFk/XxpEMBTU0s= 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:00:25 +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/ad7152.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c index 61377ca444de..59d1b35f6a4e 100644 --- a/drivers/staging/iio/cdc/ad7152.c +++ b/drivers/staging/iio/cdc/ad7152.c @@ -118,22 +118,23 @@ static inline ssize_t ad7152_start_calib(struct device *dev, mutex_lock(&chip->state_lock); ret = i2c_smbus_write_byte_data(chip->client, AD7152_REG_CFG, regval); - if (ret < 0) { - mutex_unlock(&chip->state_lock); - return ret; - } + if (ret < 0) + goto unlock; do { mdelay(20); ret = i2c_smbus_read_byte_data(chip->client, AD7152_REG_CFG); - if (ret < 0) { - mutex_unlock(&chip->state_lock); - return ret; - } + if (ret < 0) + goto unlock; + } while ((ret == regval) && timeout--); mutex_unlock(&chip->state_lock); return len; + +unlock: + mutex_unlock(&chip->state_lock); + return ret; } static ssize_t ad7152_start_offset_calib(struct device *dev,