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: <20210916164746.rujqwpnrm4i6lf7z@pengutronix.de>
Date:   Thu, 16 Sep 2021 18:47:46 +0200
From:   Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To:     Wolfram Sang <wsa+renesas@...g-engineering.com>
Cc:     linux-pwm@...r.kernel.org, linux-renesas-soc@...r.kernel.org,
        Duc Nguyen <duc.nguyen.ub@...esas.com>,
        Thierry Reding <thierry.reding@...il.com>,
        Lee Jones <lee.jones@...aro.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/2] pwm: renesas-tpu: don't allow no duty if duty_ns is
 given

On Wed, Sep 15, 2021 at 08:55:41AM +0200, Wolfram Sang wrote:
> From: Duc Nguyen <duc.nguyen.ub@...esas.com>
> 
> We have special code if duty_ns is 0. But if non-zero is given, then the
> calculation should not result in zero duty.

Why not? Assuming a PWM that supports multiples of say 100 ns for
duty_cycle, rounding a request for 550 ns down to 500 ns isn't worse
than rounding down a request for 50 ns to 0 ns is it?
 
> Signed-off-by: Duc Nguyen <duc.nguyen.ub@...esas.com>
> [wsa: split and reworded commit message]
> Signed-off-by: Wolfram Sang <wsa+renesas@...g-engineering.com>
> ---
>  drivers/pwm/pwm-renesas-tpu.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pwm/pwm-renesas-tpu.c b/drivers/pwm/pwm-renesas-tpu.c
> index 754440194650..bb51156e4bda 100644
> --- a/drivers/pwm/pwm-renesas-tpu.c
> +++ b/drivers/pwm/pwm-renesas-tpu.c
> @@ -275,7 +275,7 @@ static int tpu_pwm_config(struct pwm_chip *chip, struct pwm_device *_pwm,
>  	if (duty_ns) {
>  		duty = clk_rate / prescalers[prescaler]
>  		     / (NSEC_PER_SEC / duty_ns);

Unrelated to the change under discussion here: Dividing by the result of
a division is bad. 

Consider:
	clk_rate = 1333333333
	prescalers[prescaler] = 43
	duty_ns = 500000001

The exact result is 15503875.996124031, with the above formula you get
31007751 which is off by nearly a factor of two.

These numbers are probably not relevant, but they show the problem.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ