lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1408453101-30290-2-git-send-email-vdonnefort@gmail.com>
Date:	Tue, 19 Aug 2014 14:58:21 +0200
From:	Vincent Donnefort <vdonnefort@...il.com>
To:	hughd@...gle.com, cooloney@...il.com
Cc:	linux-leds@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-wireless@...r.kernel.org,
	Vincent Donnefort <vdonnefort@...il.com>
Subject: [PATCH] leds: make led_blink_set IRQ safe

This patch introduces a work which take care of reseting the blink workqueue and
avoid calling the cancel_delayed_work_sync function which may sleep, from an IRQ
context.

Signed-off-by: Vincent Donnefort <vdonnefort@...il.com>

diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 129729d..0971554 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -148,6 +148,24 @@ static void led_work_function(struct work_struct *ws)
 			   msecs_to_jiffies(delay));
 }
 
+static void reset_blink_work_delayed(struct work_struct *ws)
+{
+	struct led_classdev *led_cdev =
+		container_of(ws, struct led_classdev, reset_blink_work);
+
+	cancel_delayed_work_sync(&led_cdev->blink_work);
+
+	if (!led_cdev->blink_delay_on) {
+		__led_set_brightness(led_cdev, LED_OFF);
+		return;
+	} else if (!led_cdev->blink_delay_off) {
+		__led_set_brightness(led_cdev, led_cdev->blink_brightness);
+		return;
+	}
+
+	queue_delayed_work(system_wq, &led_cdev->blink_work, 1);
+}
+
 static void set_brightness_delayed(struct work_struct *ws)
 {
 	struct led_classdev *led_cdev =
@@ -234,6 +252,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
 	INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed);
 
 	INIT_DELAYED_WORK(&led_cdev->blink_work, led_work_function);
+	INIT_WORK(&led_cdev->reset_blink_work, reset_blink_work_delayed);
 
 #ifdef CONFIG_LEDS_TRIGGERS
 	led_trigger_set_default(led_cdev);
diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index 4bb1168..959510a 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -40,19 +40,7 @@ static void led_set_software_blink(struct led_classdev *led_cdev,
 	led_cdev->blink_delay_on = delay_on;
 	led_cdev->blink_delay_off = delay_off;
 
-	/* never on - just set to off */
-	if (!delay_on) {
-		__led_set_brightness(led_cdev, LED_OFF);
-		return;
-	}
-
-	/* never off - just set to brightness */
-	if (!delay_off) {
-		__led_set_brightness(led_cdev, led_cdev->blink_brightness);
-		return;
-	}
-
-	queue_delayed_work(system_wq, &led_cdev->blink_work, 1);
+	schedule_work(&led_cdev->reset_blink_work);
 }
 
 
@@ -76,8 +64,6 @@ void led_blink_set(struct led_classdev *led_cdev,
 		   unsigned long *delay_on,
 		   unsigned long *delay_off)
 {
-	cancel_delayed_work_sync(&led_cdev->blink_work);
-
 	led_cdev->flags &= ~LED_BLINK_ONESHOT;
 	led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP;
 
diff --git a/include/linux/leds.h b/include/linux/leds.h
index 6a599dc..6e5523d 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -69,6 +69,7 @@ struct led_classdev {
 
 	unsigned long		 blink_delay_on, blink_delay_off;
 	struct delayed_work	 blink_work;
+	struct work_struct	 reset_blink_work;
 	int			 blink_brightness;
 
 	struct work_struct	set_brightness_work;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ