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

From: Steven Rostedt
Date: Sat Apr 15 2023 - 04:00:19 EST




On April 15, 2023 3:04:06 AM EDT, Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx> wrote:
>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.

Sure. Why not.

-- Steve

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

--
Sent from my Android device with K-9 Mail. Please excuse my brevity and top posting.