]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
leds: leds-pwm: fix duty time overflow.
authorXiubo Li <Li.Xiubo@freescale.com>
Wed, 11 Dec 2013 09:19:42 +0000 (01:19 -0800)
committerBryan Wu <cooloney@gmail.com>
Tue, 28 Jan 2014 01:28:50 +0000 (17:28 -0800)
Overflow maybe occurs when calculates the duty time. For instance,
the period time is 990000000ns, and the max_brightness is 127, when
setting the brightness to 12, the duty value will be 25906026ns, but
it should be 93543307ns.

Signed-off-by: Bryan Wu <cooloney@gmail.com>
drivers/leds/leds-pwm.c

index b31d8e99c41992c77610fe5ca1694211035ea592..3fbd28e99b2c1927d89d4158bb6a262d1746f79b 100644 (file)
@@ -66,9 +66,11 @@ static void led_pwm_set(struct led_classdev *led_cdev,
        struct led_pwm_data *led_dat =
                container_of(led_cdev, struct led_pwm_data, cdev);
        unsigned int max = led_dat->cdev.max_brightness;
-       unsigned int period =  led_dat->period;
+       unsigned long long duty =  led_dat->period;
 
-       led_dat->duty = brightness * period / max;
+       duty *= brightness;
+       do_div(duty, max);
+       led_dat->duty = duty;
 
        if (led_dat->can_sleep)
                schedule_work(&led_dat->work);