aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-10-09 01:02:09 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-09 15:23:39 -0400
commitc362c7ff84634390b44cc1ae7808519596de162d (patch)
tree63d9f21344d5552a844688be4a4979e5847804dd
parent4bcc595ccd80decb4245096e3d1258989c50ed41 (diff)
printk: split out core logging code into helper function
The code that actually decides how to log the message (whether to put it directly into the record log, whether to append it to an existing buffered log, or whether to start a new buffered log) is fairly non-obvious code in the middle of the vprintk_emit() function. Splitting that code up into a helper function makes it easier to understand, but perhaps more importantly also allows for the code to just return early out of the helper function once it has made the decision about where the new log content goes. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--kernel/printk/printk.c78
1 files changed, 39 insertions, 39 deletions
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 7b449802089a..090e201244d8 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -1730,6 +1730,44 @@ static size_t cont_print_text(char *text, size_t size)
1730 return textlen; 1730 return textlen;
1731} 1731}
1732 1732
1733static size_t log_output(int facility, int level, enum log_flags lflags, const char *dict, size_t dictlen, char *text, size_t text_len)
1734{
1735 if (!(lflags & LOG_NEWLINE)) {
1736 /*
1737 * Flush the conflicting buffer. An earlier newline was missing,
1738 * or another task also prints continuation lines.
1739 */
1740 if (cont.len && (!(lflags & LOG_CONT) || cont.owner != current))
1741 cont_flush(LOG_NEWLINE);
1742
1743 /* buffer line if possible, otherwise store it right away */
1744 if (cont_add(facility, level, text, text_len))
1745 return text_len;
1746
1747 return log_store(facility, level, lflags | LOG_CONT, 0, dict, dictlen, text, text_len);
1748 }
1749
1750 /*
1751 * If an earlier newline was missing and it was the same task,
1752 * either merge it with the current buffer and flush, or if
1753 * there was a race with interrupts (prefix == true) then just
1754 * flush it out and store this line separately.
1755 * If the preceding printk was from a different task and missed
1756 * a newline, flush and append the newline.
1757 */
1758 if (cont.len) {
1759 bool stored = false;
1760
1761 if (cont.owner == current && (lflags & LOG_CONT))
1762 stored = cont_add(facility, level, text, text_len);
1763 cont_flush(LOG_NEWLINE);
1764 if (stored)
1765 return text_len;
1766 }
1767
1768 return log_store(facility, level, lflags, 0, dict, dictlen, text, text_len);
1769}
1770
1733asmlinkage int vprintk_emit(int facility, int level, 1771asmlinkage int vprintk_emit(int facility, int level,
1734 const char *dict, size_t dictlen, 1772 const char *dict, size_t dictlen,
1735 const char *fmt, va_list args) 1773 const char *fmt, va_list args)
@@ -1842,45 +1880,7 @@ asmlinkage int vprintk_emit(int facility, int level,
1842 if (dict) 1880 if (dict)
1843 lflags |= LOG_PREFIX|LOG_NEWLINE; 1881 lflags |= LOG_PREFIX|LOG_NEWLINE;
1844 1882
1845 if (!(lflags & LOG_NEWLINE)) { 1883 printed_len += log_output(facility, level, lflags, dict, dictlen, text, text_len);
1846 /*
1847 * Flush the conflicting buffer. An earlier newline was missing,
1848 * or another task also prints continuation lines.
1849 */
1850 if (cont.len && (!(lflags & LOG_CONT) || cont.owner != current))
1851 cont_flush(LOG_NEWLINE);
1852
1853 /* buffer line if possible, otherwise store it right away */
1854 if (cont_add(facility, level, text, text_len))
1855 printed_len += text_len;
1856 else
1857 printed_len += log_store(facility, level,
1858 lflags | LOG_CONT, 0,
1859 dict, dictlen, text, text_len);
1860 } else {
1861 bool stored = false;
1862
1863 /*
1864 * If an earlier newline was missing and it was the same task,
1865 * either merge it with the current buffer and flush, or if
1866 * there was a race with interrupts (prefix == true) then just
1867 * flush it out and store this line separately.
1868 * If the preceding printk was from a different task and missed
1869 * a newline, flush and append the newline.
1870 */
1871 if (cont.len) {
1872 if (cont.owner == current && (lflags & LOG_CONT))
1873 stored = cont_add(facility, level, text,
1874 text_len);
1875 cont_flush(LOG_NEWLINE);
1876 }
1877
1878 if (stored)
1879 printed_len += text_len;
1880 else
1881 printed_len += log_store(facility, level, lflags, 0,
1882 dict, dictlen, text, text_len);
1883 }
1884 1884
1885 logbuf_cpu = UINT_MAX; 1885 logbuf_cpu = UINT_MAX;
1886 raw_spin_unlock(&logbuf_lock); 1886 raw_spin_unlock(&logbuf_lock);