From: Lecopzer Chen Date: Mon, 23 Sep 2019 22:36:24 +0000 (-0700) Subject: mm/sparse.c: fix ALIGN() without power of 2 in sparse_buffer_alloc() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=db57e98d87908b8837352abe08515e42752270c1;p=linux.git mm/sparse.c: fix ALIGN() without power of 2 in sparse_buffer_alloc() The size argument passed into sparse_buffer_alloc() has already been aligned with PAGE_SIZE or PMD_SIZE. If the size after aligned is not power of 2 (e.g. 0x480000), the PTR_ALIGN() will return wrong value. Use roundup to round sparsemap_buf up to next multiple of size. Link: http://lkml.kernel.org/r/20190705114826.28586-1-lecopzer.chen@mediatek.com Signed-off-by: Lecopzer Chen Signed-off-by: Mark-PK Tsai Cc: YJ Chiang Cc: Lecopzer Chen Cc: Pavel Tatashin Cc: Oscar Salvador Cc: Michal Hocko Cc: Mike Rapoport Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/mm/sparse.c b/mm/sparse.c index 2bfd078301f87..79355a86064f6 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -501,7 +501,7 @@ void * __meminit sparse_buffer_alloc(unsigned long size) void *ptr = NULL; if (sparsemap_buf) { - ptr = PTR_ALIGN(sparsemap_buf, size); + ptr = (void *) roundup((unsigned long)sparsemap_buf, size); if (ptr + size > sparsemap_buf_end) ptr = NULL; else {