提交 0db37915 编写于 作者: P Pavel Machek 提交者: Jacek Anaszewski

leds: avoid races with workqueue

There are races between "main" thread and workqueue. They manifest
themselves on Thinkpad X60:

This should result in LED blinking, but it turns it off instead:

    root@amd:/data/pavel# cd /sys/class/leds/tpacpi\:\:power
    root@amd:/sys/class/leds/tpacpi::power# echo timer > trigger
    root@amd:/sys/class/leds/tpacpi::power# echo timer > trigger

It should be possible to transition from blinking to solid on by echo
0 > brightness; echo 1 > brightness... but that does not work, either,
if done too quickly.

Synchronization of the workqueue fixes both.

Fixes: 1afcadfc ("leds: core: Use set_brightness_work for the blocking op")
Signed-off-by: NPavel Machek <pavel@ucw.cz>
Signed-off-by: NJacek Anaszewski <jacek.anaszewski@gmail.com>
上级 05b8ccfb
...@@ -57,6 +57,7 @@ static ssize_t brightness_store(struct device *dev, ...@@ -57,6 +57,7 @@ static ssize_t brightness_store(struct device *dev,
if (state == LED_OFF) if (state == LED_OFF)
led_trigger_remove(led_cdev); led_trigger_remove(led_cdev);
led_set_brightness(led_cdev, state); led_set_brightness(led_cdev, state);
flush_work(&led_cdev->set_brightness_work);
ret = size; ret = size;
unlock: unlock:
......
...@@ -164,6 +164,11 @@ static void led_blink_setup(struct led_classdev *led_cdev, ...@@ -164,6 +164,11 @@ static void led_blink_setup(struct led_classdev *led_cdev,
unsigned long *delay_on, unsigned long *delay_on,
unsigned long *delay_off) unsigned long *delay_off)
{ {
/*
* If "set brightness to 0" is pending in workqueue, we don't
* want that to be reordered after blink_set()
*/
flush_work(&led_cdev->set_brightness_work);
if (!test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) && if (!test_bit(LED_BLINK_ONESHOT, &led_cdev->work_flags) &&
led_cdev->blink_set && led_cdev->blink_set &&
!led_cdev->blink_set(led_cdev, delay_on, delay_off)) !led_cdev->blink_set(led_cdev, delay_on, delay_off))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册