From: Jonathan Cameron <jic23@kernel.org>
To: SF Markus Elfring <elfring@users.sourceforge.net>
Cc: devel@driverdev.osuosl.org, linux-iio@vger.kernel.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Hartmut Knaack <knaack.h@gmx.de>,
Lars-Peter Clausen <lars@metafoo.de>,
Michael Hennerich <Michael.Hennerich@analog.com>,
Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
LKML <linux-kernel@vger.kernel.org>,
kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] staging: iio: ad7152: Improve unlocking of a mutex in ad7152_start_calib()
Date: Sun, 19 Nov 2017 15:35:24 +0000 [thread overview]
Message-ID: <20171119153524.0a88acd9@archlinux> (raw)
In-Reply-To: <eef53bde-ab45-6e5c-8e0d-bd9cf7ebc431@users.sourceforge.net>
On Fri, 3 Nov 2017 09:09:21 +0100
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
A reasonable tidy up that slightly improves the code. Just makes
it past past the point where the benefit justifies the code churn.
Applied to the togreg branch of iio.git and pushed out as testing.
Thanks,
Jonathan
> ---
> 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,
prev parent reply other threads:[~2017-11-19 15:35 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-03 8:09 [PATCH] staging: iio: ad7152: Improve unlocking of a mutex in ad7152_start_calib() SF Markus Elfring
2017-11-19 15:35 ` Jonathan Cameron [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171119153524.0a88acd9@archlinux \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=devel@driverdev.osuosl.org \
--cc=elfring@users.sourceforge.net \
--cc=gregkh@linuxfoundation.org \
--cc=kernel-janitors@vger.kernel.org \
--cc=knaack.h@gmx.de \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmeerw@pmeerw.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).