Skip to contentSkip to conversation

[2.6.7] round log buffer size to power of two

PATCH New Werner Almesberger 1 participant 1 message Sep 21, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 [2.6.7] round log buffer size to power of two

If setting the printk log buffer (with the boot command line option "log_buf_len") to a value that's not a power of two, the index calculations go wrong and yield confusing results.

This patch rounds the size to the next higher power of two. It'll yield garbage for sizes > INT_MAX bytes.

The patch is for 2.6.7, but should apply equally to 2.6.9-rc2, since the code in question hasn't changed.

- Werner

---------------------------------- cut here -----------------------------------

kernel/printk.c renamed from kernel/printk.c.orig +3 -0
@@ -30,6 +30,7 @@
 #include <linux/smp.h>
 #include <linux/security.h>
 #include <linux/bootmem.h>
+#include <linux/bitops.h>
 
 #include <asm/uaccess.h>
 
@@ -192,6 +193,8 @@
 	unsigned long size = memparse(str, &str);
 	unsigned long flags;
 
+	if (size)
+		size = 1 << fls(size-1); /* round up to power of two */
 	if (size > log_buf_len) {
 		unsigned long start, dest_idx, offset;
 		char * new_log_buf;
Signature · 3 lines
  _________________________________________________________________________
 / Werner Almesberger, Buenos Aires, Argentina     [email protected] /
/_http://www.almesberger.net/____________________________________________/