]> Gentwo Git Trees - linux/.git/commit
printk_ringbuffer: Create a helper function to decide whether more space is needed
authorPetr Mladek <pmladek@suse.com>
Fri, 7 Nov 2025 19:47:20 +0000 (20:47 +0100)
committerPetr Mladek <pmladek@suse.com>
Mon, 10 Nov 2025 12:09:43 +0000 (13:09 +0100)
commit394aa576c0b783ae728d87ed98fe4f1831dfd720
treeb4dcba6f80ddbe45e9780e106b206c1f2ce9f058
parentcc3bad11de6e0d6012460487903e7167d3e73957
printk_ringbuffer: Create a helper function to decide whether more space is needed

The decision whether some more space is needed is tricky in the printk
ring buffer code:

  1. The given lpos values might overflow. A subtraction must be used
     instead of a simple "lower than" check.

  2. Another CPU might reuse the space in the mean time. It can be
     detected when the subtraction is bigger than DATA_SIZE(data_ring).

  3. There is exactly enough space when the result of the subtraction
     is zero. But more space is needed when the result is exactly
     DATA_SIZE(data_ring).

Add a helper function to make sure that the check is done correctly
in all situations. Also it helps to make the code consistent and
better documented.

Suggested-by: John Ogness <john.ogness@linutronix.de>
Link: https://lore.kernel.org/r/87tsz7iea2.fsf@jogness.linutronix.de
Reviewed-by: John Ogness <john.ogness@linutronix.de>
Link: https://patch.msgid.link/20251107194720.1231457-3-pmladek@suse.com
[pmladek@suse.com: Updated wording as suggested by John]
Signed-off-by: Petr Mladek <pmladek@suse.com>
kernel/printk/printk_ringbuffer.c