Re: [PATCH] seq_buf: add seq_buf_printk() helper

From: Sergey Senozhatsky
Date: Tue Apr 11 2023 - 10:24:35 EST


On (23/04/11 14:14), Petr Mladek wrote:
> We might want to somehow distinguish that this is actually
> printing (reading) the context of the buffer.
>
> The name is similar to seq_buf_printf() and seq_buf_vprintf()
> whose are wrinting into the buffer.
>
> What about the following?
>
> + seq_buf_printf_seq() like the existing seq_buf_print_seq()
> + seq_buf_to_printk() like the existing seq_buf_to_user()
>
> I personally prefer seq_buf_to_printk() because it looks more
> selfexplaining to me.

I like seq_buf_to_printk().

> > +{
> > + const char *start, *lf;
> > + int len;
> > +
> > + if (s->size == 0)
> > + return;
> > +
> > + start = s->buffer;
> > + while ((lf = strchr(start, '\n'))) {
>
> We should rather use strnchr(). It seems that the trailing '\0' is
> not guaranteed. For example, seq_buf_putc() just adds the given
> character at the end.

Good point.