OSDN Git Service

mtd: nand: lpc32xx_slc: fix potential overflow over 4 bits
authorVladimir Zapolskiy <vz@mleia.com>
Wed, 30 Sep 2015 23:23:36 +0000 (02:23 +0300)
committerBrian Norris <computersforpeace@gmail.com>
Sun, 4 Oct 2015 21:30:49 +0000 (22:30 +0100)
In case if quotient of controller clock rate to device clock rate does
not fit into 4 bit value, choose the maximum acceptable value 0xF, which
stands for 16 clocks.

Signed-off-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
drivers/mtd/nand/lpc32xx_slc.c

index 9ac0f3b..a9e8a02 100644 (file)
@@ -95,7 +95,7 @@
 * slc_tac register definitions
 **********************************************************************/
 /* Computation of clock cycles on basis of controller and device clock rates */
-#define SLCTAC_CLOCKS(c, n, s) (((1 + (c / n)) & 0xF) << s)
+#define SLCTAC_CLOCKS(c, n, s) (min_t(u32, 1 + (c / n), 0xF) << s)
 
 /* Clock setting for RDY write sample wait time in 2*n clocks */
 #define SLCTAC_WDR(n)          (((n) & 0xF) << 28)