Re: [PATCH next v2 1/3] printk: inline log_output(),log_store() in vprintk_store()

From: Petr Mladek
Date: Thu Dec 03 2020 - 10:58:26 EST


On Tue 2020-12-01 21:59:39, John Ogness wrote:
> In preparation for removing logbuf_lock, inline log_output()
> and log_store() into vprintk_store(). This will simplify dealing
> with the various code branches and fallbacks that are possible.
> ---
> kernel/printk/printk.c | 134 +++++++++++++++++------------------------
> 1 file changed, 56 insertions(+), 78 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index f279d4fbd9dd..fc5e3a7d6d89 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -1983,7 +1915,53 @@ int vprintk_store(int facility, int level,
> if (dev_info)
> lflags |= LOG_NEWLINE;
>
> - return log_output(facility, level, lflags, dev_info, text, text_len);
> + if (lflags & LOG_CONT) {
> + prb_rec_init_wr(&r, text_len);
> + if (prb_reserve_in_last(&e, prb, &r, caller_id, LOG_LINE_MAX)) {
> + memcpy(&r.text_buf[r.info->text_len], text, text_len);
> + r.info->text_len += text_len;
> +
> + if (lflags & LOG_NEWLINE) {
> + r.info->flags |= LOG_NEWLINE;
> + prb_final_commit(&e);
> + } else {
> + prb_commit(&e);
> + }
> +
> + return text_len;
> + }
> + }
> +
> + prb_rec_init_wr(&r, text_len);

This is called in both branches. I would do it just once at the
beginning.

> + if (!prb_reserve(&e, prb, &r)) {
> + /* truncate the message if it is too long for empty buffer */
> + truncate_msg(&text_len, &trunc_msg_len);
> +
> + prb_rec_init_wr(&r, text_len + trunc_msg_len);
> + if (!prb_reserve(&e, prb, &r))
> + return 0;
> + }
> +
> + /* fill message */
> + memcpy(&r.text_buf[0], text, text_len);
> + if (trunc_msg_len)
> + memcpy(&r.text_buf[text_len], trunc_msg, trunc_msg_len);
> + r.info->text_len = text_len + trunc_msg_len;
> + r.info->facility = facility;
> + r.info->level = level & 7;
> + r.info->flags = lflags & 0x1f;
> + r.info->ts_nsec = ts_nsec;

This is the only location where ts_nsec is used. I would remove the
variable and call:

r.info->ts_nsec = local_clock();

> + r.info->caller_id = caller_id;
> + if (dev_info)
> + memcpy(&r.info->dev_info, dev_info, sizeof(r.info->dev_info));
> +
> + /* A message without a trailing newline can be continued. */
> + if (!(lflags & LOG_NEWLINE))
> + prb_commit(&e);
> + else
> + prb_final_commit(&e);
> +
> + return (text_len + trunc_msg_len);
> }

Both changes are cosmetic and I do not resist on them. Please, do the changes
if v3 is needed and you agree with them.

Anyway, feel free to use:

Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>

Best Regards,
Petr