* [PATCH] Input: ff-memless - fix 180-degree force inversion from s16 negation overflow
@ 2026-11-19 17:04 Ian Rogers
0 siblings, 0 replies; only message in thread
From: Ian Rogers @ 2026-11-19 17:04 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: linux-input, linux-kernel, llvm, Elkin Cruz, Ian Rogers
In ml_combine_effects(), constant-force Y component calculation negates
fixp_cos16(i) and passes it to fixp_mult(s16 a, s16 b):
y = fixp_mult(-fixp_cos16(i), level) * gain / 0xffff;
At i = 180 degrees (direction ~ 0x8000), fixp_cos32(180) is -0x7fffffff,
and arithmetic right shift by 16 in fixp_cos16(180) produces -0x8000
(-32768). Negating -32768 in 32-bit int yields +32768, which overflows
fixp_mult()'s s16 parameter a back to -32768, inverting the Y force from
full positive (+127) to full negative (-127) right at 180 degrees.
Widen fixp_mult()'s parameters and return type from s16 to int so
+32768 scales cleanly to +0x100 without truncation overflow.
Found by enabling Clang's -Wimplicit-int-conversion-on-negation on an
x86_64 allyesconfig build, with AI coding assistant help to audit the
warning and prepare the fix. Verified with a standalone C test sweeping
0..360 degrees and Clang build; not runtime-tested on force-feedback
hardware.
Fixes: 559addc25b00 ("[media] fixp-arith: replace sin/cos table by a better precision one")
Signed-off-by: Ian Rogers <irogers@google.com>
---
drivers/input/ff-memless.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
index d1fefd1dfc0d..ae8ff19905b6 100644
--- a/drivers/input/ff-memless.c
+++ b/drivers/input/ff-memless.c
@@ -229,10 +229,10 @@ static inline s16 fixp_new16(s16 a)
return ((s32)a) >> (16 - FRAC_N);
}
-static inline s16 fixp_mult(s16 a, s16 b)
+static inline int fixp_mult(int a, int b)
{
- a = ((s32)a * 0x100) / 0x7fff;
- return ((s32)(a * b)) >> FRAC_N;
+ a = (a * 0x100) / 0x7fff;
+ return (a * b) >> FRAC_N;
}
/*
--
2.56.1.708.g77570a6a1d-goog
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-19 17:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 17:04 [PATCH] Input: ff-memless - fix 180-degree force inversion from s16 negation overflow Ian Rogers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox