linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: leds-ns2: fix locking
@ 2010-09-19 13:30 Simon Guinot
  2010-09-19 13:41 ` Simon Guinot
  2010-09-20  1:34 ` Nicolas Pitre
  0 siblings, 2 replies; 4+ messages in thread
From: Simon Guinot @ 2010-09-19 13:30 UTC (permalink / raw)
  To: linux-arm-kernel

From: sguinot <sguinot@e0769a12-487d-4b36-8fb5-9ece92c58341>

This patch replace all the lock functions with the irq safe variant.
The ns2_led_{set,get}_mode() functions must be safe in all context.

For example, the trigger timer call led_set_brightness() in a softirq
context.

Signed-off-by: Simon Guinot <sguinot@lacie.com>
---
 drivers/leds/leds-ns2.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 74dce4b..350eb34 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -81,7 +81,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
 	int cmd_level;
 	int slow_level;
 
-	read_lock(&led_dat->rw_lock);
+	read_lock_irq(&led_dat->rw_lock);
 
 	cmd_level = gpio_get_value(led_dat->cmd);
 	slow_level = gpio_get_value(led_dat->slow);
@@ -95,7 +95,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
 		}
 	}
 
-	read_unlock(&led_dat->rw_lock);
+	read_unlock_irq(&led_dat->rw_lock);
 
 	return ret;
 }
@@ -104,8 +104,9 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
 			     enum ns2_led_modes mode)
 {
 	int i;
+	unsigned long flags;
 
-	write_lock(&led_dat->rw_lock);
+	write_lock_irqsave(&led_dat->rw_lock, flags);
 
 	for (i = 0; i < ARRAY_SIZE(ns2_led_modval); i++) {
 		if (mode == ns2_led_modval[i].mode) {
@@ -116,7 +117,7 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
 		}
 	}
 
-	write_unlock(&led_dat->rw_lock);
+	write_unlock_irqrestore(&led_dat->rw_lock, flags);
 }
 
 static void ns2_led_set(struct led_classdev *led_cdev,
-- 
1.6.3.1

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

* [PATCH] leds: leds-ns2: fix locking
  2010-09-19 13:30 [PATCH] leds: leds-ns2: fix locking Simon Guinot
@ 2010-09-19 13:41 ` Simon Guinot
  2010-09-19 13:51   ` Simon Guinot
  2010-09-20  1:34 ` Nicolas Pitre
  1 sibling, 1 reply; 4+ messages in thread
From: Simon Guinot @ 2010-09-19 13:41 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, Sep 19, 2010 at 03:30:59PM +0200, Simon Guinot wrote:
> From: sguinot <sguinot@e0769a12-487d-4b36-8fb5-9ece92c58341>

Sorry for the bad author field. I will resend this patch.

Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20100919/6d84c11a/attachment.sig>

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

* [PATCH] leds: leds-ns2: fix locking
  2010-09-19 13:41 ` Simon Guinot
@ 2010-09-19 13:51   ` Simon Guinot
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Guinot @ 2010-09-19 13:51 UTC (permalink / raw)
  To: linux-arm-kernel

From: Simon Guinot <sguinot@lacie.com>

This patch replace all the lock functions with the irq safe variant.
The ns2_led_{set,get}_mode() functions must be safe in all context.

For example, the trigger timer call led_set_brightness() in a softirq
context.

Signed-off-by: Simon Guinot <sguinot@lacie.com>
---
 drivers/leds/leds-ns2.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index 74dce4b..350eb34 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -81,7 +81,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
 	int cmd_level;
 	int slow_level;
 
-	read_lock(&led_dat->rw_lock);
+	read_lock_irq(&led_dat->rw_lock);
 
 	cmd_level = gpio_get_value(led_dat->cmd);
 	slow_level = gpio_get_value(led_dat->slow);
@@ -95,7 +95,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
 		}
 	}
 
-	read_unlock(&led_dat->rw_lock);
+	read_unlock_irq(&led_dat->rw_lock);
 
 	return ret;
 }
@@ -104,8 +104,9 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
 			     enum ns2_led_modes mode)
 {
 	int i;
+	unsigned long flags;
 
-	write_lock(&led_dat->rw_lock);
+	write_lock_irqsave(&led_dat->rw_lock, flags);
 
 	for (i = 0; i < ARRAY_SIZE(ns2_led_modval); i++) {
 		if (mode == ns2_led_modval[i].mode) {
@@ -116,7 +117,7 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
 		}
 	}
 
-	write_unlock(&led_dat->rw_lock);
+	write_unlock_irqrestore(&led_dat->rw_lock, flags);
 }
 
 static void ns2_led_set(struct led_classdev *led_cdev,
-- 
1.6.3.1

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

* [PATCH] leds: leds-ns2: fix locking
  2010-09-19 13:30 [PATCH] leds: leds-ns2: fix locking Simon Guinot
  2010-09-19 13:41 ` Simon Guinot
@ 2010-09-20  1:34 ` Nicolas Pitre
  1 sibling, 0 replies; 4+ messages in thread
From: Nicolas Pitre @ 2010-09-20  1:34 UTC (permalink / raw)
  To: linux-arm-kernel

On Sun, 19 Sep 2010, Simon Guinot wrote:

> From: sguinot <sguinot@e0769a12-487d-4b36-8fb5-9ece92c58341>

You should find out why your Git setup produces the above.  Your 
identity was most likely misconfigured when making this commit.

I've fixed it up locally.

> This patch replace all the lock functions with the irq safe variant.
> The ns2_led_{set,get}_mode() functions must be safe in all context.
> 
> For example, the trigger timer call led_set_brightness() in a softirq
> context.
> 
> Signed-off-by: Simon Guinot <sguinot@lacie.com>
> ---
>  drivers/leds/leds-ns2.c |    9 +++++----
>  1 files changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
> index 74dce4b..350eb34 100644
> --- a/drivers/leds/leds-ns2.c
> +++ b/drivers/leds/leds-ns2.c
> @@ -81,7 +81,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
>  	int cmd_level;
>  	int slow_level;
>  
> -	read_lock(&led_dat->rw_lock);
> +	read_lock_irq(&led_dat->rw_lock);
>  
>  	cmd_level = gpio_get_value(led_dat->cmd);
>  	slow_level = gpio_get_value(led_dat->slow);
> @@ -95,7 +95,7 @@ static int ns2_led_get_mode(struct ns2_led_data *led_dat,
>  		}
>  	}
>  
> -	read_unlock(&led_dat->rw_lock);
> +	read_unlock_irq(&led_dat->rw_lock);
>  
>  	return ret;
>  }
> @@ -104,8 +104,9 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
>  			     enum ns2_led_modes mode)
>  {
>  	int i;
> +	unsigned long flags;
>  
> -	write_lock(&led_dat->rw_lock);
> +	write_lock_irqsave(&led_dat->rw_lock, flags);
>  
>  	for (i = 0; i < ARRAY_SIZE(ns2_led_modval); i++) {
>  		if (mode == ns2_led_modval[i].mode) {
> @@ -116,7 +117,7 @@ static void ns2_led_set_mode(struct ns2_led_data *led_dat,
>  		}
>  	}
>  
> -	write_unlock(&led_dat->rw_lock);
> +	write_unlock_irqrestore(&led_dat->rw_lock, flags);
>  }
>  
>  static void ns2_led_set(struct led_classdev *led_cdev,
> -- 
> 1.6.3.1
> 

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

end of thread, other threads:[~2010-09-20  1:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-19 13:30 [PATCH] leds: leds-ns2: fix locking Simon Guinot
2010-09-19 13:41 ` Simon Guinot
2010-09-19 13:51   ` Simon Guinot
2010-09-20  1:34 ` Nicolas Pitre

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