* [PATCH] staging: iio: ad7746: Improve unlocking of a mutex in ad7746_start_calib()
@ 2017-11-03 8:33 SF Markus Elfring
2017-11-19 15:37 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: SF Markus Elfring @ 2017-11-03 8:33 UTC (permalink / raw)
To: devel, linux-iio, Greg Kroah-Hartman, Hartmut Knaack,
Jonathan Cameron, Lars-Peter Clausen, Michael Hennerich,
Peter Meerwald-Stadler
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
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,
--
2.15.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] staging: iio: ad7746: Improve unlocking of a mutex in ad7746_start_calib()
2017-11-03 8:33 [PATCH] staging: iio: ad7746: Improve unlocking of a mutex in ad7746_start_calib() SF Markus Elfring
@ 2017-11-19 15:37 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2017-11-19 15:37 UTC (permalink / raw)
To: SF Markus Elfring
Cc: devel, linux-iio, Greg Kroah-Hartman, Hartmut Knaack,
Lars-Peter Clausen, Michael Hennerich, Peter Meerwald-Stadler,
LKML, kernel-janitors
On Fri, 3 Nov 2017 09:33:57 +0100
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
Again, a reasonable little tidy up. Applied to the togreg branch
of iio.git and pushed out as testing for the autobuilders to check
we haven't missed anything.
Thanks,
Jonathan
> ---
> 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,
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-11-19 15:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-03 8:33 [PATCH] staging: iio: ad7746: Improve unlocking of a mutex in ad7746_start_calib() SF Markus Elfring
2017-11-19 15:37 ` Jonathan Cameron
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).