mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH][2.6.7] round log buffer size to power of two
@ 2004-09-21  0:32 Werner Almesberger
  0 siblings, 0 replies; only message in thread
From: Werner Almesberger @ 2004-09-21  0:32 UTC (permalink / raw)
  To: linux-kernel; +Cc: Andrew Morton

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@almesberger.net>

--- 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@almesberger.net /
/_http://www.almesberger.net/____________________________________________/

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-09-21  0:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-21  0:32 [PATCH][2.6.7] round log buffer size to power of two Werner Almesberger

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

all inboxes | Powered by JetHome®