mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Mladek <pmladek@suse.cz>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Jan Kara <jack@suse.cz>, Jiri Kosina <jkosina@suse.cz>,
	Kay Sievers <kay@vrfy.org>,
	linux-kernel@vger.kernel.org, Petr Mladek <pmladek@suse.cz>
Subject: [PATCH 3/5] printk: Split message size computation
Date: Thu, 10 Apr 2014 11:43:14 +0200	[thread overview]
Message-ID: <1397122996-15136-4-git-send-email-pmladek@suse.cz> (raw)
In-Reply-To: <1397122996-15136-1-git-send-email-pmladek@suse.cz>

We will want to recompute the message size when shrinking too long messages.
Let's put the code into separate function.

The side effect of setting "pad_len" is not nice but it is worth removing
the code duplication. Note that I will probably have one more usage for this
function when handling messages safe way in NMI context.

This patch does not change the existing behavior.

Signed-off-by: Petr Mladek <pmladek@suse.cz>
---
 kernel/printk/printk.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 5de686b6b9e1..7416dfad0a28 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -339,6 +339,18 @@ static int log_make_free_space(u32 msg_size)
 	return -ENOMEM;
 }
 
+/* compute the message size including the padding bytes */
+static u32 msg_used_size(u16 text_len, u16 dict_len, u32 *pad_len)
+{
+	u32 size;
+
+	size = sizeof(struct printk_log) + text_len + dict_len;
+	*pad_len = (-size) & (LOG_ALIGN - 1);
+	size += *pad_len;
+
+	return size;
+}
+
 /* insert record into the buffer, discard old ones, update heads */
 static void log_store(int facility, int level,
 		      enum log_flags flags, u64 ts_nsec,
@@ -349,9 +361,7 @@ static void log_store(int facility, int level,
 	u32 size, pad_len;
 
 	/* number of '\0' padding bytes to next message */
-	size = sizeof(struct printk_log) + text_len + dict_len;
-	pad_len = (-size) & (LOG_ALIGN - 1);
-	size += pad_len;
+	size = msg_used_size(text_len, dict_len, &pad_len);
 
 	/* if message does not fit empty log buffer, ignore it */
 	if (log_make_free_space(size))
-- 
1.8.4


  parent reply	other threads:[~2014-04-10  9:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-10  9:43 [PATCH 0/5] printk: Check for too long messages Petr Mladek
2014-04-10  9:43 ` [PATCH 1/5] printk: Split code for making free space in the log buffer Petr Mladek
2014-04-10  9:43 ` [PATCH 2/5] printk: Ignore too long messages Petr Mladek
2014-04-10  9:43 ` Petr Mladek [this message]
2014-04-10  9:43 ` [PATCH 4/5] printk: Shrink " Petr Mladek
2014-04-10  9:43 ` [PATCH 5/5] printk: Return really stored message length Petr Mladek

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=1397122996-15136-4-git-send-email-pmladek@suse.cz \
    --to=pmladek@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=jack@suse.cz \
    --cc=jkosina@suse.cz \
    --cc=kay@vrfy.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®