lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:	Wed, 11 Dec 2013 11:07:53 -0800
From:	Bryan Wu <cooloney@...il.com>
To:	Xiubo Li <Li.Xiubo@...escale.com>
Cc:	"rpurdie@...ys.net" <rpurdie@...ys.net>,
	Linux LED Subsystem <linux-leds@...r.kernel.org>,
	lkml <linux-kernel@...r.kernel.org>, b47053@...escale.com
Subject: Re: [PATCH] leds: leds-pwm: fix duty time overflow.

On Wed, Dec 11, 2013 at 1:19 AM, Xiubo Li <Li.Xiubo@...escale.com> wrote:
> 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.

This looks good to me. Good catch. I will merge this.

Thanks,
-Bryan


> ---
>  drivers/leds/leds-pwm.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c
> index bb6f948..7cb2cd8 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,
>         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);
> --
> 1.8.4
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ