History

bitmap: fix end condition in bitmap_find_free_region

Guennadi Liakhovetski noticed that the end condition for the loop in bitmap_find_free_region() is wrong, and the "return if error" was also using the wrong conditional that would only trigger if the bitmap was an exact multiple of the allocation size, which is not necessarily the case with dma_alloc_from_coherent(). Such a failure would end up in bitmap_find_free_region() accessing beyond the end of the bitmap.

Linus Torvalds committed 17 years ago

Commit aa8e4fc1 parent 9ead6491 file · +8 −8Browse files

Unified · Split

lib/bitmap.c+8−8
@@ -948,15 +948,15 @@ done: · 947 unmodified lines
948 */948 */
949int bitmap_find_free_region(unsigned long *bitmap, int bits, int order)949int bitmap_find_free_region(unsigned long *bitmap, int bits, int order)
950{950{
951 int pos; /* scans bitmap by regions of size order */951 int pos, end; /* scans bitmap by regions of size order */
952 952
953 for (pos = 0; pos < bits; pos += (1 << order))953 for (pos = 0 ; (end = pos + (1 << order)) <= bits; pos = end) {
954 if (__reg_op(bitmap, pos, order, REG_OP_ISFREE))954 if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE))
955 break;955 continue;
956 if (pos == bits)956 __reg_op(bitmap, pos, order, REG_OP_ALLOC);
957 return -ENOMEM;957 return pos;
958 __reg_op(bitmap, pos, order, REG_OP_ALLOC);958 }
959 return pos;959 return -ENOMEM;
960}960}
961EXPORT_SYMBOL(bitmap_find_free_region);961EXPORT_SYMBOL(bitmap_find_free_region);
962 962

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t