linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] LEDS: leds-input, fix sleep inside atomic
@ 2010-06-05 21:12 Jiri Slaby
  2010-06-05 23:45 ` Samuel Thibault
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Slaby @ 2010-06-05 21:12 UTC (permalink / raw)
  To: rpurdie; +Cc: akpm, linux-input, linux-kernel, jirislaby

input_led_connect creates an atomic context by spin_lock_irqsave and
calls functions which then perform sleeping operations. For example
GFP_KERNEL allocations in led_classdev_register.

So LOCKDEP complains then like:
------------[ cut here ]------------
WARNING: at kernel/lockdep.c:2469 lockdep_trace_alloc+0xbc/0xd0()
Pid: 1, comm: swapper Not tainted 2.6.34-mm1_64+ #5
Call Trace:
...
 [<ffffffff8109359c>] lockdep_trace_alloc+0xbc/0xd0
 [<ffffffff810f65b2>] kmem_cache_alloc+0x32/0xf0
 [<ffffffff81324826>] device_create_vargs+0x56/0x110
 [<ffffffff8132490c>] device_create+0x2c/0x30
 [<ffffffff8142068c>] led_classdev_register+0x2c/0xe0
 [<ffffffff814213de>] input_led_connect+0x21e/0x2c0
...

Fix this by changing the spinlock to mutex as it is used only in
input_handler->connect and ->disconnect and it is safe to sleep
there.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Richard Purdie <rpurdie@rpsys.net>
---
 drivers/leds/leds-input.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/leds-input.c b/drivers/leds/leds-input.c
index 93ab5ae..794155a 100644
--- a/drivers/leds/leds-input.c
+++ b/drivers/leds/leds-input.c
@@ -92,7 +92,7 @@ static struct led_trigger input_led_triggers[LED_CNT] = {
 	DEFINE_INPUT_LED_TRIGGER(LED_CHARGING, "charging"),
 };
 /* Lock for registration coherency */
-static DEFINE_SPINLOCK(input_led_registered_lock);
+static DEFINE_MUTEX(input_led_registered_lock);
 /* Which global LED classes and triggers are registered */
 static unsigned long input_led_registered[BITS_TO_LONGS(LED_CNT)];
 
@@ -159,7 +159,6 @@ static int input_led_connect(struct input_handler *handler,
 {
 	struct input_handle *handle;
 	int i, error = 0;
-	unsigned long flags;
 	struct led_classdev *leds;
 
 	if (!test_bit(EV_LED, dev->keybit))
@@ -187,7 +186,7 @@ static int input_led_connect(struct input_handler *handler,
 		goto err;
 
 	/* lazily register missing global input LEDs */
-	spin_lock_irqsave(&input_led_registered_lock, flags);
+	mutex_lock(&input_led_registered_lock);
 	for (i = 0; i < LED_CNT; i++)
 		if (input_leds[i].name
 				&& !test_bit(i, input_led_registered)
@@ -199,7 +198,7 @@ static int input_led_connect(struct input_handler *handler,
 			else
 				led_trigger_unregister(&input_led_triggers[i]);
 		}
-	spin_unlock_irqrestore(&input_led_registered_lock, flags);
+	mutex_unlock(&input_led_registered_lock);
 
 	/* and register this device's LEDs */
 	for (i = 0; i < LED_CNT; i++)
@@ -239,7 +238,6 @@ err:
 static void input_led_disconnect(struct input_handle *handle)
 {
 	int unregister, i;
-	unsigned long flags;
 	struct led_classdev *leds = handle->private;
 
 	for (i = 0; i < LED_CNT; i++)
@@ -249,7 +247,7 @@ static void input_led_disconnect(struct input_handle *handle)
 	input_unregister_handle(handle);
 	input_led_delete_handle(handle);
 
-	spin_lock_irqsave(&input_led_registered_lock, flags);
+	mutex_lock(&input_led_registered_lock);
 	for (i = 0; i < LED_CNT; i++) {
 		if (!test_bit(i, input_led_registered))
 			continue;
@@ -268,7 +266,7 @@ static void input_led_disconnect(struct input_handle *handle)
 		led_trigger_unregister(&input_led_triggers[i]);
 		clear_bit(i, input_led_registered);
 	}
-	spin_unlock_irqrestore(&input_led_registered_lock, flags);
+	mutex_unlock(&input_led_registered_lock);
 }
 
 /* Only handle input devices which have LEDs */
-- 
1.7.1

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

* Re: [PATCH 1/1] LEDS: leds-input, fix sleep inside atomic
  2010-06-05 21:12 [PATCH 1/1] LEDS: leds-input, fix sleep inside atomic Jiri Slaby
@ 2010-06-05 23:45 ` Samuel Thibault
  2010-06-16 20:46   ` Andrew Morton
  0 siblings, 1 reply; 3+ messages in thread
From: Samuel Thibault @ 2010-06-05 23:45 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: rpurdie, akpm, linux-input, linux-kernel, jirislaby

Jiri Slaby, le Sat 05 Jun 2010 23:12:22 +0200, a écrit :
> Fix this by changing the spinlock to mutex as it is used only in
> input_handler->connect and ->disconnect and it is safe to sleep
> there.

Right. in a previous patch it was also used in interrupt context, but
now it should be safe indeed.

Andrew, please fold it into the leds-input patch.

> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Richard Purdie <rpurdie@rpsys.net>
Acked-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

BTW, please also Cc authors of files when reporting bugs... :)

Samuel
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* Re: [PATCH 1/1] LEDS: leds-input, fix sleep inside atomic
  2010-06-05 23:45 ` Samuel Thibault
@ 2010-06-16 20:46   ` Andrew Morton
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2010-06-16 20:46 UTC (permalink / raw)
  To: Samuel Thibault
  Cc: Jiri Slaby, rpurdie, linux-input, linux-kernel, jirislaby,
	Alessandro Zummo

On Sun, 6 Jun 2010 01:45:06 +0200
Samuel Thibault <samuel.thibault@ens-lyon.org> wrote:

> Jiri Slaby, le Sat 05 Jun 2010 23:12:22 +0200, a __crit :
> > Fix this by changing the spinlock to mutex as it is used only in
> > input_handler->connect and ->disconnect and it is safe to sleep
> > there.
> 
> Right. in a previous patch it was also used in interrupt context, but
> now it should be safe indeed.
> 
> Andrew, please fold it into the leds-input patch.

hm, I did, nine days ago;

btw, leds-route-kbd-leds-through-the-generic-leds-layer.patch is still
in the "stuck" state coz Alessandro said he'd test it ;)

I think I'll start pestering Richard with it anyway.


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

end of thread, other threads:[~2010-06-16 20:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-05 21:12 [PATCH 1/1] LEDS: leds-input, fix sleep inside atomic Jiri Slaby
2010-06-05 23:45 ` Samuel Thibault
2010-06-16 20:46   ` Andrew Morton

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