public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] printk: ringbuffer: fix line counting
Date: Thu, 14 Jan 2021 15:02:43 +0106	[thread overview]
Message-ID: <87r1mnei5g.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <YABDAPYB4URXtpJD@alley>

On 2021-01-14, Petr Mladek <pmladek@suse.com> wrote:
>> --- a/kernel/printk/printk_ringbuffer.c
>> +++ b/kernel/printk/printk_ringbuffer.c
>> @@ -1718,7 +1718,7 @@ static bool copy_data(struct prb_data_ring *data_ring,
>>  
>>  	/* Caller interested in the line count? */
>>  	if (line_count)
>> -		*line_count = count_lines(data, data_size);
>> +		*line_count = count_lines(data, len);
>>  
>>  	/* Caller interested in the data content? */
>>  	if (!buf || !buf_size)
>
> Another question is what line count should be returned when
> the data are copied into the buffer. In this case, the text
> might get shrunken even more.

Good point. The code could look like this:

        if (!buf || !buf_size) {
                data_size = len;
        } else {
                data_size = min_t(u16, buf_size, len);
                memcpy(&buf[0], data, data_size);
        }

        if (line_count)
                *line_count = count_lines(data, data_size);
                
        return true;

John Ogness

  reply	other threads:[~2021-01-14 13:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-13 14:42 [PATCH] printk: ringbuffer: fix line counting John Ogness
2021-01-14 13:11 ` Petr Mladek
2021-01-14 13:56   ` John Ogness [this message]
2021-01-14 14:17 ` Sergey Senozhatsky
2021-01-15 11:30 ` Petr Mladek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r1mnei5g.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox