msm: board-8960: Fix overflow in memory calc.
An overflow occurs in locate_unstable_memory() when physical
memory address space ends at 0xFFFFFFFF. Change code to
handle overflow by ensuring that variables are limited to
0xFFFFFFFF and by rearranging additions and subtractions.
Change-Id: I5839499d8274214ca08b9c11b57d44861ec894a3
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
diff --git a/arch/arm/mach-msm/board-msm8960.c b/arch/arm/mach-msm/board-msm8960.c
index ece65f3..35a4804 100644
--- a/arch/arm/mach-msm/board-msm8960.c
+++ b/arch/arm/mach-msm/board-msm8960.c
@@ -1080,12 +1080,22 @@
bank_size = msm8960_memory_bank_size();
low = meminfo.bank[0].start;
high = mb->start + mb->size;
+
+ /* Check if 32 bit overflow occured */
+ if (high < mb->start)
+ high = ~0UL;
+
low &= ~(bank_size - 1);
if (high - low <= bank_size)
return;
msm8960_reserve_info.low_unstable_address = low + bank_size;
- msm8960_reserve_info.max_unstable_size = high - low - bank_size;
+ /* To avoid overflow of u32 compute max_unstable_size
+ * by first subtracting low from mb->start)
+ * */
+ msm8960_reserve_info.max_unstable_size = (mb->start - low) +
+ mb->size - bank_size;
+
msm8960_reserve_info.bank_size = bank_size;
pr_info("low unstable address %lx max size %lx bank size %lx\n",
msm8960_reserve_info.low_unstable_address,