From 8df412aa1715bcbf31276e8ac55047a18b48fdf9 Mon Sep 17 00:00:00 2001
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Mon, 20 Nov 2023 15:06:57 +0100
Subject: [PATCH 151/184] printk/ringbuffer: Extend the sequence number
 properly on 32bit.

The sequence number on 32bit platform is extendend to a full 64bit
variable from a 32bit value and a 64bit previous record.
The formala as-is is okay but it relies on the right part to be negative
which is not the case if the result is a unsigned variable.

Cast the result to a signed variable.

Reported-by: Francesco Dolcini <francesco@dolcini.it>
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202311171611.78d41dbe-oliver.sang@intel.com
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202311161555.3ee16fc9-oliver.sang@intel.com
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 kernel/printk/printk_ringbuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
index a949d02fbd17..2b2a85222d19 100644
--- a/kernel/printk/printk_ringbuffer.c
+++ b/kernel/printk/printk_ringbuffer.c
@@ -1477,7 +1477,7 @@ static inline u64 __ulseq_to_u64seq(u32 ulseq)
 	 * sequence. It needs to be expanded to 64bit. Get the first sequence
 	 * number from the ringbuffer and fold it.
 	 */
-	seq = rb_first_seq - ((u32)rb_first_seq - ulseq);
+	seq = rb_first_seq - ((s32)((u32)rb_first_seq - ulseq));
 
 	return seq;
 }
-- 
2.34.1

