RE: [PATCH v4 1/1] printk: fix zero-valued printk timestamps in early boot

From: Thomas Gleixner

Date: Tue Apr 14 2026 - 18:49:03 EST


On Mon, Apr 13 2026 at 17:58, Tim Bird wrote:
> This is a false positive warning from the compiler (see below).

This is _NOT_ a false positive warning. The compiler is absolutely
correct.

>> 34
>> 35 /* returns a nanosecond value based on early cycles */
>> 36 static inline u64 early_times_ns(void)
>> 37 {
>> 38 if (CONFIG_EARLY_CYCLES_KHZ)
>> 39 /*
>> 40 * Note: the multiply must precede the division to avoid
>> 41 * truncation and loss of resolution
>> 42 * Don't use fancier MULT/SHIFT math here. Since this is
>> 43 * static, the compiler can optimize the math operations.
>> 44 */
>> > 45 return (early_unsafe_cycles() * NS_PER_KHZ) / CONFIG_EARLY_CYCLES_KHZ;
> Based on this conditional, it's not possible for CONFIG_EARLY_CYCLES_KHZ to be zero
> on this line of code. Does GCC not catch this?
> if (0)
> x = <some expression>/0;
>
> So this is a false positive.

You clearly fail to understand how compilers work. The dead code
elimination happens _after_ the evaluation of the code and the compiler
does not care whether your initial condition evaluated to false or
not. That's documented compiler behaviour,

Whether GCC complains about it or not is completely irrelevant.

> I'll see if I can silence this warning.

Don't put much effort into it. This whole hack is going nowhere.

Thanks,

tglx