Skip to content

Commit 9a6c0e2

Browse files
jigpuBenjamin Tissoires
authored andcommitted
HID: wacom: Use ktime_t rather than int when dealing with timestamps
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]>
1 parent 4c22167 commit 9a6c0e2

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
@@ -1314,7 +1314,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13141314
struct input_dev *pen_input = wacom->pen_input;
13151315
unsigned char *data = wacom->data;
13161316
int number_of_valid_frames = 0;
1317-
int time_interval = 15000000;
1317+
ktime_t time_interval = 15000000;
13181318
ktime_t time_packet_received = ktime_get();
13191319
int i;
13201320

@@ -1348,7 +1348,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13481348
if (number_of_valid_frames) {
13491349
if (wacom->hid_data.time_delayed)
13501350
time_interval = ktime_get() - wacom->hid_data.time_delayed;
1351-
time_interval /= number_of_valid_frames;
1351+
time_interval = div_u64(time_interval, number_of_valid_frames);
13521352
wacom->hid_data.time_delayed = time_packet_received;
13531353
}
13541354

@@ -1359,7 +1359,7 @@ static void wacom_intuos_pro2_bt_pen(struct wacom_wac *wacom)
13591359
bool range = frame[0] & 0x20;
13601360
bool invert = frame[0] & 0x10;
13611361
int frames_number_reversed = number_of_valid_frames - i - 1;
1362-
int event_timestamp = time_packet_received - frames_number_reversed * time_interval;
1362+
ktime_t event_timestamp = time_packet_received - frames_number_reversed * time_interval;
13631363

13641364
if (!valid)
13651365
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)