Hi Andrew, > -----Original Message----- > From: Zdenko Pulitika > Sent: 10 August 2015 04:56 PM > To: Govindraj Raja; linux-mips@xxxxxxxxxxxxxx; linux-clk@xxxxxxxxxxxxxxx; > Stephen Boyd; Michael Turquette > Cc: Kevin Cernekee; Ralf Baechle; Andrew Bresticker; James Hartley; Damien > Horsley; James Hogan; Ezequiel Garcia > Subject: RE: [PATCH v2 1/4] clk: pistachio: Fix 32bit integer overflows > > Govindraj, > > > -----Original Message----- > > From: Govindraj Raja > > Sent: 07 August 2015 17:20 > > To: linux-mips@xxxxxxxxxxxxxx; linux-clk@xxxxxxxxxxxxxxx; Stephen > > Boyd; Michael Turquette > > Cc: Zdenko Pulitika; Kevin Cernekee; Ralf Baechle; Andrew Bresticker; > > James Hartley; Govindraj Raja; Damien Horsley; James Hogan; Ezequiel > > Garcia; Govindraj Raja > > Subject: [PATCH v2 1/4] clk: pistachio: Fix 32bit integer overflows > > > > From: Zdenko Pulitika <zdenko.pulitika@xxxxxxxxxx> > > > > This commit fixes 32bit integer overflows throughout the pll driver (i.e. > > wherever the result of integer multiplication may exceed the range of u32). > > > > One of the functions affected by this problem is .recalc_rate. It > > returns incorrect rate for some pll settings (not for all though) > > which in turn results in the incorrect rate setup of pll's child clocks. > > > > Signed-off-by: Zdenko Pulitika <zdenko.pulitika@xxxxxxxxxx> > > Signed-off-by: Govindraj Raja <govindraj.raja@xxxxxxxxxx> > > --- > > drivers/clk/pistachio/clk-pll.c | 26 ++++++++++++-------------- > > 1 file changed, 12 insertions(+), 14 deletions(-) > > > > diff --git a/drivers/clk/pistachio/clk-pll.c > > b/drivers/clk/pistachio/clk-pll.c index e17dada..68066ef 100644 > > --- a/drivers/clk/pistachio/clk-pll.c > > +++ b/drivers/clk/pistachio/clk-pll.c > > @@ -88,12 +88,10 @@ static inline void pll_lock(struct pistachio_clk_pll *pll) > > cpu_relax(); > > } > > > > -static inline u32 do_div_round_closest(u64 dividend, u32 divisor) [...] > > 1.9.1 > > [Zdenko Pulitika] Reverting pll_rate_table members from 64 to 32 bit re- > introduces multiplication overflow issue. > We can either 1) keep 64bit members in pll_rate_table and forget about overflow > or 2) have 32 bit members but then we need to type cast them to u64 in every > multiplication expression which may overflow. In my opinion, first solution is > safer and nicer, 2nd will result in ugly typecasts throughout the code and, more > importantly, there's a risk of overflow bug being repeated if somebody wishes to > modify/upgrade the existing code. Like Zdenko pointed out some operations in pll calculation may overflow without converting the struct pistachio_pll_rate_table members to long For example in below code snippet operation: [..] params->fref * params->fbdiv [..] So to be on safer side it's better to have the original code [1]. -- Thanks, Govindraj.R [1]: http://patchwork.linux-mips.org/patch/10888/