linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rfkill: fix double-mutex-locking
@ 2007-11-28 16:49 Michael Buesch
  2007-11-28 20:13 ` Ivo van Doorn
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Buesch @ 2007-11-28 16:49 UTC (permalink / raw)
  To: Ivo van Doorn, John Linville; +Cc: linux-wireless

rfkill_toggle_radio is called from functions where
rfkill->mutex is already aquired.

Remove the lock from rfkill_toggle_radio() and add it to
the only calling function that calls it without the lock held.

Signed-off-by: Michael Buesch <mb@bu3sch.de>

Index: wireless-2.6/net/rfkill/rfkill.c
===================================================================
--- wireless-2.6.orig/net/rfkill/rfkill.c	2007-11-20 19:09:35.000000000 +0100
+++ wireless-2.6/net/rfkill/rfkill.c	2007-11-28 17:09:55.000000000 +0100
@@ -60,11 +60,7 @@ static void rfkill_led_trigger(struct rf
 static int rfkill_toggle_radio(struct rfkill *rfkill,
 				enum rfkill_state state)
 {
-	int retval;
-
-	retval = mutex_lock_interruptible(&rfkill->mutex);
-	if (retval)
-		return retval;
+	int retval = 0;
 
 	if (state != rfkill->state) {
 		retval = rfkill->toggle_radio(rfkill->data, state);
@@ -74,7 +70,6 @@ static int rfkill_toggle_radio(struct rf
 		}
 	}
 
-	mutex_unlock(&rfkill->mutex);
 	return retval;
 }
 
@@ -158,12 +153,13 @@ static ssize_t rfkill_state_store(struct
 	if (!capable(CAP_NET_ADMIN))
 		return -EPERM;
 
+	if (mutex_lock_interruptible(&rfkill->mutex))
+		return -ERESTARTSYS;
 	error = rfkill_toggle_radio(rfkill,
 			state ? RFKILL_STATE_ON : RFKILL_STATE_OFF);
-	if (error)
-		return error;
+	mutex_unlock(&rfkill->mutex);
 
-	return count;
+	return error ? error : count;
 }
 
 static ssize_t rfkill_claim_show(struct device *dev,

-- 
Greetings Michael.

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

* Re: [PATCH] rfkill: fix double-mutex-locking
  2007-11-28 16:49 [PATCH] rfkill: fix double-mutex-locking Michael Buesch
@ 2007-11-28 20:13 ` Ivo van Doorn
  0 siblings, 0 replies; 2+ messages in thread
From: Ivo van Doorn @ 2007-11-28 20:13 UTC (permalink / raw)
  To: Michael Buesch; +Cc: John Linville, linux-wireless

On Wednesday 28 November 2007, Michael Buesch wrote:
> rfkill_toggle_radio is called from functions where
> rfkill->mutex is already aquired.
> 
> Remove the lock from rfkill_toggle_radio() and add it to
> the only calling function that calls it without the lock held.
> 
> Signed-off-by: Michael Buesch <mb@bu3sch.de>
Acked-by: Ivo van Doorn <IvDoorn@gmail.com>

> Index: wireless-2.6/net/rfkill/rfkill.c
> ===================================================================
> --- wireless-2.6.orig/net/rfkill/rfkill.c	2007-11-20 19:09:35.000000000 +0100
> +++ wireless-2.6/net/rfkill/rfkill.c	2007-11-28 17:09:55.000000000 +0100
> @@ -60,11 +60,7 @@ static void rfkill_led_trigger(struct rf
>  static int rfkill_toggle_radio(struct rfkill *rfkill,
>  				enum rfkill_state state)
>  {
> -	int retval;
> -
> -	retval = mutex_lock_interruptible(&rfkill->mutex);
> -	if (retval)
> -		return retval;
> +	int retval = 0;
>  
>  	if (state != rfkill->state) {
>  		retval = rfkill->toggle_radio(rfkill->data, state);
> @@ -74,7 +70,6 @@ static int rfkill_toggle_radio(struct rf
>  		}
>  	}
>  
> -	mutex_unlock(&rfkill->mutex);
>  	return retval;
>  }
>  
> @@ -158,12 +153,13 @@ static ssize_t rfkill_state_store(struct
>  	if (!capable(CAP_NET_ADMIN))
>  		return -EPERM;
>  
> +	if (mutex_lock_interruptible(&rfkill->mutex))
> +		return -ERESTARTSYS;
>  	error = rfkill_toggle_radio(rfkill,
>  			state ? RFKILL_STATE_ON : RFKILL_STATE_OFF);
> -	if (error)
> -		return error;
> +	mutex_unlock(&rfkill->mutex);
>  
> -	return count;
> +	return error ? error : count;
>  }
>  
>  static ssize_t rfkill_claim_show(struct device *dev,
> 



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

end of thread, other threads:[~2007-11-28 18:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-28 16:49 [PATCH] rfkill: fix double-mutex-locking Michael Buesch
2007-11-28 20:13 ` Ivo van Doorn

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