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] [thread-next>] [day] [month] [year] [list]
Message-ID: <9f24396a-7a1e-012e-35e2-1e055941e87e@linaro.org>
Date:   Thu, 25 May 2023 15:55:05 +0200
From:   Neil Armstrong <neil.armstrong@...aro.org>
To:     Bjorn Andersson <quic_bjorande@...cinc.com>,
        Pavel Machek <pavel@....cz>, Lee Jones <lee@...nel.org>,
        Anjelique Melendez <quic_amelende@...cinc.com>
Cc:     Uwe Kleine-König <u.kleine-koenig@...gutronix.de>,
        linux-leds@...r.kernel.org, linux-kernel@...r.kernel.org,
        linux-arm-msm@...r.kernel.org,
        Caleb Connolly <caleb.connolly@...aro.org>,
        Steev Klimaszewski <steev@...i.org>
Subject: Re: [PATCH v2] leds: qcom-lpg: Fix PWM period limits

On 15/05/2023 18:26, Bjorn Andersson wrote:
> The introduction of high resolution PWM support changed the order of the
> operations in the calculation of min and max period. The result in both
> divisions is in most cases a truncation to 0, which limits the period to
> the range of [0, 0].
> 
> Both numerators (and denominators) are within 64 bits, so the whole
> expression can be put directly into the div64_u64, instead of doing it
> partially.
> 
> Fixes: b00d2ed37617 ("leds: rgb: leds-qcom-lpg: Add support for high resolution PWM")
> Reviewed-by: Caleb Connolly <caleb.connolly@...aro.org>
> Tested-by: Steev Klimaszewski <steev@...i.org>
> Signed-off-by: Bjorn Andersson <quic_bjorande@...cinc.com>
> ---
> 
> Changes since v1:
> - Reworded first sentence to express that it's the order and not the
>    previously non-existent parenthesis that changed...
> - Picked up review tags.
> 
>   drivers/leds/rgb/leds-qcom-lpg.c | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/leds/rgb/leds-qcom-lpg.c b/drivers/leds/rgb/leds-qcom-lpg.c
> index c9cea797a697..7287fadc00df 100644
> --- a/drivers/leds/rgb/leds-qcom-lpg.c
> +++ b/drivers/leds/rgb/leds-qcom-lpg.c
> @@ -312,14 +312,14 @@ static int lpg_calc_freq(struct lpg_channel *chan, uint64_t period)
>   		max_res = LPG_RESOLUTION_9BIT;
>   	}
>   
> -	min_period = (u64)NSEC_PER_SEC *
> -			div64_u64((1 << pwm_resolution_arr[0]), clk_rate_arr[clk_len - 1]);
> +	min_period = div64_u64((u64)NSEC_PER_SEC * (1 << pwm_resolution_arr[0]),
> +			       clk_rate_arr[clk_len - 1]);
>   	if (period <= min_period)
>   		return -EINVAL;
>   
>   	/* Limit period to largest possible value, to avoid overflows */
> -	max_period = (u64)NSEC_PER_SEC * max_res * LPG_MAX_PREDIV *
> -			div64_u64((1 << LPG_MAX_M), 1024);
> +	max_period = div64_u64((u64)NSEC_PER_SEC * max_res * LPG_MAX_PREDIV * (1 << LPG_MAX_M),
> +			       1024);
>   	if (period > max_period)
>   		period = max_period;
>   

Tested-by: Neil Armstrong <neil.armstrong@...aro.org> # on SM8550-QRD

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ