Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Aldo Ariel Panzardo" <qwe.aldo@gmail.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v2] HID: wacom: avoid overflows in sequence number tracking
Date: Tue, 15 Sep 2026 14:27:25 +0000	[thread overview]
Message-ID: <20260915142726.236D21F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260915141621.3011011-1-qwe.aldo@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] hid: wacom: 64-bit modulo operation breaks 32-bit builds
--

commit 07dd42ab3d43fb513fdcf25e5070f8dd85e2b11c
Author: Aldo Ariel Panzardo <qwe.aldo@gmail.com>

HID: wacom: avoid overflows in sequence number tracking

This commit updates the dropped-packet calculation to use signed 64-bit 
arithmetic to prevent divide exceptions caused by 32-bit wrap-arounds. It also 
normalizes the sequence values according to the HID parser's signedness rules.

Fixes: 359673ea3a20 ("HID: wacom: Support sequence numbers smaller than 16-bit")
Cc: stable@vger.kernel.org

> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index 8feb8027be95e..ff99ba259b030 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -2542,18 +2542,34 @@ static void wacom_wac_pen_event(struct hid_device *hdev, struct hid_field *field
>  	case WACOM_HID_WD_BARRELSWITCH3:
>  		wacom_wac->hid_data.barrelswitch3 = value;
>  		return;
> -	case WACOM_HID_WD_SEQUENCENUMBER:
> -		if (wacom_wac->hid_data.sequence_number != value &&
> +	case WACOM_HID_WD_SEQUENCENUMBER: {
> +		s64 sequence_minimum = field->logical_minimum;
> +		s64 sequence_maximum = sequence_minimum < 0 ?
> +			(s64)field->logical_maximum :
> +			(s64)(u32)field->logical_maximum;
> +		s64 sequence_value = sequence_minimum < 0 ?
> +			(s64)value : (s64)(u32)value;
> +
> +		if (wacom_wac->hid_data.sequence_number != sequence_value &&
>  		    wacom_wac->hid_data.sequence_number >= 0) {
> -			int sequence_size = field->logical_maximum - field->logical_minimum + 1;
> -			int drop_count = (value - wacom_wac->hid_data.sequence_number) % sequence_size;
> -			hid_warn(hdev, "Dropped %d packets", drop_count);
> +			s64 sequence_size = sequence_maximum -
> +					    sequence_minimum + 1;
> +			s64 drop_count = sequence_value -
> +					 wacom_wac->hid_data.sequence_number;
> +
> +			drop_count %= sequence_size;

[Severity: Low]
Will this raw 64-bit modulo operation cause link-time build failures on 32-bit
architectures?

The variables drop_count and sequence_size are both s64. On 32-bit systems
(like i386 or arm32), the kernel does not link __moddi3, so using the raw
modulo operator on 64-bit integers typically results in an unresolved symbol
build failure.

Should this use a helper from <linux/math64.h>, such as div64_s64_rem(), to
safely perform the calculation while ensuring 32-bit compatibility?

> +			if (drop_count < 0)
> +				drop_count += sequence_size;
> +			hid_warn(hdev, "Dropped %lld packets",
> +				 (long long)drop_count);
>  		}

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260915141621.3011011-1-qwe.aldo@gmail.com?part=1

  reply	other threads:[~2026-09-15 14:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-15 11:14 [PATCH] HID: wacom: avoid overflows in sequence number tracking Aldo Ariel Panzardo
2026-09-15 14:16 ` [PATCH v2] " Aldo Ariel Panzardo
2026-09-15 14:27   ` sashiko-bot [this message]
2026-09-16 18:13   ` kernel test robot
2026-09-17  5:06   ` kernel test robot
2026-09-15 14:52 ` [PATCH v3] " Aldo Ariel Panzardo

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=20260915142726.236D21F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=qwe.aldo@gmail.com \
    --cc=sashiko-reviews@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