summaryrefslogtreecommitdiffstats
path: root/kernel/printk
diff options
context:
space:
mode:
authorPetr Mladek <pmladek@suse.cz>2014-06-04 19:11:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-06-04 19:54:16 -0400
commit034633ccb24d675850f99bf85c1c5880c831e4b6 (patch)
treeca0deb2021cadb8a0a79a1e6bf86d021a55a57f0 /kernel/printk
parent55bd53a4eb3dd18be8744f8b4d026068fc801a62 (diff)
printk: return really stored message length
I wonder if anyone uses printk return value but it is there and should be counted correctly. This patch modifies log_store() to return the number of really stored bytes from the 'text' part. Also it handles the return value in vprintk_emit(). Note that log_store() is used also in cont_flush() but we could ignore the return value there. The function works with characters that were already counted earlier. In addition, the store could newer fail here because the length of the printed text is limited by the "cont" buffer and "dict" is NULL. 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.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 7131dd4d0e3a..7476a53bc378 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -378,10 +378,10 @@ static u32 truncate_msg(u16 *text_len, u16 *trunc_msg_len,
378} 378}
379 379
380/* insert record into the buffer, discard old ones, update heads */ 380/* insert record into the buffer, discard old ones, update heads */
381static void log_store(int facility, int level, 381static int log_store(int facility, int level,
382 enum log_flags flags, u64 ts_nsec, 382 enum log_flags flags, u64 ts_nsec,
383 const char *dict, u16 dict_len, 383 const char *dict, u16 dict_len,
384 const char *text, u16 text_len) 384 const char *text, u16 text_len)
385{ 385{
386 struct printk_log *msg; 386 struct printk_log *msg;
387 u32 size, pad_len; 387 u32 size, pad_len;
@@ -396,7 +396,7 @@ static void log_store(int facility, int level,
396 &dict_len, &pad_len); 396 &dict_len, &pad_len);
397 /* survive when the log buffer is too small for trunc_msg */ 397 /* survive when the log buffer is too small for trunc_msg */
398 if (log_make_free_space(size)) 398 if (log_make_free_space(size))
399 return; 399 return 0;
400 } 400 }
401 401
402 if (log_next_idx + size + sizeof(struct printk_log) > log_buf_len) { 402 if (log_next_idx + size + sizeof(struct printk_log) > log_buf_len) {
@@ -432,6 +432,8 @@ static void log_store(int facility, int level,
432 /* insert message */ 432 /* insert message */
433 log_next_idx += msg->len; 433 log_next_idx += msg->len;
434 log_next_seq++; 434 log_next_seq++;
435
436 return msg->text_len;
435} 437}
436 438
437#ifdef CONFIG_SECURITY_DMESG_RESTRICT 439#ifdef CONFIG_SECURITY_DMESG_RESTRICT
@@ -1606,10 +1608,10 @@ asmlinkage int vprintk_emit(int facility, int level,
1606 "BUG: recent printk recursion!"; 1608 "BUG: recent printk recursion!";
1607 1609
1608 recursion_bug = 0; 1610 recursion_bug = 0;
1609 printed_len += strlen(recursion_msg); 1611 text_len = strlen(recursion_msg);
1610 /* emit KERN_CRIT message */ 1612 /* emit KERN_CRIT message */
1611 log_store(0, 2, LOG_PREFIX|LOG_NEWLINE, 0, 1613 printed_len += log_store(0, 2, LOG_PREFIX|LOG_NEWLINE, 0,
1612 NULL, 0, recursion_msg, printed_len); 1614 NULL, 0, recursion_msg, text_len);
1613 } 1615 }
1614 1616
1615 /* 1617 /*
@@ -1662,9 +1664,12 @@ asmlinkage int vprintk_emit(int facility, int level,
1662 cont_flush(LOG_NEWLINE); 1664 cont_flush(LOG_NEWLINE);
1663 1665
1664 /* buffer line if possible, otherwise store it right away */ 1666 /* buffer line if possible, otherwise store it right away */
1665 if (!cont_add(facility, level, text, text_len)) 1667 if (cont_add(facility, level, text, text_len))
1666 log_store(facility, level, lflags | LOG_CONT, 0, 1668 printed_len += text_len;
1667 dict, dictlen, text, text_len); 1669 else
1670 printed_len += log_store(facility, level,
1671 lflags | LOG_CONT, 0,
1672 dict, dictlen, text, text_len);
1668 } else { 1673 } else {
1669 bool stored = false; 1674 bool stored = false;
1670 1675
@@ -1683,11 +1688,12 @@ asmlinkage int vprintk_emit(int facility, int level,
1683 cont_flush(LOG_NEWLINE); 1688 cont_flush(LOG_NEWLINE);
1684 } 1689 }
1685 1690
1686 if (!stored) 1691 if (stored)
1687 log_store(facility, level, lflags, 0, 1692 printed_len += text_len;
1688 dict, dictlen, text, text_len); 1693 else
1694 printed_len += log_store(facility, level, lflags, 0,
1695 dict, dictlen, text, text_len);
1689 } 1696 }
1690 printed_len += text_len;
1691 1697
1692 /* 1698 /*
1693 * Try to acquire and then immediately release the console semaphore. 1699 * Try to acquire and then immediately release the console semaphore.