Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb1610b4 authored by Hans de Goede's avatar Hans de Goede Committed by Jacek Anaszewski
Browse files

led: core: Fix blink_brightness setting race



All 3 of led_timer_func, led_set_brightness and led_set_software_blink
set blink_brightness. If led_timer_func or led_set_software_blink race
with led_set_brightness they may end up overwriting the new
blink_brightness. The new atomic work_flags does not protect against
this as it just protects the flags and not blink_brightness.

This commit introduces a new new_blink_brightness value which gets
set by led_set_brightness and read by led_timer_func on LED on, fixing
this.

Dealing with the new brightness at LED on time, makes the new
brightness apply sooner, which also fixes a led_set_brightness which
happens while a oneshot blink which ends in LED on is running not
getting applied.

Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Signed-off-by: default avatarJacek Anaszewski <j.anaszewski@samsung.com>
parent a9c6ce57
Loading
Loading
Loading
Loading
+7 −7
Original line number Original line Diff line number Diff line
@@ -66,16 +66,16 @@ static void led_timer_function(unsigned long data)
	brightness = led_get_brightness(led_cdev);
	brightness = led_get_brightness(led_cdev);
	if (!brightness) {
	if (!brightness) {
		/* Time to switch the LED on. */
		/* Time to switch the LED on. */
		if (test_and_clear_bit(LED_BLINK_BRIGHTNESS_CHANGE,
					&led_cdev->work_flags))
			brightness = led_cdev->new_blink_brightness;
		else
			brightness = led_cdev->blink_brightness;
			brightness = led_cdev->blink_brightness;
		delay = led_cdev->blink_delay_on;
		delay = led_cdev->blink_delay_on;
	} else {
	} else {
		/* Store the current brightness value to be able
		/* Store the current brightness value to be able
		 * to restore it when the delay_off period is over.
		 * to restore it when the delay_off period is over.
		 * Do it only if there is no pending blink brightness
		 * change, to avoid overwriting the new value.
		 */
		 */
		if (!test_and_clear_bit(LED_BLINK_BRIGHTNESS_CHANGE,
					&led_cdev->work_flags))
		led_cdev->blink_brightness = brightness;
		led_cdev->blink_brightness = brightness;
		brightness = LED_OFF;
		brightness = LED_OFF;
		delay = led_cdev->blink_delay_off;
		delay = led_cdev->blink_delay_off;
@@ -245,7 +245,7 @@ void led_set_brightness(struct led_classdev *led_cdev,
		} else {
		} else {
			set_bit(LED_BLINK_BRIGHTNESS_CHANGE,
			set_bit(LED_BLINK_BRIGHTNESS_CHANGE,
				&led_cdev->work_flags);
				&led_cdev->work_flags);
			led_cdev->blink_brightness = brightness;
			led_cdev->new_blink_brightness = brightness;
		}
		}
		return;
		return;
	}
	}
+1 −0
Original line number Original line Diff line number Diff line
@@ -93,6 +93,7 @@ struct led_classdev {
	unsigned long		 blink_delay_on, blink_delay_off;
	unsigned long		 blink_delay_on, blink_delay_off;
	struct timer_list	 blink_timer;
	struct timer_list	 blink_timer;
	int			 blink_brightness;
	int			 blink_brightness;
	int			 new_blink_brightness;
	void			(*flash_resume)(struct led_classdev *led_cdev);
	void			(*flash_resume)(struct led_classdev *led_cdev);


	struct work_struct	set_brightness_work;
	struct work_struct	set_brightness_work;