Skip to content

Commit

Permalink
leds: leds-pwm: fix duty time overflow.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Xiubo Li authored and Bryan Wu committed Jan 28, 2014
1 parent 3df22c0 commit fc1aee0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions drivers/leds/leds-pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit fc1aee0

Please sign in to comment.