Message ID | 20230621-logitech-fixes-v1-1-32e70933c0b0@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4252847vqr; Wed, 21 Jun 2023 03:14:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7QSmFd8Yq0C/1F+HM8Sk07m0Kdootc1NkyYLS+QMLBNPXe75AJ6psk16ugQ0eL1P6/1azB X-Received: by 2002:a17:902:82cb:b0:1a6:4a64:4d27 with SMTP id u11-20020a17090282cb00b001a64a644d27mr12150306plz.40.1687342470667; Wed, 21 Jun 2023 03:14:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687342470; cv=none; d=google.com; s=arc-20160816; b=Q7m64ffWk6WsSy4nh7NMGTRrmMHBPllTgkaU4o+OCq9rhCnp+AIeilZ1Lezo3KtvSZ MawVUIyZ8GgEpVwvdW5NMG6YG75PzVx1p4RTFZIAhmkh63l1QWXref5K1u11WTmeIU5I 1HvUR5gVOF+8/G18QwUksg5Z9VTo2eH8QF1W8vdEKxWdAEZy619dnXCVnhZ7VgMM5SFu oDOToQsgYRDgk4Y1MEHnsUqHaDwJ1iKdw/wAdbxGFLnRWBujdkOf6XshPMvQw79SJfh9 /km3tPEwkDtBdzYefsP/ossKqAm8HgD0Avdu7u/L2e+pbQdzF7eytEkdDZeB/EJMV5Os MnaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=Diofrp0NHoaj7laq9s3ordTMEyCXaD8juDW832/O7Eo=; b=HFsDfWZzMLI6Zh7Kn4InddxN3xX0Jqi9UoWdFQVVPpTRSmdUwr8dW5SQv3URBGAqHb kuZLX8oSZ1w47xI/00xPin90rBlTtOEtcDJqUvWHMhxKJXN0rmel2dRGTxszLr6vW343 7NYI+5/zMgAg/G16hyAKwDTUI+AYPpPNE5hp90NcJ+I+jWqdMwjZo9g2KoQDNCR2NA2w ufFDcCEfvfU5dhSm0n+9JWfggHq+rsTmKFgv9jMXB4/cMQXWtRmhuGeaRpb+TOmsBeYE WZpZSK/j++ONs65teA56payfjm7agzDQA5xV51XcK6lm4uDQNvnJEpq6ySL4+BjTejl9 E9MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PLGFNbAP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t16-20020a170902e85000b001b3cf975c75si4299339plg.222.2023.06.21.03.14.17; Wed, 21 Jun 2023 03:14:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PLGFNbAP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230428AbjFUJnd (ORCPT <rfc822;maxin.john@gmail.com> + 99 others); Wed, 21 Jun 2023 05:43:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230146AbjFUJn3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 21 Jun 2023 05:43:29 -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 47187DD for <linux-kernel@vger.kernel.org>; Wed, 21 Jun 2023 02:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687340563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Diofrp0NHoaj7laq9s3ordTMEyCXaD8juDW832/O7Eo=; b=PLGFNbAP7wkxSvzu3PjrjD5k9tQvm/H+0Ya+K765u3vdj9RCvpfftxbg4NF3gnaMFLBRcC gZ/wIoGI59Zepa7O0C2qdLdcaPZ+UjP+f+Leu4HdS8L5xyMLtMzUum+LvpnJk0MCu306/y efekes/8JJ0+zC8p96X1vEgumqPKUXA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.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-HGWhI5BMPYuDye4tb2GKqA-1; Wed, 21 Jun 2023 05:42:37 -0400 X-MC-Unique: HGWhI5BMPYuDye4tb2GKqA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D67FE3C108C7; Wed, 21 Jun 2023 09:42:36 +0000 (UTC) Received: from xps-13.local (unknown [10.39.193.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id B064B492C13; Wed, 21 Jun 2023 09:42:35 +0000 (UTC) From: Benjamin Tissoires <benjamin.tissoires@redhat.com> Date: Wed, 21 Jun 2023 11:42:30 +0200 Subject: [PATCH] HID: logitech-hidpp: rework one more time the retries attempts MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230621-logitech-fixes-v1-1-32e70933c0b0@redhat.com> X-B4-Tracking: v=1; b=H4sIAAXGkmQC/1WLwQrCMBAFfyXs2YU0Sg79Felhmz6bBUlLVkQI/ XdTPHmbgZlGhqowGl2jireabqXLcHGUspQVrEt3Cj5cfQwDP7dVX0iZH/qBsdySR4yQIAv1aRY Dz1VKyuf2X5/BXvHj0d2n4/gCP4LGsIEAAAA= To: =?utf-8?q?Filipe_La=C3=ADns?= <lains@riseup.net>, Bastien Nocera <hadess@hadess.net>, Jiri Kosina <jikos@kernel.org> Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Benjamin Tissoires <benjamin.tissoires@redhat.com> X-Developer-Signature: v=1; a=ed25519-sha256; t=1687340555; l=5291; i=benjamin.tissoires@redhat.com; s=20230215; h=from:subject:message-id; bh=UiFLHp8Bq+QvatTIh2AbpNG2HYSjT6YexmSDYyCrUEI=; b=KeKGHpo0AAjoH0Qsj9oVKHMco9aHBn3E18cRfEinhSz88nk6+rbZWg4Lvan7cLxYgeFPsdXhu ZavHFrOSuL6DpHgPQp9d00y7PICetBA8nUho1RWGTeEBE01mKfDNwTI X-Developer-Key: i=benjamin.tissoires@redhat.com; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769306818236762395?= X-GMAIL-MSGID: =?utf-8?q?1769306818236762395?= |
Series |
HID: logitech-hidpp: rework one more time the retries attempts
|
|
Commit Message
Benjamin Tissoires
June 21, 2023, 9:42 a.m. UTC
Make the code looks less like Pascal.
Extract the internal code inside a helper function, fix the
initialization of the parameters used in the helper function
(`hidpp->answer_available` was not reset and `*response` wasn't too),
and use a `do {...} while();` loop.
Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when device is busy")
Cc: stable@vger.kernel.org
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
as requested by https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/
This is a rewrite of that particular piece of code.
---
drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++----------------
1 file changed, 61 insertions(+), 41 deletions(-)
---
base-commit: b98ec211af5508457e2b1c4cc99373630a83fa81
change-id: 20230621-logitech-fixes-a4c0e66ea2ad
Best regards,
Comments
On Wed, Jun 21, 2023 at 11:42:30AM +0200, Benjamin Tissoires wrote: > Make the code looks less like Pascal. > > Extract the internal code inside a helper function, fix the > initialization of the parameters used in the helper function > (`hidpp->answer_available` was not reset and `*response` wasn't too), > and use a `do {...} while();` loop. > > Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when device is busy") > Cc: stable@vger.kernel.org > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> > --- > as requested by https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ > This is a rewrite of that particular piece of code. > --- > drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++---------------- > 1 file changed, 61 insertions(+), 41 deletions(-) > > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c > index dfe8e09a18de..3d1ffe199f08 100644 > --- a/drivers/hid/hid-logitech-hidpp.c > +++ b/drivers/hid/hid-logitech-hidpp.c > @@ -275,21 +275,20 @@ static int __hidpp_send_report(struct hid_device *hdev, > } > > /* > - * hidpp_send_message_sync() returns 0 in case of success, and something else > - * in case of a failure. > - * - If ' something else' is positive, that means that an error has been raised > - * by the protocol itself. > - * - If ' something else' is negative, that means that we had a classic error > - * (-ENOMEM, -EPIPE, etc...) > + * Effectively send the message to the device, waiting for its answer. > + * > + * Must be called with hidpp->send_mutex locked > + * > + * Same return protocol than hidpp_send_message_sync(): > + * - success on 0 > + * - negative error means transport error > + * - positive value means protocol error > */ > -static int hidpp_send_message_sync(struct hidpp_device *hidpp, > +static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, > struct hidpp_report *message, > struct hidpp_report *response) __must_hold(&hidpp->send_mutex) ?
On Jun 21 2023, Greg KH wrote: > > On Wed, Jun 21, 2023 at 11:42:30AM +0200, Benjamin Tissoires wrote: > > Make the code looks less like Pascal. > > > > Extract the internal code inside a helper function, fix the > > initialization of the parameters used in the helper function > > (`hidpp->answer_available` was not reset and `*response` wasn't too), > > and use a `do {...} while();` loop. > > > > Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when device is busy") > > Cc: stable@vger.kernel.org > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> > > --- > > as requested by https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ > > This is a rewrite of that particular piece of code. > > --- > > drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++---------------- > > 1 file changed, 61 insertions(+), 41 deletions(-) > > > > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c > > index dfe8e09a18de..3d1ffe199f08 100644 > > --- a/drivers/hid/hid-logitech-hidpp.c > > +++ b/drivers/hid/hid-logitech-hidpp.c > > @@ -275,21 +275,20 @@ static int __hidpp_send_report(struct hid_device *hdev, > > } > > > > /* > > - * hidpp_send_message_sync() returns 0 in case of success, and something else > > - * in case of a failure. > > - * - If ' something else' is positive, that means that an error has been raised > > - * by the protocol itself. > > - * - If ' something else' is negative, that means that we had a classic error > > - * (-ENOMEM, -EPIPE, etc...) > > + * Effectively send the message to the device, waiting for its answer. > > + * > > + * Must be called with hidpp->send_mutex locked > > + * > > + * Same return protocol than hidpp_send_message_sync(): > > + * - success on 0 > > + * - negative error means transport error > > + * - positive value means protocol error > > */ > > -static int hidpp_send_message_sync(struct hidpp_device *hidpp, > > +static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, > > struct hidpp_report *message, > > struct hidpp_report *response) > > __must_hold(&hidpp->send_mutex) ? > Good point. I'll add this in v2. I'm still waiting for some feedback from the people who particpated in the original BZ, but the new bug is harder to reproduce. Anyway, there is no rush IMO. Cheers, Benjamin
On Wed, 2023-06-21 at 11:42 +0200, Benjamin Tissoires wrote: > Make the code looks less like Pascal. Honestly, while this was written in jest in an email is fine, putting this in the commit message is quite insulting. The "retry" patch tried to fix real world problems by making minimal code changes, eg. avoiding the review problem that the present patch has, and even then, all of us missed the logic bug. I also haven't written any Pascal code since 1996. > Extract the internal code inside a helper function, fix the > initialization of the parameters used in the helper function > (`hidpp->answer_available` was not reset and `*response` wasn't too), "wasn't either". > and use a `do {...} while();` loop. > > Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when device > is busy") > Cc: stable@vger.kernel.org > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> > --- > as requested by > https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ > This is a rewrite of that particular piece of code. > --- > drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++------ > ---------- > 1 file changed, 61 insertions(+), 41 deletions(-) > > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid- > logitech-hidpp.c > index dfe8e09a18de..3d1ffe199f08 100644 > --- a/drivers/hid/hid-logitech-hidpp.c > +++ b/drivers/hid/hid-logitech-hidpp.c > @@ -275,21 +275,20 @@ static int __hidpp_send_report(struct > hid_device *hdev, > } > > /* > - * hidpp_send_message_sync() returns 0 in case of success, and > something else > - * in case of a failure. > - * - If ' something else' is positive, that means that an error has > been raised > - * by the protocol itself. > - * - If ' something else' is negative, that means that we had a > classic error > - * (-ENOMEM, -EPIPE, etc...) > + * Effectively send the message to the device, waiting for its > answer. > + * > + * Must be called with hidpp->send_mutex locked > + * > + * Same return protocol than hidpp_send_message_sync(): > + * - success on 0 > + * - negative error means transport error > + * - positive value means protocol error > */ > -static int hidpp_send_message_sync(struct hidpp_device *hidpp, > +static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, > struct hidpp_report *message, > struct hidpp_report *response) > { > - int ret = -1; > - int max_retries = 3; > - > - mutex_lock(&hidpp->send_mutex); > + int ret; > > hidpp->send_receive_buf = response; > hidpp->answer_available = false; > @@ -300,41 +299,62 @@ static int hidpp_send_message_sync(struct > hidpp_device *hidpp, > */ > *response = *message; > > - for (; max_retries != 0 && ret; max_retries--) { > - ret = __hidpp_send_report(hidpp->hid_dev, message); > + ret = __hidpp_send_report(hidpp->hid_dev, message); > + if (ret) { > + dbg_hid("__hidpp_send_report returned err: %d\n", > ret); > + memset(response, 0, sizeof(struct hidpp_report)); > + return ret; > + } > > - if (ret) { > - dbg_hid("__hidpp_send_report returned err: > %d\n", ret); > - memset(response, 0, sizeof(struct > hidpp_report)); > - break; > - } > + if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, > + 5*HZ)) { > + dbg_hid("%s:timeout waiting for response\n", > __func__); > + memset(response, 0, sizeof(struct hidpp_report)); > + return -ETIMEDOUT; > + } > > - if (!wait_event_timeout(hidpp->wait, hidpp- > >answer_available, > - 5*HZ)) { > - dbg_hid("%s:timeout waiting for response\n", > __func__); > - memset(response, 0, sizeof(struct > hidpp_report)); > - ret = -ETIMEDOUT; > - break; > - } > + if (response->report_id == REPORT_ID_HIDPP_SHORT && > + response->rap.sub_id == HIDPP_ERROR) { > + ret = response->rap.params[1]; > + dbg_hid("%s:got hidpp error %02X\n", __func__, ret); > + return ret; > + } > > - if (response->report_id == REPORT_ID_HIDPP_SHORT && > - response->rap.sub_id == HIDPP_ERROR) { > - ret = response->rap.params[1]; > - dbg_hid("%s:got hidpp error %02X\n", > __func__, ret); > + if ((response->report_id == REPORT_ID_HIDPP_LONG || > + response->report_id == REPORT_ID_HIDPP_VERY_LONG) && > + response->fap.feature_index == HIDPP20_ERROR) { > + ret = response->fap.params[1]; > + dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, > ret); > + return ret; > + } > + > + return 0; > +} > + > +/* > + * hidpp_send_message_sync() returns 0 in case of success, and > something else > + * in case of a failure. > + * - If ' something else' is positive, that means that an error has > been raised > + * by the protocol itself. > + * - If ' something else' is negative, that means that we had a > classic error > + * (-ENOMEM, -EPIPE, etc...) Do we really need to re-explain the possible return values that were already explained above __do_hidpp_send_message_sync()? If we do, why don't also do it for hidpp_send_fap_command_sync() and hidpp_send_rap_command_sync(), or their callers? If it's absolutely necessary, a "see __do_hidpp_send_message_sync()" should be enough. I've double-checked that none of the existing callers expected a partially filled in "response" struct on error. Reviewed-by: Bastien Nocera <hadess@hadess.net> > + */ > +static int hidpp_send_message_sync(struct hidpp_device *hidpp, > + struct hidpp_report *message, > + struct hidpp_report *response) > +{ > + int ret; > + int max_retries = 3; > + > + mutex_lock(&hidpp->send_mutex); > + > + do { > + ret = __do_hidpp_send_message_sync(hidpp, message, > response); > + if (ret != HIDPP20_ERROR_BUSY) > break; > - } > > - if ((response->report_id == REPORT_ID_HIDPP_LONG || > - response->report_id == > REPORT_ID_HIDPP_VERY_LONG) && > - response->fap.feature_index == HIDPP20_ERROR) { > - ret = response->fap.params[1]; > - if (ret != HIDPP20_ERROR_BUSY) { > - dbg_hid("%s:got hidpp 2.0 error > %02X\n", __func__, ret); > - break; > - } > - dbg_hid("%s:got busy hidpp 2.0 error %02X, > retrying\n", __func__, ret); > - } > - } > + dbg_hid("%s:got busy hidpp 2.0 error %02X, > retrying\n", __func__, ret); > + } while (--max_retries); > > mutex_unlock(&hidpp->send_mutex); > return ret; > > --- > base-commit: b98ec211af5508457e2b1c4cc99373630a83fa81 > change-id: 20230621-logitech-fixes-a4c0e66ea2ad > > Best regards,
On Fri, 2023-06-23 at 10:37 +0200, Benjamin Tissoires wrote: > > On Jun 21 2023, Greg KH wrote: > > > > On Wed, Jun 21, 2023 at 11:42:30AM +0200, Benjamin Tissoires wrote: > > > Make the code looks less like Pascal. > > > > > > Extract the internal code inside a helper function, fix the > > > initialization of the parameters used in the helper function > > > (`hidpp->answer_available` was not reset and `*response` wasn't > > > too), > > > and use a `do {...} while();` loop. > > > > > > Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when > > > device is busy") > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> > > > --- > > > as requested by > > > https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ > > > This is a rewrite of that particular piece of code. > > > --- > > > drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++-- > > > -------------- > > > 1 file changed, 61 insertions(+), 41 deletions(-) > > > > > > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid- > > > logitech-hidpp.c > > > index dfe8e09a18de..3d1ffe199f08 100644 > > > --- a/drivers/hid/hid-logitech-hidpp.c > > > +++ b/drivers/hid/hid-logitech-hidpp.c > > > @@ -275,21 +275,20 @@ static int __hidpp_send_report(struct > > > hid_device *hdev, > > > } > > > > > > /* > > > - * hidpp_send_message_sync() returns 0 in case of success, and > > > something else > > > - * in case of a failure. > > > - * - If ' something else' is positive, that means that an error > > > has been raised > > > - * by the protocol itself. > > > - * - If ' something else' is negative, that means that we had a > > > classic error > > > - * (-ENOMEM, -EPIPE, etc...) > > > + * Effectively send the message to the device, waiting for its > > > answer. > > > + * > > > + * Must be called with hidpp->send_mutex locked > > > + * > > > + * Same return protocol than hidpp_send_message_sync(): > > > + * - success on 0 > > > + * - negative error means transport error > > > + * - positive value means protocol error > > > */ > > > -static int hidpp_send_message_sync(struct hidpp_device *hidpp, > > > +static int __do_hidpp_send_message_sync(struct hidpp_device > > > *hidpp, > > > struct hidpp_report *message, > > > struct hidpp_report *response) > > > > __must_hold(&hidpp->send_mutex) ? > > > > Good point. I'll add this in v2. > > I'm still waiting for some feedback from the people who particpated > in > the original BZ, but the new bug is harder to reproduce. Anyway, > there > is no rush IMO. The problem is only ever going to show up in very limited circumstances after the logic fix was applied. You need a hardware problem (such as the controller being too busy to answer) to trigger the problems fixed by this patch. I don't see a way to reliably reproduce it unless you inject that hardware error.
On Sun, Jun 25, 2023 at 10:30 AM Bastien Nocera <hadess@hadess.net> wrote: > > On Wed, 2023-06-21 at 11:42 +0200, Benjamin Tissoires wrote: > > Make the code looks less like Pascal. > > Honestly, while this was written in jest in an email is fine, putting > this in the commit message is quite insulting. > > The "retry" patch tried to fix real world problems by making minimal > code changes, eg. avoiding the review problem that the present patch > has, and even then, all of us missed the logic bug. > > I also haven't written any Pascal code since 1996. Apologies for that. I honestly took Linus' remark to myself only, because I was fixing your fix on my original code. And while initially fixing your for loop, I should have realized that this was very hard to follow, because of the "if (sth; sth < 1 && foo && bar; sth+=1)". I'll amend v2 > > > Extract the internal code inside a helper function, fix the > > initialization of the parameters used in the helper function > > (`hidpp->answer_available` was not reset and `*response` wasn't too), > > "wasn't either". > > > and use a `do {...} while();` loop. > > > > Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when device > > is busy") > > Cc: stable@vger.kernel.org > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> > > --- > > as requested by > > https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ > > This is a rewrite of that particular piece of code. > > --- > > drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++------ > > ---------- > > 1 file changed, 61 insertions(+), 41 deletions(-) > > > > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid- > > logitech-hidpp.c > > index dfe8e09a18de..3d1ffe199f08 100644 > > --- a/drivers/hid/hid-logitech-hidpp.c > > +++ b/drivers/hid/hid-logitech-hidpp.c > > @@ -275,21 +275,20 @@ static int __hidpp_send_report(struct > > hid_device *hdev, > > } > > > > /* > > - * hidpp_send_message_sync() returns 0 in case of success, and > > something else > > - * in case of a failure. > > - * - If ' something else' is positive, that means that an error has > > been raised > > - * by the protocol itself. > > - * - If ' something else' is negative, that means that we had a > > classic error > > - * (-ENOMEM, -EPIPE, etc...) > > + * Effectively send the message to the device, waiting for its > > answer. > > + * > > + * Must be called with hidpp->send_mutex locked > > + * > > + * Same return protocol than hidpp_send_message_sync(): > > + * - success on 0 > > + * - negative error means transport error > > + * - positive value means protocol error > > */ > > -static int hidpp_send_message_sync(struct hidpp_device *hidpp, > > +static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, > > struct hidpp_report *message, > > struct hidpp_report *response) > > { > > - int ret = -1; > > - int max_retries = 3; > > - > > - mutex_lock(&hidpp->send_mutex); > > + int ret; > > > > hidpp->send_receive_buf = response; > > hidpp->answer_available = false; > > @@ -300,41 +299,62 @@ static int hidpp_send_message_sync(struct > > hidpp_device *hidpp, > > */ > > *response = *message; > > > > - for (; max_retries != 0 && ret; max_retries--) { > > - ret = __hidpp_send_report(hidpp->hid_dev, message); > > + ret = __hidpp_send_report(hidpp->hid_dev, message); > > + if (ret) { > > + dbg_hid("__hidpp_send_report returned err: %d\n", > > ret); > > + memset(response, 0, sizeof(struct hidpp_report)); > > + return ret; > > + } > > > > - if (ret) { > > - dbg_hid("__hidpp_send_report returned err: > > %d\n", ret); > > - memset(response, 0, sizeof(struct > > hidpp_report)); > > - break; > > - } > > + if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, > > + 5*HZ)) { > > + dbg_hid("%s:timeout waiting for response\n", > > __func__); > > + memset(response, 0, sizeof(struct hidpp_report)); > > + return -ETIMEDOUT; > > + } > > > > - if (!wait_event_timeout(hidpp->wait, hidpp- > > >answer_available, > > - 5*HZ)) { > > - dbg_hid("%s:timeout waiting for response\n", > > __func__); > > - memset(response, 0, sizeof(struct > > hidpp_report)); > > - ret = -ETIMEDOUT; > > - break; > > - } > > + if (response->report_id == REPORT_ID_HIDPP_SHORT && > > + response->rap.sub_id == HIDPP_ERROR) { > > + ret = response->rap.params[1]; > > + dbg_hid("%s:got hidpp error %02X\n", __func__, ret); > > + return ret; > > + } > > > > - if (response->report_id == REPORT_ID_HIDPP_SHORT && > > - response->rap.sub_id == HIDPP_ERROR) { > > - ret = response->rap.params[1]; > > - dbg_hid("%s:got hidpp error %02X\n", > > __func__, ret); > > + if ((response->report_id == REPORT_ID_HIDPP_LONG || > > + response->report_id == REPORT_ID_HIDPP_VERY_LONG) && > > + response->fap.feature_index == HIDPP20_ERROR) { > > + ret = response->fap.params[1]; > > + dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, > > ret); > > + return ret; > > + } > > + > > + return 0; > > +} > > + > > +/* > > + * hidpp_send_message_sync() returns 0 in case of success, and > > something else > > + * in case of a failure. > > + * - If ' something else' is positive, that means that an error has > > been raised > > + * by the protocol itself. > > + * - If ' something else' is negative, that means that we had a > > classic error > > + * (-ENOMEM, -EPIPE, etc...) > > Do we really need to re-explain the possible return values that were > already explained above __do_hidpp_send_message_sync()? Right, maybe we don't need to duplicate the comment after all. > > If we do, why don't also do it for hidpp_send_fap_command_sync() and > hidpp_send_rap_command_sync(), or their callers? In a way it would make sense to do, because this is non standard. > > If it's absolutely necessary, a "see __do_hidpp_send_message_sync()" > should be enough. Good point. > > I've double-checked that none of the existing callers expected a > partially filled in "response" struct on error. > > Reviewed-by: Bastien Nocera <hadess@hadess.net> Thanks! Cheers, Benjamin > > > + */ > > +static int hidpp_send_message_sync(struct hidpp_device *hidpp, > > + struct hidpp_report *message, > > + struct hidpp_report *response) > > +{ > > + int ret; > > + int max_retries = 3; > > + > > + mutex_lock(&hidpp->send_mutex); > > + > > + do { > > + ret = __do_hidpp_send_message_sync(hidpp, message, > > response); > > + if (ret != HIDPP20_ERROR_BUSY) > > break; > > - } > > > > - if ((response->report_id == REPORT_ID_HIDPP_LONG || > > - response->report_id == > > REPORT_ID_HIDPP_VERY_LONG) && > > - response->fap.feature_index == HIDPP20_ERROR) { > > - ret = response->fap.params[1]; > > - if (ret != HIDPP20_ERROR_BUSY) { > > - dbg_hid("%s:got hidpp 2.0 error > > %02X\n", __func__, ret); > > - break; > > - } > > - dbg_hid("%s:got busy hidpp 2.0 error %02X, > > retrying\n", __func__, ret); > > - } > > - } > > + dbg_hid("%s:got busy hidpp 2.0 error %02X, > > retrying\n", __func__, ret); > > + } while (--max_retries); > > > > mutex_unlock(&hidpp->send_mutex); > > return ret; > > > > --- > > base-commit: b98ec211af5508457e2b1c4cc99373630a83fa81 > > change-id: 20230621-logitech-fixes-a4c0e66ea2ad > > > > Best regards, >
On Sun, Jun 25, 2023 at 10:30 AM Bastien Nocera <hadess@hadess.net> wrote: > > On Fri, 2023-06-23 at 10:37 +0200, Benjamin Tissoires wrote: > > > > On Jun 21 2023, Greg KH wrote: > > > > > > On Wed, Jun 21, 2023 at 11:42:30AM +0200, Benjamin Tissoires wrote: > > > > Make the code looks less like Pascal. > > > > > > > > Extract the internal code inside a helper function, fix the > > > > initialization of the parameters used in the helper function > > > > (`hidpp->answer_available` was not reset and `*response` wasn't > > > > too), > > > > and use a `do {...} while();` loop. > > > > > > > > Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when > > > > device is busy") > > > > Cc: stable@vger.kernel.org > > > > Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> > > > > --- > > > > as requested by > > > > https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ > > > > This is a rewrite of that particular piece of code. > > > > --- > > > > drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++-- > > > > -------------- > > > > 1 file changed, 61 insertions(+), 41 deletions(-) > > > > > > > > diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid- > > > > logitech-hidpp.c > > > > index dfe8e09a18de..3d1ffe199f08 100644 > > > > --- a/drivers/hid/hid-logitech-hidpp.c > > > > +++ b/drivers/hid/hid-logitech-hidpp.c > > > > @@ -275,21 +275,20 @@ static int __hidpp_send_report(struct > > > > hid_device *hdev, > > > > } > > > > > > > > /* > > > > - * hidpp_send_message_sync() returns 0 in case of success, and > > > > something else > > > > - * in case of a failure. > > > > - * - If ' something else' is positive, that means that an error > > > > has been raised > > > > - * by the protocol itself. > > > > - * - If ' something else' is negative, that means that we had a > > > > classic error > > > > - * (-ENOMEM, -EPIPE, etc...) > > > > + * Effectively send the message to the device, waiting for its > > > > answer. > > > > + * > > > > + * Must be called with hidpp->send_mutex locked > > > > + * > > > > + * Same return protocol than hidpp_send_message_sync(): > > > > + * - success on 0 > > > > + * - negative error means transport error > > > > + * - positive value means protocol error > > > > */ > > > > -static int hidpp_send_message_sync(struct hidpp_device *hidpp, > > > > +static int __do_hidpp_send_message_sync(struct hidpp_device > > > > *hidpp, > > > > struct hidpp_report *message, > > > > struct hidpp_report *response) > > > > > > __must_hold(&hidpp->send_mutex) ? > > > > > > > Good point. I'll add this in v2. > > > > I'm still waiting for some feedback from the people who particpated > > in > > the original BZ, but the new bug is harder to reproduce. Anyway, > > there > > is no rush IMO. > > The problem is only ever going to show up in very limited circumstances > after the logic fix was applied. > > You need a hardware problem (such as the controller being too busy to > answer) to trigger the problems fixed by this patch. I don't see a way > to reliably reproduce it unless you inject that hardware error. > Some people on the Bz were able to reproduce with multiple reboots. But it's not as urgent as previously, and we were close to the 6.4 final when I sent it. I'll make sure this goes into 6.5 and gets proper stable backports FWIW. Cheers, Benjamin
Linux regression tracking (Thorsten Leemhuis)
July 11, 2023, 1:09 p.m. UTC |
#7
Addressed
Unaddressed
On 26.06.23 16:02, Benjamin Tissoires wrote: > On Sun, Jun 25, 2023 at 10:30 AM Bastien Nocera <hadess@hadess.net> wrote: >> On Fri, 2023-06-23 at 10:37 +0200, Benjamin Tissoires wrote: >>> On Jun 21 2023, Greg KH wrote: >>>> On Wed, Jun 21, 2023 at 11:42:30AM +0200, Benjamin Tissoires wrote: >>>>> Make the code looks less like Pascal. >>>>> >>>>> Extract the internal code inside a helper function, fix the >>>>> initialization of the parameters used in the helper function >>>>> (`hidpp->answer_available` was not reset and `*response` wasn't >>>>> too), >>>>> and use a `do {...} while();` loop. >>>>> >>>>> Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when >>>>> device is busy") >>>>> Cc: stable@vger.kernel.org >>>>> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> >>>>> --- >>>>> as requested by >>>>> https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ >>>>> This is a rewrite of that particular piece of code. >>>>> --- >>>>> drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++-- >>>>> -------------- >>>>> 1 file changed, 61 insertions(+), 41 deletions(-) > [...] > > Some people on the Bz were able to reproduce with multiple reboots. > But it's not as urgent as previously, and we were close to the 6.4 > final when I sent it. I'll make sure this goes into 6.5 and gets > proper stable backports FWIW. Did that happen? Doesn't look like it from here, but maybe I'm missing something. Where there maybe other changes to resolve the remaining problems some users encounter sporadically since the urgent fixes went in? Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) -- Everything you wanna know about Linux kernel regression tracking: https://linux-regtracking.leemhuis.info/about/#tldr If I did something stupid, please tell me, as explained on that page.
On Tue, Jul 11, 2023 at 3:10 PM Linux regression tracking (Thorsten Leemhuis) <regressions@leemhuis.info> wrote: > > On 26.06.23 16:02, Benjamin Tissoires wrote: > > On Sun, Jun 25, 2023 at 10:30 AM Bastien Nocera <hadess@hadess.net> wrote: > >> On Fri, 2023-06-23 at 10:37 +0200, Benjamin Tissoires wrote: > >>> On Jun 21 2023, Greg KH wrote: > >>>> On Wed, Jun 21, 2023 at 11:42:30AM +0200, Benjamin Tissoires wrote: > >>>>> Make the code looks less like Pascal. > >>>>> > >>>>> Extract the internal code inside a helper function, fix the > >>>>> initialization of the parameters used in the helper function > >>>>> (`hidpp->answer_available` was not reset and `*response` wasn't > >>>>> too), > >>>>> and use a `do {...} while();` loop. > >>>>> > >>>>> Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when > >>>>> device is busy") > >>>>> Cc: stable@vger.kernel.org > >>>>> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> > >>>>> --- > >>>>> as requested by > >>>>> https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ > >>>>> This is a rewrite of that particular piece of code. > >>>>> --- > >>>>> drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++-- > >>>>> -------------- > >>>>> 1 file changed, 61 insertions(+), 41 deletions(-) > > [...] > > > > Some people on the Bz were able to reproduce with multiple reboots. > > But it's not as urgent as previously, and we were close to the 6.4 > > final when I sent it. I'll make sure this goes into 6.5 and gets > > proper stable backports FWIW. > > Did that happen? Doesn't look like it from here, but maybe I'm missing > something. Where there maybe other changes to resolve the remaining > problems some users encounter sporadically since the urgent fixes went in? No, there were no other changes that could have solved this. I guess the randomness of the problem makes it way harder to detect and to reproduce. I'll send a v2 of that patch with the reviews today or tomorrow and we can probably get it through the current 6.5 cycle. Cheers, Benjamin > > Ciao, Thorsten (wearing his 'the Linux kernel's regression tracker' hat) > -- > Everything you wanna know about Linux kernel regression tracking: > https://linux-regtracking.leemhuis.info/about/#tldr > If I did something stupid, please tell me, as explained on that page. >
Linux regression tracking (Thorsten Leemhuis)
July 11, 2023, 1:56 p.m. UTC |
#9
Addressed
Unaddressed
On 11.07.23 15:40, Benjamin Tissoires wrote: > On Tue, Jul 11, 2023 at 3:10 PM Linux regression tracking (Thorsten > Leemhuis) <regressions@leemhuis.info> wrote: >> >> On 26.06.23 16:02, Benjamin Tissoires wrote: >>> On Sun, Jun 25, 2023 at 10:30 AM Bastien Nocera <hadess@hadess.net> wrote: >>>> On Fri, 2023-06-23 at 10:37 +0200, Benjamin Tissoires wrote: >>>>> On Jun 21 2023, Greg KH wrote: >>>>>> On Wed, Jun 21, 2023 at 11:42:30AM +0200, Benjamin Tissoires wrote: >>>>>>> Make the code looks less like Pascal. >>>>>>> >>>>>>> Extract the internal code inside a helper function, fix the >>>>>>> initialization of the parameters used in the helper function >>>>>>> (`hidpp->answer_available` was not reset and `*response` wasn't >>>>>>> too), >>>>>>> and use a `do {...} while();` loop. >>>>>>> >>>>>>> Fixes: 586e8fede795 ("HID: logitech-hidpp: Retry commands when >>>>>>> device is busy") >>>>>>> Cc: stable@vger.kernel.org >>>>>>> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> >>>>>>> --- >>>>>>> as requested by >>>>>>> https://lore.kernel.org/all/CAHk-=wiMbF38KCNhPFiargenpSBoecSXTLQACKS2UMyo_Vu2ww@mail.gmail.com/ >>>>>>> This is a rewrite of that particular piece of code. >>>>>>> --- >>>>>>> drivers/hid/hid-logitech-hidpp.c | 102 +++++++++++++++++++++++-- >>>>>>> -------------- >>>>>>> 1 file changed, 61 insertions(+), 41 deletions(-) >>> [...] >>> >>> Some people on the Bz were able to reproduce with multiple reboots. >>> But it's not as urgent as previously, and we were close to the 6.4 >>> final when I sent it. I'll make sure this goes into 6.5 and gets >>> proper stable backports FWIW. >> >> Did that happen? Doesn't look like it from here, but maybe I'm missing >> something. Where there maybe other changes to resolve the remaining >> problems some users encounter sporadically since the urgent fixes went in? > > No, there were no other changes that could have solved this. I guess > the randomness of the problem makes it way harder to detect and to > reproduce. > > I'll send a v2 of that patch with the reviews today or tomorrow and we > can probably get it through the current 6.5 cycle. Great, many thx! Ciao, Thorsten
diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index dfe8e09a18de..3d1ffe199f08 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -275,21 +275,20 @@ static int __hidpp_send_report(struct hid_device *hdev, } /* - * hidpp_send_message_sync() returns 0 in case of success, and something else - * in case of a failure. - * - If ' something else' is positive, that means that an error has been raised - * by the protocol itself. - * - If ' something else' is negative, that means that we had a classic error - * (-ENOMEM, -EPIPE, etc...) + * Effectively send the message to the device, waiting for its answer. + * + * Must be called with hidpp->send_mutex locked + * + * Same return protocol than hidpp_send_message_sync(): + * - success on 0 + * - negative error means transport error + * - positive value means protocol error */ -static int hidpp_send_message_sync(struct hidpp_device *hidpp, +static int __do_hidpp_send_message_sync(struct hidpp_device *hidpp, struct hidpp_report *message, struct hidpp_report *response) { - int ret = -1; - int max_retries = 3; - - mutex_lock(&hidpp->send_mutex); + int ret; hidpp->send_receive_buf = response; hidpp->answer_available = false; @@ -300,41 +299,62 @@ static int hidpp_send_message_sync(struct hidpp_device *hidpp, */ *response = *message; - for (; max_retries != 0 && ret; max_retries--) { - ret = __hidpp_send_report(hidpp->hid_dev, message); + ret = __hidpp_send_report(hidpp->hid_dev, message); + if (ret) { + dbg_hid("__hidpp_send_report returned err: %d\n", ret); + memset(response, 0, sizeof(struct hidpp_report)); + return ret; + } - if (ret) { - dbg_hid("__hidpp_send_report returned err: %d\n", ret); - memset(response, 0, sizeof(struct hidpp_report)); - break; - } + if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, + 5*HZ)) { + dbg_hid("%s:timeout waiting for response\n", __func__); + memset(response, 0, sizeof(struct hidpp_report)); + return -ETIMEDOUT; + } - if (!wait_event_timeout(hidpp->wait, hidpp->answer_available, - 5*HZ)) { - dbg_hid("%s:timeout waiting for response\n", __func__); - memset(response, 0, sizeof(struct hidpp_report)); - ret = -ETIMEDOUT; - break; - } + if (response->report_id == REPORT_ID_HIDPP_SHORT && + response->rap.sub_id == HIDPP_ERROR) { + ret = response->rap.params[1]; + dbg_hid("%s:got hidpp error %02X\n", __func__, ret); + return ret; + } - if (response->report_id == REPORT_ID_HIDPP_SHORT && - response->rap.sub_id == HIDPP_ERROR) { - ret = response->rap.params[1]; - dbg_hid("%s:got hidpp error %02X\n", __func__, ret); + if ((response->report_id == REPORT_ID_HIDPP_LONG || + response->report_id == REPORT_ID_HIDPP_VERY_LONG) && + response->fap.feature_index == HIDPP20_ERROR) { + ret = response->fap.params[1]; + dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret); + return ret; + } + + return 0; +} + +/* + * hidpp_send_message_sync() returns 0 in case of success, and something else + * in case of a failure. + * - If ' something else' is positive, that means that an error has been raised + * by the protocol itself. + * - If ' something else' is negative, that means that we had a classic error + * (-ENOMEM, -EPIPE, etc...) + */ +static int hidpp_send_message_sync(struct hidpp_device *hidpp, + struct hidpp_report *message, + struct hidpp_report *response) +{ + int ret; + int max_retries = 3; + + mutex_lock(&hidpp->send_mutex); + + do { + ret = __do_hidpp_send_message_sync(hidpp, message, response); + if (ret != HIDPP20_ERROR_BUSY) break; - } - if ((response->report_id == REPORT_ID_HIDPP_LONG || - response->report_id == REPORT_ID_HIDPP_VERY_LONG) && - response->fap.feature_index == HIDPP20_ERROR) { - ret = response->fap.params[1]; - if (ret != HIDPP20_ERROR_BUSY) { - dbg_hid("%s:got hidpp 2.0 error %02X\n", __func__, ret); - break; - } - dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret); - } - } + dbg_hid("%s:got busy hidpp 2.0 error %02X, retrying\n", __func__, ret); + } while (--max_retries); mutex_unlock(&hidpp->send_mutex); return ret;