Skip to contentSkip to conversation

kfifo_alloc buffer

PATCH In review Martin Waitz 2 participants 3 messages Nov 4, 2004 – Nov 5, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kfifo_alloc buffer

hi :)

kfifo_alloc tries to round up the buffer size to the next power of two. But it accidently uses the original size when calling kfifo_init, which will BUG.

Index: kernel/kfifo.c
===================================================================
RCS file: /home/inf3/mnwaitz/src/linux-cvs/linux-2.5/kernel/kfifo.c,v retrieving revision 1.2

kfifo.c +2 -4
diff -u -p -r1.2 kfifo.c
@@ -66,7 +66,6 @@ EXPORT_SYMBOL(kfifo_init);
  */
 struct kfifo *kfifo_alloc(unsigned int size, int gfp_mask, spinlock_t *lock)
 {
-	unsigned int newsize;
 	unsigned char *buffer;
 	struct kfifo *ret;
 
@@ -74,13 +73,12 @@ struct kfifo *kfifo_alloc(unsigned int s
 	 * round up to the next power of 2, since our 'let the indices
 	 * wrap' tachnique works only in this case.
 	 */
-	newsize = size;
 	if (size & (size - 1)) {
 		BUG_ON(size > 0x80000000);
-		newsize = roundup_pow_of_two(size);
+		size = roundup_pow_of_two(size);
 	}
 
-	buffer = kmalloc(newsize, gfp_mask);
+	buffer = kmalloc(size, gfp_mask);
 	if (!buffer)
 		return ERR_PTR(-ENOMEM);
 
Signature · 1 line
Martin Waitz
#1 lore raw
Quoted 5 lines · Martin Waitz

hi :)

kfifo_alloc tries to round up the buffer size to the next power of two. But it accidently uses the original size when calling kfifo_init, which will BUG.

Good catch, thanks.

Linus, please apply.

Stelian.

Signature · 1 line
Stelian Pop <[email protected]>
#2 lore raw

hoi :)

by the way, shouldn't kernel/kfifo.c be moved over to lib/ ?

Signature · 1 line
Martin Waitz