Re: [PATCHv2] seq_buf: add seq_buf_do_printk() helper

From: Sergey Senozhatsky
Date: Sat Apr 15 2023 - 03:04:19 EST


On (23/04/14 11:00), Petr Mladek wrote:
> > +void seq_buf_do_printk(struct seq_buf *s, const char *lvl)
> > +{
> > + const char *start, *lf;
> > + int len;
> > +
> > + if (s->size == 0 || s->len == 0)
> > + return;
> > +
> > + seq_buf_terminate(s);
> > +
> > + start = s->buffer;
> > + while ((lf = strchr(start, '\n'))) {
> > + len = lf - start + 1;
> > + printk("%s%.*s", lvl, len, start);
> > + start = ++lf;
> > + }
> > +
> > + /* No trailing LF */
> > + if (start < s->buffer + s->len) {
> > + len = s->buffer + s->len - start;
> > + printk("%s%.*s\n", lvl, len, start);
>
> We know that the string is '\0' terminated, so the last print
> might be easier:
>
> if (start < s->buffer + s->len)
> printk("%s%s\n", lvl, start);

Indeed. Steven, let me know if you'd prefer a v3.

> Anyway, it looks good. With or without this change:
>
> Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>

Thanks Petr!