Re: [PATCH] 8250_dw: do not int overflow when rate can not be aplied

2018-01-12 Thread Ed Blake
On 11/01/18 18:03, Ed Blake wrote: > On 11/01/18 17:55, Nuno Gonçalves wrote: >> So, for me clk_round_rate() always returns 2400, and only the loop >> variable i changes, so the search is monotonic, from the highest baud >> to the lowest (increasing divider). >> >> I am using a Allwiner H2+, wi

Re: [PATCH] 8250_dw: do not int overflow when rate can not be aplied

2018-01-11 Thread Ed Blake
On 11/01/18 17:55, Nuno Gonçalves wrote: > So, for me clk_round_rate() always returns 2400, and only the loop > variable i changes, so the search is monotonic, from the highest baud > to the lowest (increasing divider). > > I am using a Allwiner H2+, with the serial port configuration from > su

Re: [PATCH] 8250_dw: do not int overflow when rate can not be aplied

2018-01-11 Thread Nuno Gonçalves
So, for me clk_round_rate() always returns 2400, and only the loop variable i changes, so the search is monotonic, from the highest baud to the lowest (increasing divider). I am using a Allwiner H2+, with the serial port configuration from sunxi-h3-h5.dtsi. Are you sure that clk_round_rate ca

Re: [PATCH] 8250_dw: do not int overflow when rate can not be aplied

2018-01-11 Thread Ed Blake
On 11/01/18 17:28, Nuno Gonçalves wrote: > I have to disagree :) > > if (rate < i * min_rate) is true to i=a, then > > (rate >= i * min_rate && rate <= i * max_rate) will always be false > for any i=b, where b>a. No, because 'rate' is assigned from clk_round_rate() each iteration. The idea of thi

Re: [PATCH] 8250_dw: do not int overflow when rate can not be aplied

2018-01-11 Thread Nuno Gonçalves
I have to disagree :) if (rate < i * min_rate) is true to i=a, then (rate >= i * min_rate && rate <= i * max_rate) will always be false for any i=b, where b>a. If this condition is true, it means the old condition would be always false for the remaining of the iteration. My patch "only" avoids

Re: [PATCH] 8250_dw: do not int overflow when rate can not be aplied

2018-01-11 Thread Ed Blake
Hi Nuno, Thanks for reporting this and the patch. On 11/01/18 13:38, Nuno Goncalves wrote: > When target_rate is big enough and not permitted in hardware, > then i is looped to UART_DIV_MAX (0x), and i * max_rate will overflow > (32b signed). > > A fix is to quit the loop early enough, as soo

[PATCH] 8250_dw: do not int overflow when rate can not be aplied

2018-01-11 Thread Nuno Goncalves
When target_rate is big enough and not permitted in hardware, then i is looped to UART_DIV_MAX (0x), and i * max_rate will overflow (32b signed). A fix is to quit the loop early enough, as soon as rate < i * min_rate as it means the rate is not permitted. This avoids arbitraty rates to be app