From patchwork Wed Jun 7 21:41:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gerecke, Jason" X-Patchwork-Id: 13271359 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7303BC7EE23 for ; Wed, 7 Jun 2023 21:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbjFGVlL (ORCPT ); Wed, 7 Jun 2023 17:41:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229683AbjFGVlJ (ORCPT ); Wed, 7 Jun 2023 17:41:09 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE04A1BF7; Wed, 7 Jun 2023 14:41:08 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-bacfa9fa329so5467276.0; Wed, 07 Jun 2023 14:41:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686174067; x=1688766067; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nGrbqkR+iLzazRj/5Eznoucnd0w6CLsNLWJLkMCRjmE=; b=CJjLzbCxwiqomsb+jlDBuo4XtdzT0RRbk0bBi7sk+uwEbXCEV+5211UEpBoSeK7ddD DfCZlyTN+ZHpQqT5+kTW4u3LJgyysWmHA5vfXUH65OoTNmtJVHOpq1nfuwvMq5GAw63Z NkAE61S1L1WXzRmjR9vw1TfWJboQspQaDWdrVFu1AkEIL8+WjOAxl1FDWfktTheScczs 1bhFwwc9qG1j8NWRI2OoebHdEGipSto8Fa4EuxAis629dECIUtxLFq+gy9kJMOr1o+TM sCwjQDJqtDl3VDSuSsBDI7XfY5QYGmM9fJpH/jQ6xfDB3sAi1DAaPeMQS922pCo7N7/t sIpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686174067; x=1688766067; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nGrbqkR+iLzazRj/5Eznoucnd0w6CLsNLWJLkMCRjmE=; b=anpFJG1QiZj7MKRyu1E+xMEWN4VMFg7GZGoF4lJka2404GaFExr9qBxClydIvmg/YH m8b50yFCs1j9oFiydLjmaMsAkeMNgw0Zkw0UW0gFmzooVXVFXAbTN7BRzVyuv44q59KG PTbYceChy1p/maMsKsV9qCPQ1uUKoOYrIUFZUJgfR53cWYSxoBvX8vR30jb+TyfJcx+p ovEXdSFJjqkwbSWzrs/KxeR91d/OseRy7P58+sQrfjdTJp5zKZ53231so0sufxvKlS0z lfun2SFFXlBGXh0Bwrr1DES8ZRZYSr5EdZ8Yt4/mnhd+vok9D0BCsAXETKyV43JMc1+o k9rg== X-Gm-Message-State: AC+VfDwg1XKaagQWLN5mdOjFO+7Cm8X7NLioXDH7xJKrZKTnecMqbUzh n375XO+NFqy22Q7i7TRj/LpaM+BdlsqFPg== X-Google-Smtp-Source: ACHHUZ58QT/d69mv9JhOkCKiAQq7JxdtSdfrT3g9kxfF6x5JcDQ6rcAbB2vfoB33GiVxVU+lfkOzbw== X-Received: by 2002:a25:fa09:0:b0:b9e:6d2c:ce2 with SMTP id b9-20020a25fa09000000b00b9e6d2c0ce2mr6629219ybe.46.1686174067588; Wed, 07 Jun 2023 14:41:07 -0700 (PDT) Received: from horus.lan (75-164-186-145.ptld.qwest.net. [75.164.186.145]) by smtp.gmail.com with ESMTPSA id e18-20020a258912000000b00ba7c2112650sm172714ybl.30.2023.06.07.14.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 14:41:07 -0700 (PDT) From: Jason Gerecke X-Google-Original-From: Jason Gerecke To: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Tissoires , Jiri Kosina Cc: Ping Cheng , Aaron Armstrong Skomra , Joshua Dickens , Jason Gerecke Subject: [PATCH] HID: wacom: Use ktime_t rather than int when dealing with timestamps Date: Wed, 7 Jun 2023 14:41:02 -0700 Message-ID: <20230607214102.2113-1-jason.gerecke@wacom.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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") Signed-off-by: Jason Gerecke Reviewed-by: Peter Hutterer --- drivers/hid/wacom_wac.c | 4 ++-- drivers/hid/wacom_wac.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/hid/wacom_wac.c b/drivers/hid/wacom_wac.c index 2ccf83837134..2f16e47e4b69 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; @@ -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 1a40bb8c5810..ee21bb260f22 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 {