The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] bitmap: fix bitmap_find_free_region()
@ 2008-12-19 11:26 Guennadi Liakhovetski
  2008-12-19 13:02 ` Johannes Weiner
  0 siblings, 1 reply; 9+ messages in thread
From: Guennadi Liakhovetski @ 2008-12-19 11:26 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton

Currently bitmap_find_free_region() assumes, that the requested region 
size is smaller than the entire bitmap. If this is not the case it fails 
to detect it and returns success, while pointing at a position outside of 
the region.

Signed-off-by: Guennadi Liakhovetski <lg@denx.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
It is hard to believe, that this is a bug, last time this code was touched 
in 2006... Or should the caller guarantee, that the requested region is 
not larger than the bitmap? Then dma_alloc_from_coherent() is buggy, which 
is where I hit this bug. But it seems to me bitmap_find_free_region() 
should be fixed.

diff --git a/lib/bitmap.c b/lib/bitmap.c
index 1338469..079c5e3 100644
--- a/lib/bitmap.c
+++ b/lib/bitmap.c
@@ -950,6 +950,9 @@ int bitmap_find_free_region(unsigned long *bitmap, int bits, int order)
 {
 	int pos;		/* scans bitmap by regions of size order */
 
+	if (bits < 1 << order)
+		return -ENOMEM;
+
 	for (pos = 0; pos < bits; pos += (1 << order))
 		if (__reg_op(bitmap, pos, order, REG_OP_ISFREE))
 			break;

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-12-20 11:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-19 11:26 [PATCH] bitmap: fix bitmap_find_free_region() Guennadi Liakhovetski
2008-12-19 13:02 ` Johannes Weiner
2008-12-19 13:18   ` Guennadi Liakhovetski
2008-12-19 13:59     ` Pekka Enberg
2008-12-19 14:47     ` Johannes Weiner
2008-12-19 15:09       ` Guennadi Liakhovetski
2008-12-19 22:45         ` Johannes Weiner
2008-12-19 23:19           ` Guennadi Liakhovetski
2008-12-20 11:34             ` Johannes Weiner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox