Re: [PATCH v4] HID: wacom: avoid divide exception in dropped-packet calculation
From: Jiri Kosina
Date: Thu Nov 19 2026 - 15:38:33 EST
On Fri, 6 Nov 2026, Aldo Ariel Panzardo wrote:
> The dropped-packet calculation uses a modulo against sequence_size
> (logical_maximum - logical_minimum + 1). When a HID descriptor
> declares a sequence field whose logical range spans all 32-bit
> values, sequence_size wraps to zero and the modulo triggers a
> divide exception.
>
> Replace the division-based calculation with a branch that computes
> the forward distance through the sequence range directly, as
> suggested by Jason Gerecke. This keeps the existing int types and
> avoids the divide-by-zero without any 64-bit arithmetic.
>
> Fixes: 359673ea3a20 ("HID: wacom: Support sequence numbers smaller than 16-bit")
> Cc: stable@xxxxxxxxxxxxxxx
> Suggested-by: Jason Gerecke <jason.gerecke@xxxxxxxxx>
> Signed-off-by: Aldo Ariel Panzardo <qwe.aldo@xxxxxxxxx>
> ---
>
> Changes in v4:
> - Replace s64 arithmetic with a branch-based helper that computes
> the forward wrapped distance directly, as suggested by Jason Gerecke.
> Keeps sequence_number as int; no type changes needed.
Applied to hid.git#for-7.4/upstream-fixes, thanks.
--
Jiri Kosina
SUSE Labs