lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 26 Oct 2017 17:00:07 +0200
From:   SF Markus Elfring <elfring@...rs.sourceforge.net>
To:     linux-iio@...r.kernel.org, Andreas Klinger <ak@...klinger.de>,
        Hartmut Knaack <knaack.h@....de>,
        Jonathan Cameron <jic23@...nel.org>,
        Lars-Peter Clausen <lars@...afoo.de>,
        Peter Meerwald-Stadler <pmeerw@...erw.net>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        kernel-janitors@...r.kernel.org
Subject: [PATCH] iio/proximity/srf08: Improve unlocking of a mutex in
 srf08_read_ranging()

From: Markus Elfring <elfring@...rs.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 drivers/iio/proximity/srf08.c | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/proximity/srf08.c b/drivers/iio/proximity/srf08.c
index f2bf783f829a..85957550195b 100644
--- a/drivers/iio/proximity/srf08.c
+++ b/drivers/iio/proximity/srf08.c
@@ -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;
 }
 
-- 
2.14.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ