Skip to contentSkip to conversation

mm/sparse: fix ALIGN() without power of 2 in sparse_buffer_alloc()

PATCH New Lecopzer Chen 1 participant 1 message Jul 5, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/sparse: fix ALIGN() without power of 2 in sparse_buffer_alloc()

The size argumnet passed into sparse_buffer_alloc() has already 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.

Cc YJ Chiang <[email protected]>
Cc Lecopzer Chen <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Pavel Tatashin <[email protected]>
Cc Oscar Salvador <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Mike Rapoport <[email protected]>
---
 mm/sparse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/sparse.c +1 -1
index 2b3b5be85120..dafd130f9a55 100644
@@ -459,7 +459,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 {
Signature · 1 line
2.18.0