Re: [PATCH] selftests: timers: Fix valid-adjtimex signed left-shift undefined behavior

From: Shuah Khan
Date: Thu Apr 11 2024 - 17:01:54 EST


On 4/9/24 14:22, John Stultz wrote:
So, the struct adjtimex freq field takes a signed value who's
units are in shifted (<<16) parts-per-million.

Unfortunately for negative adjustments, the straightforward use
of:
freq = ppm<<16
will trip undefined behavior warnings with clang:

valid-adjtimex.c:66:6: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
-499<<16,
~~~~^
valid-adjtimex.c:67:6: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
-450<<16,
~~~~^
...

So fix our use of shifting negative values in the valid-adjtimex
test case to use multiply by (1<<16) to avoid this.

The patch also aligns the values a bit to make it look nicer.

Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: Stephen Boyd <sboyd@xxxxxxxxxx>
Cc: Anna-Maria Behnsen <anna-maria@xxxxxxxxxxxxx>
Cc: Frederic Weisbecker <frederic@xxxxxxxxxx>
Cc: Shuah Khan <shuah@xxxxxxxxxx>
Cc: Nathan Chancellor <nathan@xxxxxxxxxx>
Cc: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>
Cc: Lee Jones <joneslee@xxxxxxxxxx>
Cc: Muhammad Usama Anjum <usama.anjum@xxxxxxxxxxxxx>
Cc: linux-kselftest@xxxxxxxxxxxxxxx
Reported-by: Lee Jones <joneslee@xxxxxxxxxx>
Reported-by: Muhammad Usama Anjum <usama.anjum@xxxxxxxxxxxxx>
Link: https://lore.kernel.org/lkml/0c6d4f0d-2064-4444-986b-1d1ed782135f@xxxxxxxxxxxxx/
Signed-off-by: John Stultz <jstultz@xxxxxxxxxx>
---

Applied to linux-kselftest next for Linux6.10-rc1.

thanks,
-- Shuah