Re: [PATCH 1/4] printk/NMI: Handle continuous lines and missing newline

From: David Sterba
Date: Mon Oct 31 2016 - 04:51:55 EST


On Thu, Oct 27, 2016 at 05:52:51PM +0200, Petr Mladek wrote:
> +static int printk_nmi_flush_buffer(unsigned char *start, size_t len)
> {
> - const char *buf = s->buffer + start;
> + unsigned char *c, *end;
> + bool header;
> +
> + c = start;
> + end = start + len;
> + header = true;
> +
> + /* Print line by line. */
> + while (c < end) {
> + if (*c == '\n') {
> + printk_nmi_flush_line(start, c - start + 1);
> + start = ++c;
> + header = true;
> + continue;
> + }
>
> - printk_nmi_flush_line(buf, (end - start) + 1);
> + /* Handle continuous lines or missing new line. */
> + if ((c + 1 < end) && printk_get_level(c)) {
> + if (header) {
> + c += 2;
> + continue;
> + }
> +
> + printk_nmi_flush_line(start, c - start);
> + start = c++;
> + header = true;
> + continue;
> + }
> +
> + header = false;
> + c++;
> + }
> +
> + /* Check if there was a partial line. Ignore pure header. */
> + if (start < end && !header) {
> + printk_nmi_flush_line(start, end - start);
> + printk_nmi_flush_line("\n", strlen("\n"));

Not introduced by this patch as it was in the original code and the
compiler is smart enough to replace strlen("\n") with 1, but still it
looks strange.