Skip to content

Commit d89750b

Browse files
jigpugregkh
authored andcommitted
HID: wacom: Use ktime_t rather than int when dealing with timestamps
commit 9a6c0e2 upstream. 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: 17d793f ("HID: wacom: insert timestamp to packed Bluetooth (BT) events") CC: [email protected] Signed-off-by: Jason Gerecke <[email protected]> Reviewed-by: Benjamin Tissoires <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Benjamin Tissoires <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 879e79c commit d89750b

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

drivers/hid/wacom_wac.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13091309
struct input_dev *pen_input = wacom->pen_input;
13101310
unsigned char *data = wacom->data;
13111311
int number_of_valid_frames = 0;
1312-
int time_interval = 15000000;
1312+
ktime_t time_interval = 15000000;
13131313
ktime_t time_packet_received = ktime_get();
13141314
int i;
13151315

@@ -1343,7 +1343,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13431343
if (number_of_valid_frames) {
13441344
if (wacom->hid_data.time_delayed)
13451345
time_interval = ktime_get() - wacom->hid_data.time_delayed;
1346-
time_interval /= number_of_valid_frames;
1346+
time_interval = div_u64(time_interval, number_of_valid_frames);
13471347
wacom->hid_data.time_delayed = time_packet_received;
13481348
}
13491349

@@ -1354,7 +1354,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13541354
bool range = frame[0] & 0x20;
13551355
bool invert = frame[0] & 0x10;
13561356
int frames_number_reversed = number_of_valid_frames - i - 1;
1357-
int event_timestamp = time_packet_received - frames_number_reversed * time_interval;
1357+
ktime_t event_timestamp = time_packet_received - frames_number_reversed * time_interval;
13581358

13591359
if (!valid)
13601360
continue;

drivers/hid/wacom_wac.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ struct hid_data {
324324
int ps_connected;
325325
bool pad_input_event_flag;
326326
unsigned short sequence_number;
327-
int time_delayed;
327+
ktime_t time_delayed;
328328
};
329329

330330
struct wacom_remote_data {

0 commit comments

Comments
 (0)