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]
Message-ID: <b0acc12a-e48c-d51a-f7e3-606e66e6fe7b@users.sourceforge.net>
Date:   Thu, 2 Nov 2017 20:40:12 +0100
From:   SF Markus Elfring <elfring@...rs.sourceforge.net>
To:     devel@...verdev.osuosl.org,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        H Hartley Sweeten <hsweeten@...ionengravers.com>,
        Ian Abbott <abbotti@....co.uk>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        kernel-janitors@...r.kernel.org
Subject: [PATCH] staging: comedi: usbduxfast: Improve unlocking of a mutex in
 usbduxfast_ai_insn_read()

From: Markus Elfring <elfring@...rs.sourceforge.net>
Date: Thu, 2 Nov 2017 20:30:31 +0100

* Add a jump target so that a call of the function "mutex_unlock" is stored
  only twice in this function implementation.

* Replace five calls by goto statements.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <elfring@...rs.sourceforge.net>
---
 drivers/staging/comedi/drivers/usbduxfast.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/drivers/staging/comedi/drivers/usbduxfast.c b/drivers/staging/comedi/drivers/usbduxfast.c
index 608403c7586b..e5884faf7275 100644
--- a/drivers/staging/comedi/drivers/usbduxfast.c
+++ b/drivers/staging/comedi/drivers/usbduxfast.c
@@ -777,8 +777,8 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
 	if (devpriv->ai_cmd_running) {
 		dev_err(dev->class_dev,
 			"ai_insn_read not possible, async cmd is running\n");
-		mutex_unlock(&devpriv->mut);
-		return -EBUSY;
+		ret = -EBUSY;
+		goto unlock;
 	}
 
 	/* set command for the first channel */
@@ -798,10 +798,8 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
 	usbduxfast_cmd_data(dev, 6, 0x01, 0x00, rngmask, 0x00);
 
 	ret = usbduxfast_send_cmd(dev, SENDADCOMMANDS);
-	if (ret < 0) {
-		mutex_unlock(&devpriv->mut);
-		return ret;
-	}
+	if (ret < 0)
+		goto unlock;
 
 	for (i = 0; i < PACKETS_TO_IGNORE; i++) {
 		ret = usb_bulk_msg(usb, usb_rcvbulkpipe(usb, BULKINEP),
@@ -809,8 +807,7 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
 				   &actual_length, 10000);
 		if (ret < 0) {
 			dev_err(dev->class_dev, "insn timeout, no data\n");
-			mutex_unlock(&devpriv->mut);
-			return ret;
+			goto unlock;
 		}
 	}
 
@@ -820,14 +817,13 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
 				   &actual_length, 10000);
 		if (ret < 0) {
 			dev_err(dev->class_dev, "insn data error: %d\n", ret);
-			mutex_unlock(&devpriv->mut);
-			return ret;
+			goto unlock;
 		}
 		n = actual_length / sizeof(u16);
 		if ((n % 16) != 0) {
 			dev_err(dev->class_dev, "insn data packet corrupted\n");
-			mutex_unlock(&devpriv->mut);
-			return -EINVAL;
+			ret = -EINVAL;
+			goto unlock;
 		}
 		for (j = chan; (j < n) && (i < insn->n); j = j + 16) {
 			data[i] = ((u16 *)(devpriv->inbuf))[j];
@@ -838,6 +834,10 @@ static int usbduxfast_ai_insn_read(struct comedi_device *dev,
 	mutex_unlock(&devpriv->mut);
 
 	return insn->n;
+
+unlock:
+	mutex_unlock(&devpriv->mut);
+	return ret;
 }
 
 static int usbduxfast_upload_firmware(struct comedi_device *dev,
-- 
2.15.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ