printk_ringbuffer: Fix space_used() when blk_lpos->next overflows

Since commit 67e1b0052f ("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: 67e1b0052f ("printk_ringbuffer: don't needlessly wrap data blocks around")
Signed-off-by: Wang Wensheng <[email protected]>
Reviewed-by: John Ogness <[email protected]>
Reviewed-by: Petr Mladek <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Petr Mladek <[email protected]>
This commit is contained in:
Wang Wensheng
2026-10-27 14:52:23 +01:00
committed by Petr Mladek
parent 5b212610d0
commit 2b2dc9dd35
+3 -5
View File
@@ -1237,11 +1237,9 @@ static unsigned int space_used(struct prb_data_ring *data_ring,
if (BLK_DATALESS(blk_lpos))
return 0;
if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next)) {
/* Data block does not wrap. */
return (DATA_INDEX(data_ring, blk_lpos->next) -
DATA_INDEX(data_ring, blk_lpos->begin));
}
/* Data block does not wrap. */
if (!is_blk_wrapped(data_ring, blk_lpos->begin, blk_lpos->next))
return blk_lpos->next - blk_lpos->begin;
/*
* For wrapping data blocks, the trailing (wasted) space is