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]
Date:	Thu, 19 Mar 2015 23:34:58 -0700
From:	Stephen Boyd <sboyd@...eaurora.org>
To:	Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
Cc:	linux-kernel@...r.kernel.org,
	Heikki Krogerus <heikki.krogerus@...ux.intel.com>
Subject: Re: [PATCH v1 1/1] clk: fractional-divider: eliminate while-loop

On 03/19, Andy Shevchenko wrote:
> We may do a calculation of the rounded rate based on (*prate / div) value in
> case it is not 0. It's as much higher as power of two of nearest value to
> (*prate / div / maxn). Thus, the patch replaces while-loop by direct
> calculations.
> 
> While here, fix off-by-one error. maxn is the maximum value that can be hold by
> a register which means all ones in it.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
> ---
>  drivers/clk/clk-fractional-divider.c | 13 ++++++-------
>  1 file changed, 6 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/clk/clk-fractional-divider.c b/drivers/clk/clk-fractional-divider.c
> index 6aa72d9..4c0541b 100644
> --- a/drivers/clk/clk-fractional-divider.c
> +++ b/drivers/clk/clk-fractional-divider.c
> @@ -14,6 +14,7 @@
>  #include <linux/device.h>
>  #include <linux/slab.h>
>  #include <linux/gcd.h>
> +#include <linux/log2.h>
>  
>  #define to_clk_fd(_hw) container_of(_hw, struct clk_fractional_divider, hw)
>  
> @@ -49,18 +50,16 @@ static long clk_fd_round_rate(struct clk_hw *hw, unsigned long rate,
>  			      unsigned long *prate)
>  {
>  	struct clk_fractional_divider *fd = to_clk_fd(hw);
> -	unsigned maxn = (fd->nmask >> fd->nshift) + 1;
> -	unsigned div;
> +	unsigned maxn = fd->nmask >> fd->nshift;
> +	unsigned long div, n;
>  
>  	if (!rate || rate >= *prate)
>  		return *prate;
>  
>  	div = gcd(*prate, rate);
> -
> -	while ((*prate / div) > maxn) {
> -		div <<= 1;
> -		rate <<= 1;
> -	}
> +	n = *prate / div;
> +	if (n > maxn)
> +		return rate * roundup_pow_of_two(n / maxn);
>  
>  	return rate;
>  }

Is there any reason why this code isn't using
rational_best_approximation() and mult_frac()? 

-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
--
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