Re: [PATCH printk v2 5/7] printk: Use struct console_buffers

Petr Mladek
2022-11-24T15:22:56Z

On Thu 2022-11-24 00:19:58, John Ogness wrote:
> From: Thomas Gleixner <tglx@linutronix.de>
>
> Replace the separately allocated output buffers with a single
> instance of struct console_buffers.
>
> Note that the buffer size of devkmsg_user.text_buf, when replaced
> with console_buffers.text, reduces from CONSOLE_EXT_LOG_MAX to
> CONSOLE_LOG_MAX. However, the buffer is only used to read ringbuffer
> records. These records have a maximum size of LOG_LINE_MAX, which
> is defined as CONSOLE_LOG_MAX - PREFIX_MAX.
>
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -2007,6 +2007,10 @@ static int console_trylock_spinning(void)
> return 1;
> }
>
> +#if DROPPED_TEXT_MAX > CONSOLE_EXT_LOG_MAX
> +#error "DROPPED_TEXT_MAX too large for console_buffers->ext_text"
> +#endif

A better solution would be to remove DROPPED_TEXT_MAX completely
and pass the buffer size to call_console_driver(). I mean to do:

static void call_console_driver(struct console *con, const char *text, size_t len,
- char *dropped_text)
+ char *dropped_text, size_t dropped_text_size)
{
size_t dropped_len;

- if (con->dropped && dropped_text) {
- dropped_len = snprintf(dropped_text, DROPPED_TEXT_MAX,
+ if (con->dropped && dropped_text && dropped_text_size) {
+ dropped_len = snprintf(dropped_text, dropped_text_size,
"** %lu printk messages dropped **\n",
con->dropped);
con->dropped = 0;
con->write(con, dropped_text, dropped_len);
}

con->write(con, text, len);
}

The rest looks good. And it is a nice clean up.

Best Regards,
Petr