Skip to contentSkip to conversation

unlock 12c_mutex before return

PATCH In review Roel Kluin 2 participants 4 messages Oct 23, 2007 Media (V4L/DVB)

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 unlock 12c_mutex before return

unlock 12c_mutex before return -EINVAL

---

drivers/media/dvb/dvb-usb/au6610.c +3 -1
index 18e0b16..31f47c7 100644
@@ -82,8 +82,10 @@ static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
 		return -EAGAIN;
 
-	if (num > 2)
+	if (num > 2) {
+                mutex_unlock(&d->i2c_mutex);
 		return -EINVAL;
+	}
 
 	for (i = 0; i < num; i++) {
 		/* write/read request */
author
#1 lore raw

And a similar one in drivers/media/dvb/dvb-usb/gl861.c --
unlock 12c_mutex before return -EINVAL

---

drivers/media/dvb/dvb-usb/gl861.c +3 -1
index f01d99c..20c340a 100644
@@ -59,8 +59,10 @@ static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
 		return -EAGAIN;
 
-	if (num > 2)
+	if (num > 2) {
+		mutex_unlock(&d->i2c_mutex);
 		return -EINVAL;
+	}
 
 	for (i = 0; i < num; i++) {
 		/* write/read request */
#2 lore raw
In reply to Roel Kluin
Quoted 9 lines · Roel Kluin

unlock 12c_mutex before return -EINVAL

---

drivers/media/dvb/dvb-usb/au6610.c +0 -0
index 18e0b16..31f47c7 100644

drivers/media/dvb/dvb-usb/au6610.c static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], · line 87

Quoted 7 lines
drivers/media/dvb/dvb-usb/au6610.c +2 -1
@@ -82,8 +82,10 @@ static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
 		return -EAGAIN;
 
-	if (num > 2)
+	if (num > 2) {
+                mutex_unlock(&d->i2c_mutex);
 		return -EINVAL;

How about moving the check before the lock?

Andreas.

Signature · 4 lines
Andreas Schwab, SuSE Labs, [email protected]
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
author
#3 lore raw
Quoted 6 lines · Andreas Schwab

Review

Quoted 4 lines
(quoted diff) +2 -1
-	if (num > 2)
+	if (num > 2) {
+                mutex_unlock(&d->i2c_mutex);
 		return -EINVAL;

How about moving the check before the lock?

Good suggestion. Patch below covers both previous patches. --
Move check before lock

---

drivers/media/dvb/dvb-usb/au6610.c +3 -3
index 18e0b16..f3ff813 100644
@@ -79,12 +79,12 @@ static int au6610_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
 	int i;
 
-	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
-		return -EAGAIN;
-
 	if (num > 2)
 		return -EINVAL;
 
+	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+		return -EAGAIN;
+
 	for (i = 0; i < num; i++) {
 		/* write/read request */
 		if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
drivers/media/dvb/dvb-usb/gl861.c +3 -3
index f01d99c..6b99d9f 100644
@@ -56,12 +56,12 @@ static int gl861_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
 	struct dvb_usb_device *d = i2c_get_adapdata(adap);
 	int i;
 
-	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
-		return -EAGAIN;
-
 	if (num > 2)
 		return -EINVAL;
 
+	if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+		return -EAGAIN;
+
 	for (i = 0; i < num; i++) {
 		/* write/read request */
 		if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {