Skip to contentSkip to conversation

powerpc: fix alignment problem in rh_alloc_align() with exact-sized blocks

PATCH Applied Timur Tabi 2 participants 2 messages May 14, 2007 – May 15, 2007 PowerPC

lore
Share & tools
lore

Timur Tabi

author
#0 lore raw

PATCH 1/1 powerpc: fix alignment problem in rh_alloc_align() with exact-sized blocks

When an rheap is created, the caller can specify the alignment to use. In rh_alloc_align(), if a free block is found that is the exact size needed (including extra space for alignment), that configured alignment value is not used to align the pointer. Instead, the default alignment is used. If the default alignment is smaller than the configured alignment, then the returned value will not be aligned correctly.

---
 arch/powerpc/lib/rheap.c |   22 ++++++++--------------
 1 files changed, 8 insertions(+), 14 deletions(-)
arch/powerpc/lib/rheap.c +8 -14
index b2f6dcc..180ee29 100644
@@ -468,25 +468,19 @@ unsigned long rh_alloc_align(rh_info_t * info, int size, int alignment, const ch
 	if (blk->size == size) {
 		/* Move from free list to taken list */
 		list_del(&blk->list);
-		blk->owner = owner;
-		start = blk->start;
-
-		attach_taken_block(info, blk);
+		newblk = blk;
+	} else {
+		newblk = get_slot(info);
+		newblk->start = blk->start;
+		newblk->size = size;
 
-		return start;
+		/* blk still in free list, with updated start, size */
+		blk->start += size;
+		blk->size -= size;
 	}
 
-	newblk = get_slot(info);
-	newblk->start = blk->start;
-	newblk->size = size;
 	newblk->owner = owner;
-
-	/* blk still in free list, with updated start, size */
-	blk->start += size;
-	blk->size -= size;
-
 	start = newblk->start;
-
 	attach_taken_block(info, newblk);
 
 	/* for larger alignment return fixed up pointer  */
Signature · 1 line
1.5.0.2.260.g2eb065
Applied
#1 lore raw
Quoted 7 lines · Timur Tabi

When an rheap is created, the caller can specify the alignment to use. In rh_alloc_align(), if a free block is found that is the exact size needed (including extra space for alignment), that configured alignment value is not used to align the pointer. Instead, the default alignment is used. If the default alignment is smaller than the configured alignment, then the returned value will not be aligned correctly.

Quoted 5 lines
---
 arch/powerpc/lib/rheap.c |   22 ++++++++--------------
 1 files changed, 8 insertions(+), 14 deletions(-)

applied.

- k