Re: [PATCH] printk_ringbuffer: Fix space_used() when blk_lpos->next overflows
From: Petr Mladek
Date: Tue Oct 27 2026 - 09:55:02 EST
On Sun 2026-10-04 15:57:55, Wang Wensheng wrote:
> Since commit 67e1b0052f6b ("printk_ringbuffer: don't needlessly wrap data
> blocks around") blk_lpos is treated as not wrapped when blk_lpos->next
> overflows to the start of data_ring. We use the indices of blk_lpos->next
> and blk_lpos->start to calculate the size of the data_block. This computes
> zero minus a small positive value, resulting in underflow and an
> unexpectedly large value. Simply using the original lpos with wrap-counts
> solves the problem.
>
> Fixes: 67e1b0052f6b ("printk_ringbuffer: don't needlessly wrap data blocks around")
> Signed-off-by: Wang Wensheng <wsw9603@xxxxxxx>
Great catch! The fix looks good.
Reviewed-by: Petr Mladek <pmladek@xxxxxxxx>
As John explained, fortunately it is not critical because the space
is used only to count the free size when copying messages from
the initial static ring buffer to a bigger one. And the bug
will happen only when there is no free space anyway.
Well, I will still queue it for 7.4 because I am going to create
another pull request anyway.
Best Regards,
Petr