diff options
author | Alex Elder <elder@linaro.org> | 2014-07-16 08:44:38 -0500 |
---|---|---|
committer | Alex Elder <elder@linaro.org> | 2014-07-17 08:54:53 -0500 |
commit | 4010ea588f7693e492dc75016dd9fe3d094c80c1 (patch) | |
tree | 065c2450057f2234417844b9f09969711d0675e7 | |
parent | cf1b51674ddc5f9b714df84ebaa018dfc8d6b758 (diff) |
printk: honor LOG_PREFIX in msg_print_text()
This patch fixes a problem similar to what was addressed in the
previous patch.
All paths that read and format log records (for consoles, and for
reading via syslog and /dev/kmsg) go through msg_print_text(). That
function starts with some logic to determine whether the given log
record when formatted should begin with a "prefix" string, and
whether it should end with a newline. That logic has a bug.
The LOG_PREFIX flag in a log record indicates that when it's
formatted, a log record should include a prefix. This is used to
force a record to begin a new line--even if its preceding log record
contained LOG_CONT (indicating its content should be combined with
the next record).
Like the previous patch, the problem occurs when these flags are
all set:
prev & LOG_CONT
msg->flags & LOG_PREFIX
msg->flags & LOG_CONT
In that case, "prefix" should be true but it is not.
The fix involves checking LOG_PREFIX when a message has its LOG_CONT
flag set, and in that case allowing "prefix" to become false only
if LOG_PREFIX is not set. I.e., the logic for "prefix" would become:
if (prev & LOG_CONT && !(msg->flags & LOG_PREFIX))
prefix = false;
if (msg->flags & LOG_CONT)
if (prev & LOG_CONT && !(msg->flags & LOG_PREFIX))
prefix = false;
However, note that this makes the (msg->flags & LOG_CONT) block
redunant--it's handled by the test just above it. The result
becomes quite a bit simpler than before.
The following table concisely defines the problem:
prev | msg | msg ||
CONT |PREFIX| CONT ||prefix
------+------+------++------
clear| clear| clear|| true
clear| clear| set || true
clear| set | clear|| true
clear| set | set || true
set | clear| clear|| false
set | clear| set || false
set | set | clear|| true
set | set | set || false <-- should be true
Signed-off-by: Alex Elder <elder@linaro.org>
-rw-r--r-- | kernel/printk/printk.c | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 5d719bfebe9..e5ee1cb35a7 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1006,11 +1006,8 @@ static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev, if ((prev & LOG_CONT) && !(msg->flags & LOG_PREFIX)) prefix = false; - if (msg->flags & LOG_CONT) { - if (prev & LOG_CONT) - prefix = false; + if (msg->flags & LOG_CONT) newline = false; - } do { const char *next = memchr(text, '\n', text_size); |