From: Ian Rogers <irogers@google.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Elkin Cruz <elkin@google.com>,
Ian Rogers <irogers@google.com>
Subject: [PATCH] Input: ff-memless - fix 180-degree force inversion from s16 negation overflow
Date: Thu, 19 Nov 2026 09:04:43 -0800 [thread overview]
Message-ID: <20261119170443.1513294-1-irogers@google.com> (raw)
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
reply other threads:[~2026-11-19 17:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119170443.1513294-1-irogers@google.com \
--to=irogers@google.com \
--cc=dmitry.torokhov@gmail.com \
--cc=elkin@google.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox