public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@linaro.org>
To: akpm@linux-foundation.org
Cc: pmladek@suse.cz, bp@suse.de, john.stultz@linaro.org,
	jack@suse.cz, linux-kernel@vger.kernel.org
Subject: [PATCH v2 4/6] printk: honor LOG_PREFIX in msg_print_text()
Date: Thu, 17 Jul 2014 09:09:09 -0500	[thread overview]
Message-ID: <1405606151-19875-5-git-send-email-elder@linaro.org> (raw)
In-Reply-To: <1405606151-19875-1-git-send-email-elder@linaro.org>

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>
---
 kernel/printk/printk.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 5d719bf..e5ee1cb 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);
-- 
1.9.1


  parent reply	other threads:[~2014-07-17 14:09 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-17 14:09 [PATCH v2 0/6] printk: start simplifying some flags Alex Elder
2014-07-17 14:09 ` [PATCH v2 1/6] printk: initialize syslog_prev and console_prev Alex Elder
2014-07-18 10:43   ` Petr Mládek
2014-07-18 13:38     ` Alex Elder
2014-07-17 14:09 ` [PATCH v2 2/6] printk: LOG_CONT and LOG_NEWLINE are opposites Alex Elder
2014-07-18 10:53   ` Petr Mládek
2014-07-18 13:39     ` Alex Elder
2014-07-17 14:09 ` [PATCH v2 3/6] printk: honor LOG_PREFIX in devkmsg_read() Alex Elder
2014-07-17 14:09 ` Alex Elder [this message]
2014-07-18 11:03   ` [PATCH v2 4/6] printk: honor LOG_PREFIX in msg_print_text() Petr Mládek
2014-07-17 14:09 ` [PATCH v2 5/6] printk: insert newline in devkmsg_read() Alex Elder
2014-07-18 11:45   ` Petr Mládek
2014-07-18 14:02     ` Alex Elder
2014-07-17 14:09 ` [PATCH v2 6/6] printk: correct some more typos Alex Elder
2014-07-18 11:46   ` Petr Mládek
2014-07-17 15:59 ` [PATCH v2 0/6] printk: start simplifying some flags Joe Perches
2014-07-17 16:04   ` Alex Elder

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=1405606151-19875-5-git-send-email-elder@linaro.org \
    --to=elder@linaro.org \
    --cc=akpm@linux-foundation.org \
    --cc=bp@suse.de \
    --cc=jack@suse.cz \
    --cc=john.stultz@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.cz \
    /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