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

From: Werner Almesberger
Date: Mon Sep 20 2004 - 19:34:31 EST


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 -----------------------------------

Signed-off-by: Werner Almesberger <werner@xxxxxxxxxxxxxxx>

--- linux-2.6.7/kernel/printk.c.orig Mon Sep 20 20:49:02 2004
+++ linux-2.6.7/kernel/printk.c Mon Sep 20 21:26:09 2004
@@ -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;

--
_________________________________________________________________________
/ Werner Almesberger, Buenos Aires, Argentina werner@xxxxxxxxxxxxxxx /
/_http://www.almesberger.net/____________________________________________/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/