From: FUJITA Tomonori An undocumented alteration :( Signed-off-by: FUJITA Tomonori Cc: Jeff Garzik Cc: James Bottomley Cc: Jens Axboe Signed-off-by: Andrew Morton --- lib/iommu-helper.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff -puN lib/iommu-helper.c~iommu-sg-add-iommu-helper-functions-for-the-free-area-management-update lib/iommu-helper.c --- a/lib/iommu-helper.c~iommu-sg-add-iommu-helper-functions-for-the-free-area-management-update +++ a/lib/iommu-helper.c @@ -8,15 +8,20 @@ static unsigned long find_next_zero_area(unsigned long *map, unsigned long size, unsigned long start, - unsigned int nr) + unsigned int nr, + unsigned long align_mask) { unsigned long index, end, i; again: index = find_next_zero_bit(map, size, start); + + /* Align allocation */ + index = (index + align_mask) & ~align_mask; + end = index + nr; - if (end > size) + if (end >= size) return -1; - for (i = index + 1; i < end; i++) { + for (i = index; i < end; i++) { if (test_bit(i, map)) { start = i+1; goto again; @@ -50,9 +55,8 @@ unsigned long iommu_area_alloc(unsigned { unsigned long index; again: - index = find_next_zero_area(map, size, start, nr); + index = find_next_zero_area(map, size, start, nr, align_mask); if (index != -1) { - index = (index + align_mask) & ~align_mask; if (is_span_boundary(index, nr, shift, boundary_size)) { /* we could do more effectively */ start = index + 1; _