Skip to content

Commit a1ad4b8

Browse files
cdownpmladek
authored andcommitted
printk: Straighten out log_flags into printk_info_flags
In the past, `enum log_flags` was part of `struct log`, hence the name. `struct log` has since been reworked and now this struct is stored inside `struct printk_info`. However, the name was never updated, which is somewhat confusing -- especially since these flags operate at the record level rather than at the level of an abstract log. printk_info_flags also joins its other metadata struct friends in printk_ringbuffer.h. Signed-off-by: Chris Down <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Acked-by: Andy Shevchenko <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/3dd801982f02603e6e3aa4f8bc4f5ebb830a4949.1623775748.git.chris@chrisdown.name
1 parent 91027d0 commit a1ad4b8

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

kernel/printk/internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212

1313
#define PRINTK_NMI_CONTEXT_OFFSET 0x010000000
1414

15+
/* Flags for a single printk record. */
16+
enum printk_info_flags {
17+
LOG_NEWLINE = 2, /* text ended with a newline */
18+
LOG_CONT = 8, /* text is a fragment of a continuation line */
19+
};
20+
1521
__printf(4, 0)
1622
int vprintk_store(int facility, int level,
1723
const struct dev_printk_info *dev_info,

kernel/printk/printk.c

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,6 @@ static int console_msg_format = MSG_FORMAT_DEFAULT;
350350
* non-prinatable characters are escaped in the "\xff" notation.
351351
*/
352352

353-
enum log_flags {
354-
LOG_NEWLINE = 2, /* text ended with a newline */
355-
LOG_CONT = 8, /* text is a fragment of a continuation line */
356-
};
357-
358353
/* syslog_lock protects syslog_* variables and write access to clear_seq. */
359354
static DEFINE_RAW_SPINLOCK(syslog_lock);
360355

@@ -1965,19 +1960,20 @@ static inline u32 printk_caller_id(void)
19651960
*
19661961
* @text: The terminated text message.
19671962
* @level: A pointer to the current level value, will be updated.
1968-
* @lflags: A pointer to the current log flags, will be updated.
1963+
* @flags: A pointer to the current printk_info flags, will be updated.
19691964
*
19701965
* @level may be NULL if the caller is not interested in the parsed value.
19711966
* Otherwise the variable pointed to by @level must be set to
19721967
* LOGLEVEL_DEFAULT in order to be updated with the parsed value.
19731968
*
1974-
* @lflags may be NULL if the caller is not interested in the parsed value.
1975-
* Otherwise the variable pointed to by @lflags will be OR'd with the parsed
1969+
* @flags may be NULL if the caller is not interested in the parsed value.
1970+
* Otherwise the variable pointed to by @flags will be OR'd with the parsed
19761971
* value.
19771972
*
19781973
* Return: The length of the parsed level and control flags.
19791974
*/
1980-
static u16 parse_prefix(char *text, int *level, enum log_flags *lflags)
1975+
static u16 parse_prefix(char *text, int *level,
1976+
enum printk_info_flags *flags)
19811977
{
19821978
u16 prefix_len = 0;
19831979
int kern_level;
@@ -1993,8 +1989,8 @@ static u16 parse_prefix(char *text, int *level, enum log_flags *lflags)
19931989
*level = kern_level - '0';
19941990
break;
19951991
case 'c': /* KERN_CONT */
1996-
if (lflags)
1997-
*lflags |= LOG_CONT;
1992+
if (flags)
1993+
*flags |= LOG_CONT;
19981994
}
19991995

20001996
prefix_len += 2;
@@ -2004,8 +2000,9 @@ static u16 parse_prefix(char *text, int *level, enum log_flags *lflags)
20042000
return prefix_len;
20052001
}
20062002

2007-
static u16 printk_sprint(char *text, u16 size, int facility, enum log_flags *lflags,
2008-
const char *fmt, va_list args)
2003+
static u16 printk_sprint(char *text, u16 size, int facility,
2004+
enum printk_info_flags *flags, const char *fmt,
2005+
va_list args)
20092006
{
20102007
u16 text_len;
20112008

@@ -2014,7 +2011,7 @@ static u16 printk_sprint(char *text, u16 size, int facility, enum log_flags *lfl
20142011
/* Mark and strip a trailing newline. */
20152012
if (text_len && text[text_len - 1] == '\n') {
20162013
text_len--;
2017-
*lflags |= LOG_NEWLINE;
2014+
*flags |= LOG_NEWLINE;
20182015
}
20192016

20202017
/* Strip log level and control flags. */
@@ -2038,7 +2035,7 @@ int vprintk_store(int facility, int level,
20382035
{
20392036
const u32 caller_id = printk_caller_id();
20402037
struct prb_reserved_entry e;
2041-
enum log_flags lflags = 0;
2038+
enum printk_info_flags flags = 0;
20422039
struct printk_record r;
20432040
u16 trunc_msg_len = 0;
20442041
char prefix_buf[8];
@@ -2070,22 +2067,22 @@ int vprintk_store(int facility, int level,
20702067

20712068
/* Extract log level or control flags. */
20722069
if (facility == 0)
2073-
parse_prefix(&prefix_buf[0], &level, &lflags);
2070+
parse_prefix(&prefix_buf[0], &level, &flags);
20742071

20752072
if (level == LOGLEVEL_DEFAULT)
20762073
level = default_message_loglevel;
20772074

20782075
if (dev_info)
2079-
lflags |= LOG_NEWLINE;
2076+
flags |= LOG_NEWLINE;
20802077

2081-
if (lflags & LOG_CONT) {
2078+
if (flags & LOG_CONT) {
20822079
prb_rec_init_wr(&r, reserve_size);
20832080
if (prb_reserve_in_last(&e, prb, &r, caller_id, LOG_LINE_MAX)) {
20842081
text_len = printk_sprint(&r.text_buf[r.info->text_len], reserve_size,
2085-
facility, &lflags, fmt, args);
2082+
facility, &flags, fmt, args);
20862083
r.info->text_len += text_len;
20872084

2088-
if (lflags & LOG_NEWLINE) {
2085+
if (flags & LOG_NEWLINE) {
20892086
r.info->flags |= LOG_NEWLINE;
20902087
prb_final_commit(&e);
20912088
} else {
@@ -2112,20 +2109,20 @@ int vprintk_store(int facility, int level,
21122109
}
21132110

21142111
/* fill message */
2115-
text_len = printk_sprint(&r.text_buf[0], reserve_size, facility, &lflags, fmt, args);
2112+
text_len = printk_sprint(&r.text_buf[0], reserve_size, facility, &flags, fmt, args);
21162113
if (trunc_msg_len)
21172114
memcpy(&r.text_buf[text_len], trunc_msg, trunc_msg_len);
21182115
r.info->text_len = text_len + trunc_msg_len;
21192116
r.info->facility = facility;
21202117
r.info->level = level & 7;
2121-
r.info->flags = lflags & 0x1f;
2118+
r.info->flags = flags & 0x1f;
21222119
r.info->ts_nsec = ts_nsec;
21232120
r.info->caller_id = caller_id;
21242121
if (dev_info)
21252122
memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info));
21262123

21272124
/* A message without a trailing newline can be continued. */
2128-
if (!(lflags & LOG_NEWLINE))
2125+
if (!(flags & LOG_NEWLINE))
21292126
prb_commit(&e);
21302127
else
21312128
prb_final_commit(&e);

0 commit comments

Comments
 (0)