Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: use vmalloc_array and vcalloc for array allocations

Instead of using array_size or just a multiply, use a function that
takes care of both the multiplication and the overflow checks.

Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

+2 -4
+1 -1
mm/percpu-stats.c
··· 144 144 spin_unlock_irq(&pcpu_lock); 145 145 146 146 /* there can be at most this many free and allocated fragments */ 147 - buffer = vmalloc(array_size(sizeof(int), (2 * max_nr_alloc + 1))); 147 + buffer = vmalloc_array(2 * max_nr_alloc + 1, sizeof(int)); 148 148 if (!buffer) 149 149 return -ENOMEM; 150 150
+1 -3
mm/swap_cgroup.c
··· 167 167 int swap_cgroup_swapon(int type, unsigned long max_pages) 168 168 { 169 169 void *array; 170 - unsigned long array_size; 171 170 unsigned long length; 172 171 struct swap_cgroup_ctrl *ctrl; 173 172 174 173 length = DIV_ROUND_UP(max_pages, SC_PER_PAGE); 175 - array_size = length * sizeof(void *); 176 174 177 - array = vzalloc(array_size); 175 + array = vcalloc(length, sizeof(void *)); 178 176 if (!array) 179 177 goto nomem; 180 178