From: Werner Almesberger <werner@almesberger.net>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Andrew Morton <akpm@osdl.org>
Subject: [PATCH][2.6.7] round log buffer size to power of two
Date: Mon, 20 Sep 2004 21:32:54 -0300 [thread overview]
Message-ID: <20040920213254.B2093@almesberger.net> (raw)
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/____________________________________________/
reply other threads:[~2004-09-21 0:33 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040920213254.B2093@almesberger.net \
--to=werner@almesberger.net \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®