Skip to contentSkip to conversation

staging: iio: ad7746: Improve unlocking of a mutex in ad7746_start_calib()

PATCH In review SF Markus Elfring 2 participants 2 messages Nov 3, 2017 – Nov 19, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: iio: ad7746: Improve unlocking of a mutex in ad7746_start_calib()

From: Markus Elfring <[email protected]>
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.

---
 drivers/staging/iio/cdc/ad7746.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/staging/iio/cdc/ad7746.c +9 -8
index a124853a05f0..c4a864725376 100644
@@ -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,
Signature · 1 line
2.15.0
maintainer
#1 lore raw
Quoted 11 lines · On Fri, 3 Nov 2017 09:33:57 +0100 SF Markus Elfring…

From: Markus Elfring <[email protected]>
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.

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

Quoted 41 lines
---
 drivers/staging/iio/cdc/ad7746.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
drivers/staging/iio/cdc/ad7746.c +9 -8
index a124853a05f0..c4a864725376 100644
@@ -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,