From mboxrd@z Thu Jan 1 00:00:00 1970 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 8B555EB64D7 for ; Wed, 21 Jun 2023 10:52:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232634AbjFUKwK (ORCPT ); Wed, 21 Jun 2023 06:52:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231734AbjFUKvn (ORCPT ); Wed, 21 Jun 2023 06:51:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD4271BE6; Wed, 21 Jun 2023 03:50:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F1062614E9; Wed, 21 Jun 2023 10:50:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB37BC433C8; Wed, 21 Jun 2023 10:50:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1687344627; bh=cGQrS2SFrCOw8DMVAnIO4+fl2u2O+y02ZnnotmrAlDI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nG3Lb+8ZRwlReRXhUe9bnlJ/cH3779QLwSAvm9T8c0eCnkcx0Tp29YPVxvc0e7ep1 CuuFRPqzXv9l6vDxBjyCHtNmW28F5Dcn0MDwAjKYv9PH4EFcwyeuoj+LSrcv45HeIx NYwy3qlt8J6UPcvqCfVQbyLjQigXKA94bB9yCJYc= Date: Wed, 21 Jun 2023 12:50:21 +0200 From: Greg KH To: Benjamin Tissoires Cc: Filipe =?iso-8859-1?Q?La=EDns?= , Bastien Nocera , Jiri Kosina , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] HID: logitech-hidpp: rework one more time the retries attempts Message-ID: <2023062156-trespass-pandemic-7f4f@gregkh> References: <20230621-logitech-fixes-v1-1-32e70933c0b0@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230621-logitech-fixes-v1-1-32e70933c0b0@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 > --- > 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) ?