From patchwork Sun Oct 8 09:54:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412672 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 98A7FE95A8E for ; Sun, 8 Oct 2023 09:55:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344586AbjJHJzw (ORCPT ); Sun, 8 Oct 2023 05:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344569AbjJHJzv (ORCPT ); Sun, 8 Oct 2023 05:55:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6E05C5 for ; Sun, 8 Oct 2023 02:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iiZJPTeCOBMQkn0nOhKSU0XyqdnlUqKu4LlFA7D/2NA=; b=a8ASCYZ9YUMP1ITnSs+TGuO/Uk3R1uwJh30OIkOpvTiJ5ONqodofuR+luTBlR6OlwJ2iK5 ba4N18+dksGUGV5snT0ST1VeFnhW1I9q7Mz229DrrPrkhCspUYCPlAMfVGg675QsITlnI6 WIwD+Cv0QDrr4CN08A0XSqymOLTIqaI= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-50-TdWQR5FeOye-K8I6rFBtxA-1; Sun, 08 Oct 2023 05:55:01 -0400 X-MC-Unique: TdWQR5FeOye-K8I6rFBtxA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E556429AA2F0; Sun, 8 Oct 2023 09:55:00 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A8BCC15BB8; Sun, 8 Oct 2023 09:54:59 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 01/14] HID: logitech-hidpp: Revert "Don't restart communication if not necessary" Date: Sun, 8 Oct 2023 11:54:44 +0200 Message-ID: <20231008095458.8926-2-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Commit 91cf9a98ae41 ("HID: logitech-hidpp: make .probe usbhid capable") makes hidpp_probe() first call hid_hw_start(hdev, 0) to allow IO without connecting any hid subdrivers (hid-input, hidraw). This is done to allow to retrieve the device's name and serial number and store these in hdev->name and hdev->uniq. Then later on IO is stopped and started again with hid_hw_start(hdev, HID_CONNECT_DEFAULT) connecting hid-input and hidraw after the name and serial number have been setup. Commit 498ba2069035 ("HID: logitech-hidpp: Don't restart communication if not necessary") changed the probe() code to only do the start with a 0 connect-mask + restart later for unifying devices. But for non unifying devices hdev->name and hdev->uniq are updated too. So this change re-introduces the problem for which the start with a 0 connect-mask + restart later behavior was introduced. Revert the change to limit the restart behavior to unifying devices to fix hdev->name changing after userspace facing devices have already been registered. Fixes: 498ba2069035 ("HID: logitech-hidpp: Don't restart communication if not necessary") Cc: Bastien Nocera Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index a209d51bd247..09f7723eaabe 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4394,7 +4394,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) bool connected; unsigned int connect_mask = HID_CONNECT_DEFAULT; struct hidpp_ff_private_data data; - bool will_restart = false; /* report_fixup needs drvdata to be set before we call hid_parse */ hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL); @@ -4445,10 +4444,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } - if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT || - hidpp->quirks & HIDPP_QUIRK_UNIFYING) - will_restart = true; - INIT_WORK(&hidpp->work, delayed_work_cb); mutex_init(&hidpp->send_mutex); init_waitqueue_head(&hidpp->wait); @@ -4463,7 +4458,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) * Plain USB connections need to actually call start and open * on the transport driver to allow incoming data. */ - ret = hid_hw_start(hdev, will_restart ? 0 : connect_mask); + ret = hid_hw_start(hdev, 0); if (ret) { hid_err(hdev, "hw start failed\n"); goto hid_hw_start_fail; @@ -4502,7 +4497,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hidpp->wireless_feature_index = 0; else if (ret) goto hid_hw_init_fail; - ret = 0; } if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { @@ -4518,21 +4512,19 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) schedule_work(&hidpp->work); flush_work(&hidpp->work); - if (will_restart) { - /* Reset the HID node state */ - hid_device_io_stop(hdev); - hid_hw_close(hdev); - hid_hw_stop(hdev); + /* Reset the HID node state */ + hid_device_io_stop(hdev); + hid_hw_close(hdev); + hid_hw_stop(hdev); - if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT) - connect_mask &= ~HID_CONNECT_HIDINPUT; + if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT) + connect_mask &= ~HID_CONNECT_HIDINPUT; - /* Now export the actual inputs and hidraw nodes to the world */ - ret = hid_hw_start(hdev, connect_mask); - if (ret) { - hid_err(hdev, "%s:hid_hw_start returned error\n", __func__); - goto hid_hw_start_fail; - } + /* Now export the actual inputs and hidraw nodes to the world */ + ret = hid_hw_start(hdev, connect_mask); + if (ret) { + hid_err(hdev, "%s:hid_hw_start returned error\n", __func__); + goto hid_hw_start_fail; } if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { From patchwork Sun Oct 8 09:54:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412671 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 5EA73E95A67 for ; Sun, 8 Oct 2023 09:55:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343601AbjJHJzv (ORCPT ); Sun, 8 Oct 2023 05:55:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343527AbjJHJzv (ORCPT ); Sun, 8 Oct 2023 05:55:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BBE8B6 for ; Sun, 8 Oct 2023 02:55:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758904; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pLEh9LlSm/GpY5t9FQz8qXk8MjAt4GSngbLRwAGPRpo=; b=fKa5jEn4mUOWEYGwZ8CQQ/KXtv0IcrmYY2jWLUZrAOVcUv9sGucJP01jh95lFOjooYPNrE /CMaNrMf40iW+x3IdNzHTgCyl1WowFM0/WkPIFR2IfjDtY98kRatXdh+Jq2ROPMNhAMLxp eP5kBUCbknqs4ZZom9BoBXHhZa/lGoc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-JxMOvfGvM4u0-OsgGxj3Kg-1; Sun, 08 Oct 2023 05:55:02 -0400 X-MC-Unique: JxMOvfGvM4u0-OsgGxj3Kg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0A7CE8007A4; Sun, 8 Oct 2023 09:55:02 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23C00C15BB8; Sun, 8 Oct 2023 09:55:01 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 02/14] HID: logitech-hidpp: Move hidpp_overwrite_name() to before connect check Date: Sun, 8 Oct 2023 11:54:45 +0200 Message-ID: <20231008095458.8926-3-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Move the hidpp_overwrite_name() call to before the connect check, this puts it at the same place in the probe() order as hidpp_serial_init() which seems more logical. This should not make a difference since this is in the non-unifying path and only unifying devices can be probed in non-connected state. This is a preparation patch for moving the connect check to after restarting IO, in case we miss a connect packet coming in while IO is disabled during the restart. Doing this before the connect check requires dropping the protocol version check since protocol_major is not set yet now. Instead this relies on hidpp_root_get_feature(HIDPP_PAGE_GET_DEVICE_NAME_TYPE) failing on older devices, just like how hidpp_get_serial() relies on hidpp_root_get_feature(HIDPP_PAGE_DEVICE_INFORMATION) failing on older devices. So this again makes the code more consistent. Also stop printing an error on failure now, since with the proto version check gone failures are expected to happen on older devices. Signed-off-by: Hans de Goede --- Note: The weird unbalanced curly braces in the "else { ... }" go away in the next patch in the series. --- drivers/hid/hid-logitech-hidpp.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 09f7723eaabe..b1965b91c5bb 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4136,19 +4136,12 @@ static void hidpp_overwrite_name(struct hid_device *hdev) struct hidpp_device *hidpp = hid_get_drvdata(hdev); char *name; - if (hidpp->protocol_major < 2) - return; - name = hidpp_get_device_name(hidpp); - - if (!name) { - hid_err(hdev, "unable to retrieve the name of the device"); - } else { + if (name) { dbg_hid("HID++: Got name: %s\n", name); snprintf(hdev->name, sizeof(hdev->name), "%s", name); + kfree(name); } - - kfree(name); } static int hidpp_input_open(struct input_dev *dev) @@ -4476,8 +4469,12 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) if (hidpp->quirks & HIDPP_QUIRK_UNIFYING) hidpp_unifying_init(hidpp); - else if (hid_is_usb(hidpp->hid_dev)) - hidpp_serial_init(hidpp); + else { + if (hid_is_usb(hidpp->hid_dev)) + hidpp_serial_init(hidpp); + + hidpp_overwrite_name(hdev); + } connected = hidpp_root_get_protocol_version(hidpp) == 0; atomic_set(&hidpp->connected, connected); @@ -4487,8 +4484,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hid_err(hdev, "Device not connected"); goto hid_hw_init_fail; } - - hidpp_overwrite_name(hdev); } if (connected && hidpp->protocol_major >= 2) { From patchwork Sun Oct 8 09:54:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412683 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 BDB1FE95A92 for ; Sun, 8 Oct 2023 09:56:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344594AbjJHJ4n (ORCPT ); Sun, 8 Oct 2023 05:56:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35638 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344611AbjJHJ4l (ORCPT ); Sun, 8 Oct 2023 05:56:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 015AAE4 for ; Sun, 8 Oct 2023 02:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758917; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oQvLg+JPXEv8o5z4dY3wQ/bz64J6fDlwx2H8YDJFR38=; b=aAXtZViZ+nAMXeNZttzM+/lzU5EU4w8iPYa31rm5D9LikqjIasmWWBbG0jOcnZgbSHKKdt InIzOAmx7toYjYcC+Zl1VveGSIRa/mpLbrkQ82meZJ0JZP+mMtv+r0CWOwfgdPCBRI1ECc ETfwlAUj+udf4Sn+FYb9vJf6zOIGDwM= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-483-DEganfwRPqOU7dwxS9IR3w-1; Sun, 08 Oct 2023 05:55:03 -0400 X-MC-Unique: DEganfwRPqOU7dwxS9IR3w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 256C029A9CB2; Sun, 8 Oct 2023 09:55:03 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C7A5C158BA; Sun, 8 Oct 2023 09:55:02 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 03/14] HID: logitech-hidpp: Add hidpp_non_unifying_init() helper Date: Sun, 8 Oct 2023 11:54:46 +0200 Message-ID: <20231008095458.8926-4-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Turn hidpp_overwrite_name() into a hidpp_non_unifying_init() helper which takes care of setting both the name and the serial for non unifying devices. This mirrors the hidpp_unifying_init() helper for unifying devices. Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index b1965b91c5bb..e4dbbdf46b97 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4131,11 +4131,16 @@ static int hidpp_initialize_battery(struct hidpp_device *hidpp) return ret; } -static void hidpp_overwrite_name(struct hid_device *hdev) +/* Get name + serial for USB and Bluetooth HID++ devices */ +static void hidpp_non_unifying_init(struct hidpp_device *hidpp) { - struct hidpp_device *hidpp = hid_get_drvdata(hdev); + struct hid_device *hdev = hidpp->hid_dev; char *name; + /* Bluetooth devices already have their serialnr set */ + if (hid_is_usb(hdev)) + hidpp_serial_init(hidpp); + name = hidpp_get_device_name(hidpp); if (name) { dbg_hid("HID++: Got name: %s\n", name); @@ -4467,14 +4472,11 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) /* Allow incoming packets */ hid_device_io_start(hdev); + /* Get name + serial, store in hdev->name + hdev->uniq */ if (hidpp->quirks & HIDPP_QUIRK_UNIFYING) hidpp_unifying_init(hidpp); - else { - if (hid_is_usb(hidpp->hid_dev)) - hidpp_serial_init(hidpp); - - hidpp_overwrite_name(hdev); - } + else + hidpp_non_unifying_init(hidpp); connected = hidpp_root_get_protocol_version(hidpp) == 0; atomic_set(&hidpp->connected, connected); From patchwork Sun Oct 8 09:54:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412673 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 10A7AE95A82 for ; Sun, 8 Oct 2023 09:55:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344569AbjJHJzx (ORCPT ); Sun, 8 Oct 2023 05:55:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343527AbjJHJzv (ORCPT ); Sun, 8 Oct 2023 05:55:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AD6AB9 for ; Sun, 8 Oct 2023 02:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758908; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vyKbtYyY6iouGTEtEYqX+tlsTSdPpCWEROB3g6eFfS4=; b=TpkdmC9+NJa4CnSYnGpeB4fB5XCnkJWuMX5dFiyEq5+htlYSTLhg33fTuT8+Y22wKJQVxt 46PIcf4Os2DsTjNwiThQa+lI7ZHT+CSVAR04cKz9LqNNnIgW3bcyvugWuDSrvlg4vJg86u f+YKR4bVWuO+AW7dGgHjD2NLeaHTDac= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-193-ZDsapweuN3Ox0U3mvnczvA-1; Sun, 08 Oct 2023 05:55:05 -0400 X-MC-Unique: ZDsapweuN3Ox0U3mvnczvA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 404638039C8; Sun, 8 Oct 2023 09:55:04 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57C24C15BB8; Sun, 8 Oct 2023 09:55:03 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 04/14] HID: logitech-hidpp: Remove connected check for non-unifying devices Date: Sun, 8 Oct 2023 11:54:47 +0200 Message-ID: <20231008095458.8926-5-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Non-unifying devices (USB, Bluetooth) are always connected during probe(), remove the unnecessary connected check. This is a preparation patch for moving querying if the device is connected to after restarting IO, in case we miss a connect packet coming in while IO is disabled during the restart. Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index e4dbbdf46b97..82f9723154f1 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4480,13 +4480,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) connected = hidpp_root_get_protocol_version(hidpp) == 0; atomic_set(&hidpp->connected, connected); - if (!(hidpp->quirks & HIDPP_QUIRK_UNIFYING)) { - if (!connected) { - ret = -ENODEV; - hid_err(hdev, "Device not connected"); - goto hid_hw_init_fail; - } - } if (connected && hidpp->protocol_major >= 2) { ret = hidpp_set_wireless_feature_index(hidpp); From patchwork Sun Oct 8 09:54:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412675 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 46068E95A82 for ; Sun, 8 Oct 2023 09:56:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344592AbjJHJ4A (ORCPT ); Sun, 8 Oct 2023 05:56:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344580AbjJHJz7 (ORCPT ); Sun, 8 Oct 2023 05:55:59 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2BEFCA for ; Sun, 8 Oct 2023 02:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nYZDKtSlXnQ1FRRsCoZLuiE/XL41iqdTU3dUtClMnq0=; b=RylFfRzirCNrIYtY/MEjf9j0LjEWm62d/+ozAtP5dub1WtEa8qPXfdf2AjrUe3FV0lFGQ/ pVAwygloZjD/f3wXexDeQyZjKveUfWh3b2RqIY02b2MkSEQo5kNE27UhAfS63b3dsox97A MNxG8eAPDPq9svReHmHF5xeWm4glDFk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-246-5E6pH1xxOSW5nFgdQNZm9g-1; Sun, 08 Oct 2023 05:55:05 -0400 X-MC-Unique: 5E6pH1xxOSW5nFgdQNZm9g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B3B51C0634C; Sun, 8 Oct 2023 09:55:05 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72558C15BB8; Sun, 8 Oct 2023 09:55:04 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 05/14] HID: logitech-hidpp: Move get_wireless_feature_index() check to hidpp_connect_event() Date: Sun, 8 Oct 2023 11:54:48 +0200 Message-ID: <20231008095458.8926-6-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Calling get_wireless_feature_index() from probe() causes the wireless_feature_index to only get set for unifying devices which are already connected at probe() time. It does not get set for devices which connect later. Fix this by moving get_wireless_feature_index() to hidpp_connect_event(), this does not make a difference for devices connected at probe() since probe() will queue the hidpp_connect_event() for those at probe time. Fixes: 0da0a63b7cba ("HID: logitech-hidpp: Support WirelessDeviceStatus connect events") Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 82f9723154f1..fe4c4871ea5c 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1835,15 +1835,14 @@ static int hidpp_battery_get_property(struct power_supply *psy, /* -------------------------------------------------------------------------- */ #define HIDPP_PAGE_WIRELESS_DEVICE_STATUS 0x1d4b -static int hidpp_set_wireless_feature_index(struct hidpp_device *hidpp) +static int hidpp_get_wireless_feature_index(struct hidpp_device *hidpp, u8 *feature_index) { u8 feature_type; int ret; ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_WIRELESS_DEVICE_STATUS, - &hidpp->wireless_feature_index, - &feature_type); + feature_index, &feature_type); return ret; } @@ -4247,6 +4246,13 @@ static void hidpp_connect_event(struct hidpp_device *hidpp) } } + if (hidpp->protocol_major >= 2) { + u8 feature_index; + + if (!hidpp_get_wireless_feature_index(hidpp, &feature_index)) + hidpp->wireless_feature_index = feature_index; + } + if (hidpp->name == hdev->name && hidpp->protocol_major >= 2) { name = hidpp_get_device_name(hidpp); if (name) { @@ -4481,14 +4487,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) connected = hidpp_root_get_protocol_version(hidpp) == 0; atomic_set(&hidpp->connected, connected); - if (connected && hidpp->protocol_major >= 2) { - ret = hidpp_set_wireless_feature_index(hidpp); - if (ret == -ENOENT) - hidpp->wireless_feature_index = 0; - else if (ret) - goto hid_hw_init_fail; - } - if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { ret = wtp_get_config(hidpp); if (ret) From patchwork Sun Oct 8 09:54:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412679 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 5EC6BE95A93 for ; Sun, 8 Oct 2023 09:56:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344604AbjJHJ4l (ORCPT ); Sun, 8 Oct 2023 05:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344601AbjJHJ4j (ORCPT ); Sun, 8 Oct 2023 05:56:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF0A1D6 for ; Sun, 8 Oct 2023 02:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m5Wx+p0kRhQubpyIx6inGC9BRA9xSG1uoLrE4lbSn08=; b=G3I2IT0yVOMXDSd3OyiE9bAE61Wv0zIBm7BfcXEcx0AP7kwqb5ifEDwXkfb0/klnu8OK+R BCR8aZlreBxFFoP3Nbj1NcMoJTv7ocz3mUv/BKHdejjciE+DGCW/YkvIgDp3Jh9nJkrnxr wOcBMuom8VtkHCsl04NQSryreSEiR4g= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-170-TOKu0S9EMgGB2ACJ6g7qMg-1; Sun, 08 Oct 2023 05:55:06 -0400 X-MC-Unique: TOKu0S9EMgGB2ACJ6g7qMg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7401A101A550; Sun, 8 Oct 2023 09:55:06 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D5CEC15BB8; Sun, 8 Oct 2023 09:55:05 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 06/14] HID: logitech-hidpp: Remove wtp_get_config() call from probe() Date: Sun, 8 Oct 2023 11:54:49 +0200 Message-ID: <20231008095458.8926-7-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org For WTP devices which start disconnected (paired with the unifying receiver, but not connected atm) hidpp_connect_event() takes care of calling wtp_get_config() when the device later connects. There is no need to have a separate code path for WTP devices which are connected at probe() time, these can use the same code-path since probe() will queue the hidpp_connect_event() for those at probe time. Drop the unnecessary wtp_get_config() call from probe(). This is a preparation patch for moving the connect check to after restarting IO, in case we miss a connect packet coming in while IO is disabled during the restart. Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index fe4c4871ea5c..d7375885b0c7 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4487,11 +4487,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) connected = hidpp_root_get_protocol_version(hidpp) == 0; atomic_set(&hidpp->connected, connected); - if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) { - ret = wtp_get_config(hidpp); - if (ret) - goto hid_hw_init_fail; - } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { + if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { ret = g920_get_config(hidpp, &data); if (ret) goto hid_hw_init_fail; From patchwork Sun Oct 8 09:54:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412681 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 1CBD6E95A82 for ; Sun, 8 Oct 2023 09:56:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344601AbjJHJ4m (ORCPT ); Sun, 8 Oct 2023 05:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344595AbjJHJ4j (ORCPT ); Sun, 8 Oct 2023 05:56:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30ACECF for ; Sun, 8 Oct 2023 02:55:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VVfUSopk5t12LKrHUthPZUWOI01Jqu8XjIzmyBdvUWs=; b=bagXua9QI+OEqZpaDnBnEFnuMRiBGapajtz1gHXvsJmpm9xqQkHsgj4pBr1ngtvf7Ss7Th Rm8kBbECozJx7SykZEcoKrVULbARWBU6UD4sgQrya1Lmbpm3UgBt/7v1bTZKurStw4suPi gGtk0GTy54oS7hQDZoLYHZq+lD+LxH0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-542-Bn25gETeO1-aTEJhyY6Syg-1; Sun, 08 Oct 2023 05:55:07 -0400 X-MC-Unique: Bn25gETeO1-aTEJhyY6Syg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8DAE18030D4; Sun, 8 Oct 2023 09:55:07 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id A67FAC15BB8; Sun, 8 Oct 2023 09:55:06 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 07/14] HID: logitech-hidpp: Remove connected check for g920_get_config() call Date: Sun, 8 Oct 2023 11:54:50 +0200 Message-ID: <20231008095458.8926-8-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The G920 is a wired USB device, so it is always connected, remove the unnecessary connected check. This is a preparation patch for moving the connect check to after restarting IO, in case we miss a connect packet coming in while IO is disabled during the restart. Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index d7375885b0c7..bbb1c6d8ccc9 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4487,7 +4487,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) connected = hidpp_root_get_protocol_version(hidpp) == 0; atomic_set(&hidpp->connected, connected); - if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { + if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { ret = g920_get_config(hidpp, &data); if (ret) goto hid_hw_init_fail; From patchwork Sun Oct 8 09:54:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412677 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 97D77E95A67 for ; Sun, 8 Oct 2023 09:56:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344559AbjJHJ4j (ORCPT ); Sun, 8 Oct 2023 05:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344587AbjJHJ4i (ORCPT ); Sun, 8 Oct 2023 05:56:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4147BDE for ; Sun, 8 Oct 2023 02:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758915; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kjt1ZM5ZIEDUJZJunDTsgtms04Zn5kENYo6Vh2F0W6U=; b=GZP4YouE7BT6FuyhHOdBHGO5OY4GdVB1i4yV9QjEWiqr16uKdyv6Hc4TLjrZ4cFYF/uzw+ ZIrLw4qdytYQyv+oGRIaqDlUb1UW9qGmmH4uC8uke9giM/c4z+xIaXz4UEcrhQRd+b2whm UCCQY01+oizPTlbXAvvMEOkI6Dp99Qw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-145-Yc1Qru95NySj6akQNb1REg-1; Sun, 08 Oct 2023 05:55:09 -0400 X-MC-Unique: Yc1Qru95NySj6akQNb1REg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A59361C0634C; Sun, 8 Oct 2023 09:55:08 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF245C15BB8; Sun, 8 Oct 2023 09:55:07 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 08/14] HID: logitech-hidpp: Add a hidpp_connect_and_start() helper Date: Sun, 8 Oct 2023 11:54:51 +0200 Message-ID: <20231008095458.8926-9-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Add a helper to take the 3 hid_hw_start() + hid_hw_open() + hid_device_io_start() steps which are necessary to be able to talk to the hw. This is a preparation patch for moving the connect check to after restarting IO, in case we miss a connect packet coming in while IO is disabled during the restart. Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 40 ++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index bbb1c6d8ccc9..45b371e7b9ee 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4391,6 +4391,29 @@ static bool hidpp_application_equals(struct hid_device *hdev, return report && report->application == application; } +static int hidpp_connect_and_start(struct hidpp_device *hidpp, unsigned int connect_mask) +{ + struct hid_device *hdev = hidpp->hid_dev; + int ret; + + ret = hid_hw_start(hdev, connect_mask); + if (ret) { + hid_err(hdev, "hw start failed: %d\n", ret); + return ret; + } + + ret = hid_hw_open(hdev); + if (ret) { + hid_err(hdev, "hw open failed: %d\n", ret); + hid_hw_stop(hdev); + return ret; + } + + /* Allow incoming packets */ + hid_device_io_start(hdev); + return 0; +} + static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct hidpp_device *hidpp; @@ -4462,21 +4485,9 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) * Plain USB connections need to actually call start and open * on the transport driver to allow incoming data. */ - ret = hid_hw_start(hdev, 0); - if (ret) { - hid_err(hdev, "hw start failed\n"); + ret = hidpp_connect_and_start(hidpp, 0); + if (ret) goto hid_hw_start_fail; - } - - ret = hid_hw_open(hdev); - if (ret < 0) { - dev_err(&hdev->dev, "%s:hid_hw_open returned error:%d\n", - __func__, ret); - goto hid_hw_open_fail; - } - - /* Allow incoming packets */ - hid_device_io_start(hdev); /* Get name + serial, store in hdev->name + hdev->uniq */ if (hidpp->quirks & HIDPP_QUIRK_UNIFYING) @@ -4523,7 +4534,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hid_hw_init_fail: hid_hw_close(hdev); -hid_hw_open_fail: hid_hw_stop(hdev); hid_hw_start_fail: sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); From patchwork Sun Oct 8 09:54:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412682 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 287ACE95A67 for ; Sun, 8 Oct 2023 09:56:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344595AbjJHJ4m (ORCPT ); Sun, 8 Oct 2023 05:56:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344594AbjJHJ4j (ORCPT ); Sun, 8 Oct 2023 05:56:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C61FDB for ; Sun, 8 Oct 2023 02:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758915; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KJq/Ec7wnLFV4pTAzO90EYK/ZY+gdtXPDKi7fGxTIbI=; b=i1D2zJVes1OLz7Ygk1EV80HQr4APFt+zKtzfEcGt/rpH1u86Si6MTyVMqy3UTAlgApRhOe C3glC51ys5LKDf1DyhI6I7NH4advBDRa8rGbqsRzadnJdWKgKOiVPYBryF6MfGD9CE4u4v bVIOvq4vdps2eNoEUmy4p8cUE7raiN4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-520-CjQCd6YHMiOXQXxUortCWQ-1; Sun, 08 Oct 2023 05:55:10 -0400 X-MC-Unique: CjQCd6YHMiOXQXxUortCWQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DB7EF185A78E; Sun, 8 Oct 2023 09:55:09 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7803C15BB8; Sun, 8 Oct 2023 09:55:08 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org, Benjamin Tissoires Subject: [PATCH v2 09/14] HID: logitech-hidpp: Move the connected check to after restarting IO Date: Sun, 8 Oct 2023 11:54:52 +0200 Message-ID: <20231008095458.8926-10-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org While restarting IO incoming packets get disabled by calling hid_device_io_stop() and they do not get re-enabled again until the hid-core enables the when probe() is done. This leaves a window where connect events may get lost, causing hidpp to not be aware that a device has (dis)connected. To fix this fully restart IO using the new hidpp_connect_and_start() helper and move the connected check to after restarting IO. This requires calling hid_hw_close() at the end of probe() to balance the open() now done on restart. Reported-by: Benjamin Tissoires Closes: https://lore.kernel.org/linux-input/zjiang3fdy4o7r3daupwpnx6zesmeeerldpx5fno2adzialpre@cdp7tq4araww/ Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 33 ++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 45b371e7b9ee..ff834f905eda 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4482,8 +4482,10 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hdev->name); /* - * Plain USB connections need to actually call start and open - * on the transport driver to allow incoming data. + * First call hid_hw_start(hdev, 0) to allow IO without connecting any + * hid subdrivers (hid-input, hidraw). This allows retrieving the dev's + * name and serial number and store these in hdev->name and hdev->uniq, + * before the hid-input and hidraw drivers expose these to userspace. */ ret = hidpp_connect_and_start(hidpp, 0); if (ret) @@ -4495,18 +4497,12 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) else hidpp_non_unifying_init(hidpp); - connected = hidpp_root_get_protocol_version(hidpp) == 0; - atomic_set(&hidpp->connected, connected); - if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { ret = g920_get_config(hidpp, &data); if (ret) goto hid_hw_init_fail; } - schedule_work(&hidpp->work); - flush_work(&hidpp->work); - /* Reset the HID node state */ hid_device_io_stop(hdev); hid_hw_close(hdev); @@ -4516,11 +4512,19 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) connect_mask &= ~HID_CONNECT_HIDINPUT; /* Now export the actual inputs and hidraw nodes to the world */ - ret = hid_hw_start(hdev, connect_mask); - if (ret) { - hid_err(hdev, "%s:hid_hw_start returned error\n", __func__); + ret = hidpp_connect_and_start(hidpp, connect_mask); + if (ret) goto hid_hw_start_fail; - } + + /* + * Now that incoming packets are enabled and will not be disabled + * again (which may cause missing packets) check the connected state + * of the device. + */ + connected = hidpp_root_get_protocol_version(hidpp) == 0; + atomic_set(&hidpp->connected, connected); + schedule_work(&hidpp->work); + flush_work(&hidpp->work); if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { ret = hidpp_ff_init(hidpp, &data); @@ -4530,6 +4534,11 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) ret); } + /* + * This relies on logi_dj_ll_close() being a no-op so that DJ connection + * events will still be received. + */ + hid_hw_close(hdev); return ret; hid_hw_init_fail: From patchwork Sun Oct 8 09:54:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412678 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 A9CBAE95A8F for ; Sun, 8 Oct 2023 09:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344609AbjJHJ4l (ORCPT ); Sun, 8 Oct 2023 05:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35620 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344604AbjJHJ4j (ORCPT ); Sun, 8 Oct 2023 05:56:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AC97D8 for ; Sun, 8 Oct 2023 02:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QmU2dB37nwoWWj81lKTV6Gm1hvKlJIRjrZ/iBPPqOcY=; b=T074PkdA+3kybgLOvC6ci//+66oXroYs+Qp6TO1CbI4FyLphsQJu9luw+ukrjkEo/God8Y sJen2uZYAwsbqskTE36RGPQXBsKIdplxM0lm5J701ekvU2BXySFOGxkbp88ZLpkAhw+cO6 U4s5qATiDxiS9ZS4cOVSVyIopJI1C0A= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-607-Kh5035ZDN6K8JIc463ek7Q-1; Sun, 08 Oct 2023 05:55:11 -0400 X-MC-Unique: Kh5035ZDN6K8JIc463ek7Q-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F356229AB412; Sun, 8 Oct 2023 09:55:10 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1906DC15BB8; Sun, 8 Oct 2023 09:55:09 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 10/14] HID: logitech-hidpp: Move g920_get_config() to just before hidpp_ff_init() Date: Sun, 8 Oct 2023 11:54:53 +0200 Message-ID: <20231008095458.8926-11-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The data retrieved by g920_get_config() is onyl used by hidpp_ff_init(). Now that the hw is kept open till the end of probe() the g920_get_config() call can be moved to just before hidpp_ff_init() to have all the HIDPP_QUIRK_CLASS_G920 together in a single place. Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index ff834f905eda..b278e2b8924a 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -4420,7 +4420,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) int ret; bool connected; unsigned int connect_mask = HID_CONNECT_DEFAULT; - struct hidpp_ff_private_data data; /* report_fixup needs drvdata to be set before we call hid_parse */ hidpp = devm_kzalloc(&hdev->dev, sizeof(*hidpp), GFP_KERNEL); @@ -4497,12 +4496,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) else hidpp_non_unifying_init(hidpp); - if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { - ret = g920_get_config(hidpp, &data); - if (ret) - goto hid_hw_init_fail; - } - /* Reset the HID node state */ hid_device_io_stop(hdev); hid_hw_close(hdev); @@ -4527,7 +4520,12 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) flush_work(&hidpp->work); if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { - ret = hidpp_ff_init(hidpp, &data); + struct hidpp_ff_private_data data; + + ret = g920_get_config(hidpp, &data); + if (!ret) + ret = hidpp_ff_init(hidpp, &data); + if (ret) hid_warn(hidpp->hid_dev, "Unable to initialize force feedback support, errno %d\n", @@ -4541,9 +4539,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hid_hw_close(hdev); return ret; -hid_hw_init_fail: - hid_hw_close(hdev); - hid_hw_stop(hdev); hid_hw_start_fail: sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); cancel_work_sync(&hidpp->work); From patchwork Sun Oct 8 09:54:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412676 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 5A323E95A82 for ; Sun, 8 Oct 2023 09:56:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344608AbjJHJ4j (ORCPT ); Sun, 8 Oct 2023 05:56:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344594AbjJHJ4i (ORCPT ); Sun, 8 Oct 2023 05:56:38 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 966ACE9 for ; Sun, 8 Oct 2023 02:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758919; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E1kj2POh2TKKg4arWVtWEwTpR1rPeel0wPR3HdautPE=; b=RJwaEiJ9Rwf/0KUKzfZGEgB2K1H3QHvttwMrU1wWonoIqyAsBwbn8cdkh8VlWxIg+J6JbI gtdMhawJjRKjbdE2/hLVAfBXBdNUUZ38tupdKTrnflmE6PMD6p69ahWxgS6NPbLuV/MCnc u5mfa3ZZGaZ+syvl2p/ltJjkGoXrQU4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-554-yn3WIBqTNkSN1NPe_usLZg-1; Sun, 08 Oct 2023 05:55:12 -0400 X-MC-Unique: yn3WIBqTNkSN1NPe_usLZg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 17DB1185A790; Sun, 8 Oct 2023 09:55:12 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 317EEC15BB8; Sun, 8 Oct 2023 09:55:11 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 11/14] HID: logitech-hidpp: Remove unused connected param from *_connect() Date: Sun, 8 Oct 2023 11:54:54 +0200 Message-ID: <20231008095458.8926-12-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Remove the unused connected function parameter from wtp_connect(), m560_send_config_command() and k400_connect(). Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index b278e2b8924a..2b0a2ea5da22 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -3141,7 +3141,7 @@ static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id) return 0; }; -static int wtp_connect(struct hid_device *hdev, bool connected) +static int wtp_connect(struct hid_device *hdev) { struct hidpp_device *hidpp = hid_get_drvdata(hdev); struct wtp_data *wd = hidpp->private_data; @@ -3203,7 +3203,7 @@ static const u8 m560_config_parameter[] = {0x00, 0xaf, 0x03}; #define M560_SUB_ID 0x0a #define M560_BUTTON_MODE_REGISTER 0x35 -static int m560_send_config_command(struct hid_device *hdev, bool connected) +static int m560_send_config_command(struct hid_device *hdev) { struct hidpp_report response; struct hidpp_device *hidpp_dev; @@ -3398,7 +3398,7 @@ static int k400_allocate(struct hid_device *hdev) return 0; }; -static int k400_connect(struct hid_device *hdev, bool connected) +static int k400_connect(struct hid_device *hdev) { struct hidpp_device *hidpp = hid_get_drvdata(hdev); @@ -4205,15 +4205,15 @@ static void hidpp_connect_event(struct hidpp_device *hidpp) } if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) { - ret = wtp_connect(hdev, connected); + ret = wtp_connect(hdev); if (ret) return; } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_M560) { - ret = m560_send_config_command(hdev, connected); + ret = m560_send_config_command(hdev); if (ret) return; } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_K400) { - ret = k400_connect(hdev, connected); + ret = k400_connect(hdev); if (ret) return; } From patchwork Sun Oct 8 09:54:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412680 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 2A91CE95A8E for ; Sun, 8 Oct 2023 09:56:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344587AbjJHJ4k (ORCPT ); Sun, 8 Oct 2023 05:56:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344603AbjJHJ4j (ORCPT ); Sun, 8 Oct 2023 05:56:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FB98DF for ; Sun, 8 Oct 2023 02:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758916; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=acwgmegbFXWKSqtmQPBbFfDnzH4lXgA3eWG9aKrDpEY=; b=DeBm6QWNEG+skgcMpaj7FRFfpY8pYWVMvm8K/dGk2qkNG0itibzwWktf+uSgbo5PVj0L1X O91w635i14leQtBdHNFcSlZvK1qEuMitxpgWZaqju2oRr881xykR31yx/teUs3hcor/wjf xpdgfSFiICPDLzAgvYvoaFoNUs5QHzc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-413-cFqZHP6jMW6eC51SHBNDEQ-1; Sun, 08 Oct 2023 05:55:13 -0400 X-MC-Unique: cFqZHP6jMW6eC51SHBNDEQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31C05185A78E; Sun, 8 Oct 2023 09:55:13 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 49DA5C15BB8; Sun, 8 Oct 2023 09:55:12 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 12/14] HID: logitech-hidpp: Fix connect event race Date: Sun, 8 Oct 2023 11:54:55 +0200 Message-ID: <20231008095458.8926-13-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org There is a connect event race in hidpp_probe() in these 2 lines: connected = hidpp_root_get_protocol_version(hidpp) == 0; atomic_set(&hidpp->connected, connected); Specifically the following can happen: 1. This line from hidpp_probe() is executed: connected = hidpp_root_get_protocol_version(hidpp) == 0; and sets connected to false; 2. A connect-event packet is received and does: atomic_set(&hidpp->connected, true); 3. The next line from hidpp_probe() is executed: atomic_set(&hidpp->connected, connected); and sets the atomic_t back to 0 again. 4. hidpp_connect_event() runs and sees the connected device as disconnected because of this. To fix this make hidpp_connect_event() query the connection status of the device itself instead of having it rely on possibly stale data cached in struct hidpp_device. Signed-off-by: Hans de Goede --- drivers/hid/hid-logitech-hidpp.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 2b0a2ea5da22..37213dcc9d9c 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -194,7 +194,6 @@ struct hidpp_device { struct work_struct work; struct kfifo delayed_work_fifo; - atomic_t connected; struct input_dev *delayed_input; unsigned long quirks; @@ -3893,8 +3892,6 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, } if (unlikely(hidpp_report_is_connect_event(hidpp, report))) { - atomic_set(&hidpp->connected, - !(report->rap.params[0] & (1 << 6))); if (schedule_work(&hidpp->work) == 0) dbg_hid("%s: connect event already queued\n", __func__); return 1; @@ -4189,12 +4186,14 @@ static struct input_dev *hidpp_allocate_input(struct hid_device *hdev) static void hidpp_connect_event(struct hidpp_device *hidpp) { struct hid_device *hdev = hidpp->hid_dev; - int ret = 0; - bool connected = atomic_read(&hidpp->connected); struct input_dev *input; char *name, *devm_name; + int ret; - if (!connected) { + /* Get device version to check if it is connected */ + ret = hidpp_root_get_protocol_version(hidpp); + if (ret) { + hid_info(hidpp->hid_dev, "Disconnected\n"); if (hidpp->battery.ps) { hidpp->battery.online = false; hidpp->battery.status = POWER_SUPPLY_STATUS_UNKNOWN; @@ -4235,17 +4234,6 @@ static void hidpp_connect_event(struct hidpp_device *hidpp) if (ret) return; } - - /* the device is already connected, we can ask for its name and - * protocol */ - if (!hidpp->protocol_major) { - ret = hidpp_root_get_protocol_version(hidpp); - if (ret) { - hid_err(hdev, "Can not get the protocol version.\n"); - return; - } - } - if (hidpp->protocol_major >= 2) { u8 feature_index; @@ -4418,7 +4406,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) { struct hidpp_device *hidpp; int ret; - bool connected; unsigned int connect_mask = HID_CONNECT_DEFAULT; /* report_fixup needs drvdata to be set before we call hid_parse */ @@ -4511,11 +4498,9 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) /* * Now that incoming packets are enabled and will not be disabled - * again (which may cause missing packets) check the connected state - * of the device. + * again (which may cause missing packets) queue hidpp_connect_event() + * to check the connected state of the device. */ - connected = hidpp_root_get_protocol_version(hidpp) == 0; - atomic_set(&hidpp->connected, connected); schedule_work(&hidpp->work); flush_work(&hidpp->work); From patchwork Sun Oct 8 09:54:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412685 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 B0DCCE95A67 for ; Sun, 8 Oct 2023 09:56:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344603AbjJHJ4s (ORCPT ); Sun, 8 Oct 2023 05:56:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344612AbjJHJ4r (ORCPT ); Sun, 8 Oct 2023 05:56:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90DACF1 for ; Sun, 8 Oct 2023 02:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758932; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b5rJrslAnv1U9s2DPDPrRtntfVCJmFEfnHd6BuXiqxU=; b=TI8qoUOIFGP42orL9Y0KMQIUjPosTu0zbSJ8900TBbwgak9n54nPy/yLv3LiLe9AkIGXWx fah19qvdJ/WMZqPmK0tD4NiW5CfB4nV/hTjfu+vlv2GY3g7maBEjxiauph8WkOpPAbsLth ugZ/KIz9jDOWQ8M0pik0AN+YHUH9NPI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-530-CVyg9Dh2NsefyL_4Hrjy_w-1; Sun, 08 Oct 2023 05:55:14 -0400 X-MC-Unique: CVyg9Dh2NsefyL_4Hrjy_w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B9CA101A550; Sun, 8 Oct 2023 09:55:14 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64103C15BB8; Sun, 8 Oct 2023 09:55:13 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 13/14] HID: logitech-hidpp: Avoid hidpp_connect_event() running while probe() restarts IO Date: Sun, 8 Oct 2023 11:54:56 +0200 Message-ID: <20231008095458.8926-14-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org hidpp_probe() restarts IO after setting things up, if we get a connect event just before hidpp_probe() stops all IO then hidpp_connect_event() will be running from the workqueue and it will see IO errors. To avoid this add an enable_connect_event flag and only set that after the IO restart is done. Since an hidpp_connect_event() run is queued after restarting IO anyways, connect events before that run can safely be ignored. Note this also means that hidpp_connect_event() is now guaranteed to not get queued on hidpp_connect_and_start() failures so the work for this no longer needs to be cancelled on failure. Signed-off-by: Hans de Goede --- Changes in v2: - Use an enable_connect_event flag instead of a mutex --- drivers/hid/hid-logitech-hidpp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 37213dcc9d9c..9e34a29619a0 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -192,6 +192,7 @@ struct hidpp_device { void *private_data; + atomic_t enable_connect_event; struct work_struct work; struct kfifo delayed_work_fifo; struct input_dev *delayed_input; @@ -3892,6 +3893,9 @@ static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data, } if (unlikely(hidpp_report_is_connect_event(hidpp, report))) { + if (!atomic_read(&hidpp->enable_connect_event)) + return 1; + if (schedule_work(&hidpp->work) == 0) dbg_hid("%s: connect event already queued\n", __func__); return 1; @@ -4501,6 +4505,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) * again (which may cause missing packets) queue hidpp_connect_event() * to check the connected state of the device. */ + atomic_set(&hidpp->enable_connect_event, 1); schedule_work(&hidpp->work); flush_work(&hidpp->work); @@ -4526,7 +4531,6 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hid_hw_start_fail: sysfs_remove_group(&hdev->dev.kobj, &ps_attribute_group); - cancel_work_sync(&hidpp->work); mutex_destroy(&hidpp->send_mutex); return ret; } From patchwork Sun Oct 8 09:54:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13412684 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 8CFE1E95A82 for ; Sun, 8 Oct 2023 09:56:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344611AbjJHJ4r (ORCPT ); Sun, 8 Oct 2023 05:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344603AbjJHJ4q (ORCPT ); Sun, 8 Oct 2023 05:56:46 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36EE3ED for ; Sun, 8 Oct 2023 02:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696758924; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=muUtavzrGlnYFeN/CRVD9MuCcTK7JeTDnX4CZ+6Zefc=; b=LhzhCIIrV10TYSdQtVqkdQOGsz3ow1rfvf+YFn5WD3kJqrCqrptV800rqhA625xvuj2gb+ BCyhTcv/A7ZZmo/oC8JbA1UU9mJAPnJLcSo4v7P8gEmzquFkmCmNcPqWXlE6snzbYbuxON F6mh4YUOdix3BiDJAxlK081Bfb1ew54= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-584-B41DR_oROOKe1BSggIKmSw-1; Sun, 08 Oct 2023 05:55:15 -0400 X-MC-Unique: B41DR_oROOKe1BSggIKmSw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 657B280349A; Sun, 8 Oct 2023 09:55:15 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E089C15BB8; Sun, 8 Oct 2023 09:55:14 +0000 (UTC) From: Hans de Goede To: =?utf-8?q?Filipe_La=C3=ADns?= , Bastien Nocera , Jiri Kosina , Benjamin Tissoires Cc: Hans de Goede , linux-input@vger.kernel.org Subject: [PATCH v2 14/14] HID: logitech-hidpp: Drop delayed_work_cb() Date: Sun, 8 Oct 2023 11:54:57 +0200 Message-ID: <20231008095458.8926-15-hdegoede@redhat.com> In-Reply-To: <20231008095458.8926-1-hdegoede@redhat.com> References: <20231008095458.8926-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Drop delayed_work_cb() instead make hidpp_connect_event() the workqueue function itself. Besides resulting in a small cleanup this will hopefully also make it clearer that going forward hidpp_connect_event() should only be run from a workqueue and not be directly invoked. Signed-off-by: Hans de Goede Link: https://lore.kernel.org/r/20231006081858.17677-3-hdegoede@redhat.com --- drivers/hid/hid-logitech-hidpp.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 9e34a29619a0..547544a5649b 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -235,8 +235,6 @@ struct hidpp_device { #define HIDPP20_ERROR_UNSUPPORTED 0x09 #define HIDPP20_ERROR 0xff -static void hidpp_connect_event(struct hidpp_device *hidpp_dev); - static int __hidpp_send_report(struct hid_device *hdev, struct hidpp_report *hidpp_report) { @@ -450,13 +448,6 @@ static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev, return ret; } -static void delayed_work_cb(struct work_struct *work) -{ - struct hidpp_device *hidpp = container_of(work, struct hidpp_device, - work); - hidpp_connect_event(hidpp); -} - static inline bool hidpp_match_answer(struct hidpp_report *question, struct hidpp_report *answer) { @@ -4187,8 +4178,9 @@ static struct input_dev *hidpp_allocate_input(struct hid_device *hdev) return input_dev; } -static void hidpp_connect_event(struct hidpp_device *hidpp) +static void hidpp_connect_event(struct work_struct *work) { + struct hidpp_device *hidpp = container_of(work, struct hidpp_device, work); struct hid_device *hdev = hidpp->hid_dev; struct input_dev *input; char *name, *devm_name; @@ -4461,7 +4453,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) return ret; } - INIT_WORK(&hidpp->work, delayed_work_cb); + INIT_WORK(&hidpp->work, hidpp_connect_event); mutex_init(&hidpp->send_mutex); init_waitqueue_head(&hidpp->wait);