Skip to contentSkip to conversation

iio/proximity/srf08: Improve unlocking of a mutex in srf08_read_ranging()

PATCH In review SF Markus Elfring 2 participants 2 messages Oct 26, 2017

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

PATCH 1/1 iio/proximity/srf08: Improve unlocking of a mutex in srf08_read_ranging()

From: Markus Elfring <[email protected]>
Date: Thu, 26 Oct 2017 16:51:08 +0200

Add a jump target so that a call of the function "mutex_unlock" is stored only once at the end of this function implementation.
Replace two calls by goto statements.

This issue was detected by using the Coccinelle software.

---
 drivers/iio/proximity/srf08.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/iio/proximity/srf08.c +5 -9
index f2bf783f829a..85957550195b 100644
@@ -135,8 +135,7 @@ static int srf08_read_ranging(struct srf08_data *data)
 			SRF08_WRITE_COMMAND, SRF08_CMD_RANGING_CM);
 	if (ret < 0) {
 		dev_err(&client->dev, "write command - err: %d\n", ret);
-		mutex_unlock(&data->lock);
-		return ret;
+		goto unlock;
 	}
 
 	/*
@@ -163,20 +162,17 @@ static int srf08_read_ranging(struct srf08_data *data)
 
 	if (ret >= 255 || ret <= 0) {
 		dev_err(&client->dev, "device not ready\n");
-		mutex_unlock(&data->lock);
-		return -EIO;
+		ret = -EIO;
+		goto unlock;
 	}
 
 	ret = i2c_smbus_read_word_swapped(data->client,
 						SRF08_READ_ECHO_1_HIGH);
-	if (ret < 0) {
+	if (ret < 0)
 		dev_err(&client->dev, "cannot read distance: ret=%d\n", ret);
-		mutex_unlock(&data->lock);
-		return ret;
-	}
 
+unlock:
 	mutex_unlock(&data->lock);
-
 	return ret;
 }
 
Signature · 1 line
2.14.3
maintainer
#1 lore raw
Quoted 10 lines · On Thu, 26 Oct 2017 17:00:07 +0200 SF Markus Elfring…

From: Markus Elfring <[email protected]>
Date: Thu, 26 Oct 2017 16:51:08 +0200

Add a jump target so that a call of the function "mutex_unlock" is stored only once at the end of this function implementation.
Replace two calls by goto statements.

This issue was detected by using the Coccinelle software.

This simple case is a reasonable change. A few minor points though. Firstly, for a given subsystem please look at other patches to identify the standard formatting used in patch titles.

Secondly make sure you don't make unconnected changes. Here there is a whitespace change that should not be here.

Jonathan

Quoted 30 lines
---
 drivers/iio/proximity/srf08.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)
drivers/iio/proximity/srf08.c +3 -4
index f2bf783f829a..85957550195b 100644
@@ -135,8 +135,7 @@ static int srf08_read_ranging(struct srf08_data *data)
 			SRF08_WRITE_COMMAND, SRF08_CMD_RANGING_CM);
 	if (ret < 0) {
 		dev_err(&client->dev, "write command - err: %d\n", ret);
-		mutex_unlock(&data->lock);
-		return ret;
+		goto unlock;
 	}
 
 	/*
@@ -163,20 +162,17 @@ static int srf08_read_ranging(struct srf08_data *data)
 
 	if (ret >= 255 || ret <= 0) {
 		dev_err(&client->dev, "device not ready\n");
-		mutex_unlock(&data->lock);
-		return -EIO;
+		ret = -EIO;
+		goto unlock;
 	}
 
 	ret = i2c_smbus_read_word_swapped(data->client,
 						SRF08_READ_ECHO_1_HIGH);

drivers/iio/proximity/srf08.c static int srf08_read_ranging(struct srf08_data *data) · line 179

Quoted 10 lines
drivers/iio/proximity/srf08.c +2 -5
-	if (ret < 0) {
+	if (ret < 0)
 		dev_err(&client->dev, "cannot read distance: ret=%d\n", ret);
-		mutex_unlock(&data->lock);
-		return ret;
-	}
 
+unlock:
 	mutex_unlock(&data->lock);
-

Please don't make unconnected white space changes.

Quoted 3 lines
drivers/iio/proximity/srf08.c +0 -0
 	return ret;
 }