Commit 85c87043 authored by Petr Mladek's avatar Petr Mladek Committed by Linus Torvalds

printk: split message size computation

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: default avatarPetr Mladek <pmladek@suse.cz>
Cc: Jan Kara <jack@suse.cz>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Kay Sievers <kay@vrfy.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f40e4b9f
...@@ -339,6 +339,18 @@ static int log_make_free_space(u32 msg_size) ...@@ -339,6 +339,18 @@ static int log_make_free_space(u32 msg_size)
return -ENOMEM; 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 */ /* insert record into the buffer, discard old ones, update heads */
static void log_store(int facility, int level, static void log_store(int facility, int level,
enum log_flags flags, u64 ts_nsec, enum log_flags flags, u64 ts_nsec,
...@@ -349,9 +361,7 @@ static void log_store(int facility, int level, ...@@ -349,9 +361,7 @@ static void log_store(int facility, int level,
u32 size, pad_len; u32 size, pad_len;
/* number of '\0' padding bytes to next message */ /* number of '\0' padding bytes to next message */
size = sizeof(struct printk_log) + text_len + dict_len; size = msg_used_size(text_len, dict_len, &pad_len);
pad_len = (-size) & (LOG_ALIGN - 1);
size += pad_len;
/* if message does not fit empty log buffer, ignore it */ /* if message does not fit empty log buffer, ignore it */
if (log_make_free_space(size)) if (log_make_free_space(size))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment