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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Sat, 20 Jun 2020 09:12:01 +0100
From:   Russell King - ARM Linux admin <linux@...linux.org.uk>
To:     Serge Semin <Sergey.Semin@...kalelectronics.ru>
Cc:     Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Jiri Slaby <jslaby@...e.com>,
        Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Serge Semin <fancer.lancer@...il.com>,
        Alexey Malahov <Alexey.Malahov@...kalelectronics.ru>,
        Arnd Bergmann <arnd@...db.de>,
        Maxime Ripard <mripard@...nel.org>,
        Will Deacon <will@...nel.org>, linux-mips@...r.kernel.org,
        linux-arm-kernel@...ts.infradead.org, linux-serial@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH v7 2/3] serial: 8250_dw: Simplify the ref clock rate
 setting procedure

On Fri, Jun 19, 2020 at 11:02:50PM +0300, Serge Semin wrote:
> Really instead of twice checking the clk_round_rate() return value
> we could do it once, and if it isn't error the clock rate can be changed.
> By doing so we decrease a number of ret-value tests and remove a weird
> goto-based construction implemented in the dw8250_set_termios() method.

This doesn't look right to me - neither the before code nor the after
code.

>  	clk_disable_unprepare(d->clk);
>  	rate = clk_round_rate(d->clk, baud * 16);
> -	if (rate < 0)
> -		ret = rate;
> -	else if (rate == 0)
> -		ret = -ENOENT;
> -	else
> +	if (rate > 0) {
>  		ret = clk_set_rate(d->clk, rate);
> +		if (!ret)
> +			p->uartclk = rate;
> +	}
>  	clk_prepare_enable(d->clk);
>  
> -	if (ret)
> -		goto out;
> -
> -	p->uartclk = rate;

	newrate = baud * 16;

	clk_disable_unprepare(d->clk);
	rate = clk_round_rate(newrate);
	ret = clk_set_rate(d->clk, newrate);
	if (!ret)
		p->uartclk = rate;

	ret = elk_prepare_enable(d->clk);
	/* check ret for failure, means the clock is no longer running */

is all that should be necessary: note that clk_round_rate() is required
to return the rate that a successful call to clk_set_rate() would result
in for that clock.  It is equivalent to:

	ret = clk_set_rate(d->clk, newrate);
	if (ret == 0)
		p->uartclk = clk_get_rate(d->clk);

The other commonly misunderstood thing about the clk API is that the
rate you pass in to clk_round_rate() to discover the actual clock rate
and the value passed in to clk_set_rate() _should_ be the same value.
You should _not_ do clk_set_rate(clk, clk_round_rate(clk, newrate));

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ