lkml.org 
[lkml]   [2021]   [Jan]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] printk: ringbuffer: fix line counting
Date
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

\
 
 \ /
  Last update: 2021-01-14 14:59    [W:0.069 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site