microblaze: Prevent the overflow of the start
authorShubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Sat, 11 Jan 2020 13:14:34 +0000 (18:44 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 24 Feb 2020 07:34:53 +0000 (08:34 +0100)
[ Upstream commit 061d2c1d593076424c910cb1b64ecdb5c9a6923f ]

In case the start + cache size is more than the max int the
start overflows.
Prevent the same.

Signed-off-by: Shubhrajyoti Datta <shubhrajyoti.datta@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
arch/microblaze/kernel/cpu/cache.c

index 0bde47e..dcba538 100644 (file)
@@ -92,7 +92,8 @@ static inline void __disable_dcache_nomsr(void)
 #define CACHE_LOOP_LIMITS(start, end, cache_line_length, cache_size)   \
 do {                                                                   \
        int align = ~(cache_line_length - 1);                           \
-       end = min(start + cache_size, end);                             \
+       if (start <  UINT_MAX - cache_size)                             \
+               end = min(start + cache_size, end);                     \
        start &= align;                                                 \
 } while (0)