diff options
author | Xiubo Li <Li.Xiubo@freescale.com> | 2013-12-11 04:19:42 -0500 |
---|---|---|
committer | Bryan Wu <cooloney@gmail.com> | 2014-01-27 20:28:50 -0500 |
commit | fc1aee038b609dc33067ca9dd477b16ea893cae0 (patch) | |
tree | c098d278595f5efbdf7621969cf59d28aac6badf | |
parent | 3df22c06b9ca7df02e095595994d229811305825 (diff) |
leds: leds-pwm: fix duty time overflow.
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>
-rw-r--r-- | drivers/leds/leds-pwm.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index b31d8e99c419..3fbd28e99b2c 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c | |||
@@ -66,9 +66,11 @@ static void led_pwm_set(struct led_classdev *led_cdev, | |||
66 | struct led_pwm_data *led_dat = | 66 | struct led_pwm_data *led_dat = |
67 | container_of(led_cdev, struct led_pwm_data, cdev); | 67 | container_of(led_cdev, struct led_pwm_data, cdev); |
68 | unsigned int max = led_dat->cdev.max_brightness; | 68 | unsigned int max = led_dat->cdev.max_brightness; |
69 | unsigned int period = led_dat->period; | 69 | unsigned long long duty = led_dat->period; |
70 | 70 | ||
71 | led_dat->duty = brightness * period / max; | 71 | duty *= brightness; |
72 | do_div(duty, max); | ||
73 | led_dat->duty = duty; | ||
72 | 74 | ||
73 | if (led_dat->can_sleep) | 75 | if (led_dat->can_sleep) |
74 | schedule_work(&led_dat->work); | 76 | schedule_work(&led_dat->work); |