LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH] unlock 12c_mutex before return
@ 2007-10-23  0:00 Roel Kluin
  2007-10-23  0:06 ` Roel Kluin
  2007-10-23  9:50 ` Andreas Schwab
  0 siblings, 2 replies; 4+ messages in thread
From: Roel Kluin @ 2007-10-23  0:00 UTC (permalink / raw)
  To: lkml

    unlock 12c_mutex before return -EINVAL
    
    Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/drivers/media/dvb/dvb-usb/au6610.c b/drivers/media/dvb/dvb-usb/au6610.c
index 18e0b16..31f47c7 100644
--- a/drivers/media/dvb/dvb-usb/au6610.c
+++ b/drivers/media/dvb/dvb-usb/au6610.c
@@ -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 */

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] unlock 12c_mutex before return
  2007-10-23  0:00 [PATCH] unlock 12c_mutex before return Roel Kluin
@ 2007-10-23  0:06 ` Roel Kluin
  2007-10-23  9:50 ` Andreas Schwab
  1 sibling, 0 replies; 4+ messages in thread
From: Roel Kluin @ 2007-10-23  0:06 UTC (permalink / raw)
  To: lkml

And a similar one in drivers/media/dvb/dvb-usb/gl861.c
--
    unlock 12c_mutex before return -EINVAL
    
    Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/drivers/media/dvb/dvb-usb/gl861.c b/drivers/media/dvb/dvb-usb/gl861.c
index f01d99c..20c340a 100644
--- a/drivers/media/dvb/dvb-usb/gl861.c
+++ b/drivers/media/dvb/dvb-usb/gl861.c
@@ -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 */


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] unlock 12c_mutex before return
  2007-10-23  0:00 [PATCH] unlock 12c_mutex before return Roel Kluin
  2007-10-23  0:06 ` Roel Kluin
@ 2007-10-23  9:50 ` Andreas Schwab
  2007-10-23 12:32   ` Roel Kluin
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2007-10-23  9:50 UTC (permalink / raw)
  To: Roel Kluin; +Cc: lkml

Roel Kluin <12o3l@tiscali.nl> writes:

>     unlock 12c_mutex before return -EINVAL
>     
>     Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
> ---
> diff --git a/drivers/media/dvb/dvb-usb/au6610.c b/drivers/media/dvb/dvb-usb/au6610.c
> index 18e0b16..31f47c7 100644
> --- a/drivers/media/dvb/dvb-usb/au6610.c
> +++ b/drivers/media/dvb/dvb-usb/au6610.c
> @@ -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.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
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."

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] unlock 12c_mutex before return
  2007-10-23  9:50 ` Andreas Schwab
@ 2007-10-23 12:32   ` Roel Kluin
  0 siblings, 0 replies; 4+ messages in thread
From: Roel Kluin @ 2007-10-23 12:32 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: lkml

Andreas Schwab wrote:

>> -	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

Signed-off-by: Roel Kluin <12o3l@tiscali.nl>
---
diff --git a/drivers/media/dvb/dvb-usb/au6610.c b/drivers/media/dvb/dvb-usb/au6610.c
index 18e0b16..f3ff813 100644
--- a/drivers/media/dvb/dvb-usb/au6610.c
+++ b/drivers/media/dvb/dvb-usb/au6610.c
@@ -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)) {
diff --git a/drivers/media/dvb/dvb-usb/gl861.c b/drivers/media/dvb/dvb-usb/gl861.c
index f01d99c..6b99d9f 100644
--- a/drivers/media/dvb/dvb-usb/gl861.c
+++ b/drivers/media/dvb/dvb-usb/gl861.c
@@ -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)) {


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-10-23 12:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-23  0:00 [PATCH] unlock 12c_mutex before return Roel Kluin
2007-10-23  0:06 ` Roel Kluin
2007-10-23  9:50 ` Andreas Schwab
2007-10-23 12:32   ` Roel Kluin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).