linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gerecke <killertofu@gmail.com>
To: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	Jiri Kosina <jikos@kernel.org>
Cc: Ping Cheng <pinglinux@gmail.com>,
	Aaron Armstrong Skomra <skomra@gmail.com>,
	Joshua Dickens <Joshua@joshua-dickens.com>,
	Peter Hutterer <peter.hutterer@who-t.net>,
	Jason Gerecke <jason.gerecke@wacom.com>,
	stable@vger.kernel.org
Subject: Re: [PATCH v2] HID: wacom: Use ktime_t rather than int when dealing with timestamps
Date: Wed, 21 Jun 2023 08:18:08 -0700	[thread overview]
Message-ID: <CANRwn3R-XbfB+mP9AQ-J7R_19jLi4eS3MhswaWjL+LCEih-7pg@mail.gmail.com> (raw)
In-Reply-To: <20230608213828.2108-1-jason.gerecke@wacom.com>

Following up since no action seems to have been taken on this patch yet.

On Thu, Jun 8, 2023 at 2:38 PM Jason Gerecke <killertofu@gmail.com> wrote:
>
> Code which interacts with timestamps needs to use the ktime_t type
> returned by functions like ktime_get. The int type does not offer
> enough space to store these values, and attempting to use it is a
> recipe for problems. In this particular case, overflows would occur
> when calculating/storing timestamps leading to incorrect values being
> reported to userspace. In some cases these bad timestamps cause input
> handling in userspace to appear hung.
>
> Link: https://gitlab.freedesktop.org/libinput/libinput/-/issues/901
> Fixes: 17d793f3ed53 ("HID: wacom: insert timestamp to packed Bluetooth (BT) events")
> CC: stable@vger.kernel.org
> Signed-off-by: Jason Gerecke <jason.gerecke@wacom.com>
> ---
> v2: Use div_u64 to perform division to deal with ARC and ARM architectures
>     (as found by the kernel test robot)
>
>  drivers/hid/wacom_wac.c | 6 +++---
>  drivers/hid/wacom_wac.h | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c
> index 2ccf838371343..174bf03908d7c 100644
> --- a/drivers/hid/wacom_wac.c
> +++ b/drivers/hid/wacom_wac.c
> @@ -1314,7 +1314,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
>         struct input_dev *pen_input = wacom->pen_input;
>         unsigned char *data = wacom->data;
>         int number_of_valid_frames = 0;
> -       int time_interval = 15000000;
> +       ktime_t time_interval = 15000000;
>         ktime_t time_packet_received = ktime_get();
>         int i;
>
> @@ -1348,7 +1348,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
>         if (number_of_valid_frames) {
>                 if (wacom->hid_data.time_delayed)
>                         time_interval = ktime_get() - wacom->hid_data.time_delayed;
> -               time_interval /= number_of_valid_frames;
> +               time_interval = div_u64(time_interval, number_of_valid_frames);
>                 wacom->hid_data.time_delayed = time_packet_received;
>         }
>
> @@ -1359,7 +1359,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
>                 bool range = frame[0] & 0x20;
>                 bool invert = frame[0] & 0x10;
>                 int frames_number_reversed = number_of_valid_frames - i - 1;
> -               int event_timestamp = time_packet_received - frames_number_reversed * time_interval;
> +               ktime_t event_timestamp = time_packet_received - frames_number_reversed * time_interval;
>
>                 if (!valid)
>                         continue;
> diff --git a/drivers/hid/wacom_wac.h b/drivers/hid/wacom_wac.h
> index 1a40bb8c5810c..ee21bb260f22f 100644
> --- a/drivers/hid/wacom_wac.h
> +++ b/drivers/hid/wacom_wac.h
> @@ -324,7 +324,7 @@ struct hid_data {
>         int ps_connected;
>         bool pad_input_event_flag;
>         unsigned short sequence_number;
> -       int time_delayed;
> +       ktime_t time_delayed;
>  };
>
>  struct wacom_remote_data {
> --
> 2.41.0
>

  reply	other threads:[~2023-06-21 15:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-07 21:41 [PATCH] HID: wacom: Use ktime_t rather than int when dealing with timestamps Jason Gerecke
2023-06-08  2:51 ` Peter Hutterer
2023-06-08 13:35 ` kernel test robot
2023-06-08 14:26 ` kernel test robot
2023-06-08 21:38 ` [PATCH v2] " Jason Gerecke
2023-06-21 15:18   ` Jason Gerecke [this message]
2023-06-21 16:04     ` Benjamin Tissoires
2023-06-21 20:52       ` Jason Gerecke
2023-06-26 14:54   ` bentiss

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=CANRwn3R-XbfB+mP9AQ-J7R_19jLi4eS3MhswaWjL+LCEih-7pg@mail.gmail.com \
    --to=killertofu@gmail.com \
    --cc=Joshua@joshua-dickens.com \
    --cc=benjamin.tissoires@redhat.com \
    --cc=jason.gerecke@wacom.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.hutterer@who-t.net \
    --cc=pinglinux@gmail.com \
    --cc=skomra@gmail.com \
    --cc=stable@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).