diff options
| author | Petr Mladek <pmladek@suse.cz> | 2014-06-04 19:11:31 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-04 19:54:16 -0400 |
| commit | 85c87043023b7e5535f975bbee12a4f5399df520 (patch) | |
| tree | dd1ad8eb2e43fa09bb06cfff67bd13a6016dc5a0 /kernel/printk | |
| parent | f40e4b9f70d48eb08f443642283fdd9d05b27c6d (diff) | |
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: Petr 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/printk')
| -rw-r--r-- | kernel/printk/printk.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 8fbbab1771eb..9f088ed8404b 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c | |||
| @@ -339,6 +339,18 @@ static int log_make_free_space(u32 msg_size) | |||
| 339 | return -ENOMEM; | 339 | return -ENOMEM; |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | /* compute the message size including the padding bytes */ | ||
| 343 | static u32 msg_used_size(u16 text_len, u16 dict_len, u32 *pad_len) | ||
| 344 | { | ||
| 345 | u32 size; | ||
| 346 | |||
| 347 | size = sizeof(struct printk_log) + text_len + dict_len; | ||
| 348 | *pad_len = (-size) & (LOG_ALIGN - 1); | ||
| 349 | size += *pad_len; | ||
| 350 | |||
| 351 | return size; | ||
| 352 | } | ||
| 353 | |||
| 342 | /* insert record into the buffer, discard old ones, update heads */ | 354 | /* insert record into the buffer, discard old ones, update heads */ |
| 343 | static void log_store(int facility, int level, | 355 | static void log_store(int facility, int level, |
| 344 | enum log_flags flags, u64 ts_nsec, | 356 | enum log_flags flags, u64 ts_nsec, |
| @@ -349,9 +361,7 @@ static void log_store(int facility, int level, | |||
| 349 | u32 size, pad_len; | 361 | u32 size, pad_len; |
| 350 | 362 | ||
| 351 | /* number of '\0' padding bytes to next message */ | 363 | /* number of '\0' padding bytes to next message */ |
| 352 | size = sizeof(struct printk_log) + text_len + dict_len; | 364 | size = msg_used_size(text_len, dict_len, &pad_len); |
| 353 | pad_len = (-size) & (LOG_ALIGN - 1); | ||
| 354 | size += pad_len; | ||
| 355 | 365 | ||
| 356 | /* if message does not fit empty log buffer, ignore it */ | 366 | /* if message does not fit empty log buffer, ignore it */ |
| 357 | if (log_make_free_space(size)) | 367 | if (log_make_free_space(size)) |
