Messages in this thread | | | From | John Ogness <> | Subject | Re: [PATCH] printk: ringbuffer: fix line counting | Date | Thu, 14 Jan 2021 15:02:43 +0106 |
| |
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
| |