dm bufio: fix integer overflow when limiting maximum cache size
[pandora-kernel.git] / drivers / md / dm-bufio.c
index 3bf7267..ec24a1c 100644 (file)
@@ -839,7 +839,8 @@ static void __get_memory_limit(struct dm_bufio_client *c,
                buffers = DM_BUFIO_MIN_BUFFERS;
 
        *limit_buffers = buffers;
-       *threshold_buffers = buffers * DM_BUFIO_WRITEBACK_PERCENT / 100;
+       *threshold_buffers = mult_frac(buffers,
+                                      DM_BUFIO_WRITEBACK_PERCENT, 100);
 }
 
 /*
@@ -1620,19 +1621,15 @@ static int __init dm_bufio_init(void)
        memset(&dm_bufio_caches, 0, sizeof dm_bufio_caches);
        memset(&dm_bufio_cache_names, 0, sizeof dm_bufio_cache_names);
 
-       mem = (__u64)((totalram_pages - totalhigh_pages) *
-                     DM_BUFIO_MEMORY_PERCENT / 100) << PAGE_SHIFT;
+       mem = (__u64)mult_frac(totalram_pages - totalhigh_pages,
+                              DM_BUFIO_MEMORY_PERCENT, 100) << PAGE_SHIFT;
 
        if (mem > ULONG_MAX)
                mem = ULONG_MAX;
 
 #ifdef CONFIG_MMU
-       /*
-        * Get the size of vmalloc space the same way as VMALLOC_TOTAL
-        * in fs/proc/internal.h
-        */
-       if (mem > (VMALLOC_END - VMALLOC_START) * DM_BUFIO_VMALLOC_PERCENT / 100)
-               mem = (VMALLOC_END - VMALLOC_START) * DM_BUFIO_VMALLOC_PERCENT / 100;
+       if (mem > mult_frac(VMALLOC_END - VMALLOC_START, DM_BUFIO_VMALLOC_PERCENT, 100))
+               mem = mult_frac(VMALLOC_END - VMALLOC_START, DM_BUFIO_VMALLOC_PERCENT, 100);
 #endif
 
        dm_bufio_default_cache_size = mem;