Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3624457rdh; Thu, 28 Sep 2023 18:46:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFiD0EYhDgphROVxhtrX+W0nkR0j5Q1yI7b80rtHB6v+aYgDpWFy4yUt3PrrcddW3a7qOKl X-Received: by 2002:a05:6a00:1352:b0:68a:6d1a:b812 with SMTP id k18-20020a056a00135200b0068a6d1ab812mr3581908pfu.9.1695951962877; Thu, 28 Sep 2023 18:46:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695951962; cv=none; d=google.com; s=arc-20160816; b=IXXPe9vhuzFPzMiRdQQCcrovrJGg920jevuG1klCTbCl7IoiDDdjVLQJU19Z6dpdec SnYjXIX72zDK/gJclXeazrVMdgKyZqYPWYXX4Bja6KFrIkNWe50YymC1pY18Oq3yO0qR /08habQ3BJ+cQEQPuN84btE7IevVZeI5NYj2RdEBl8JpTJqaBzgtuMUkC6jPTiZ7HX7q 4ZQlYJPXW0XfMHoBfddo2MmD8SmVBUhFAqqZAl0QzbP/XP+ZVyT42TXacBZ90DGdIfJQ FfxSddczTA/9OUemln4xyHPiFiCxNj/o51exmFmPaGVM43BwPgvG5MBA5hyB2PMv6fYa LsQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:message-id:user-agent :references:in-reply-to:subject:cc:to:from:date:mime-version :dkim-signature; bh=zrv40APT9E/B6+ncIzsM8oariWwXOpk9h2J8tU7f20A=; fh=ru11/NaC3dhIONNE6v2KMsZuHaFJ6l2RzEqTXTh+Dno=; b=DdFQG6mUUIHfOmHXmrxop+pEKS19jLGdIEOsOguy7mFyhDdxo2EV6TORzJ9ck3iC1Z SOSnptVPQgqJQDbCOEtNPAhxjipOkuhBPGolFYAIwgBYhlVM6KSnGuWbnPeNnQLUMU/b iIGzqerrDLy3iw0xQIq2biLvy3hFucQaarS+6YRJQVos4TUj6Cduonz57y3XwNmKqW4j B8gf5d3GGDAIPyqxql0ULExIIILXwiRK3x455iNlPGDHJ0XfxKqjuirfRKuDOz0MOvpP d3Dshj45ktTqe0xn5iRkJpJ0PT1sjEdqbZkf8+UBY+qxHMISeMfQ7/uCpdHNva632X0x 6BPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lentin.co.uk header.s=mythic-beasts-k1 header.b=DbkohBxC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id d3-20020a633603000000b00579ab302fd2si14100209pga.814.2023.09.28.18.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 18:46:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@lentin.co.uk header.s=mythic-beasts-k1 header.b=DbkohBxC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 9283D82E4172; Thu, 28 Sep 2023 14:07:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232262AbjI1VHA (ORCPT + 99 others); Thu, 28 Sep 2023 17:07:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232220AbjI1VG7 (ORCPT ); Thu, 28 Sep 2023 17:06:59 -0400 Received: from mx1.mythic-beasts.com (mx1.mythic-beasts.com [IPv6:2a00:1098:0:86:1000:0:2:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D245180; Thu, 28 Sep 2023 14:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lentin.co.uk; s=mythic-beasts-k1; h=Subject:To:From:Date; bh=zrv40APT9E/B6+ncIzsM8oariWwXOpk9h2J8tU7f20A=; b=DbkohBxC+L/E/e6L1SRbyQ6qy6 uh4CP3lVZjdxUPN7j3N+jheKJrS4FJ5+OBownO7FzfVzdY0aRiSiSEQ5azCIftF/4fJX52am+xbvl gk3runlcC8BDTsyYLEKTN3guFTFn8yYbFCzEPlpjocfZOt+lodx4kR6k67QjVNVac7QT1na+o1T+q n4LV2nugzzyus8srBTAvJvbnbVHcCOsuBztWxlkwUdbLvYH8E0IXZdkHP4syOELvilGu0/hOSdzhp oNkoDezlqPqj9MXpLg9rbnBt6JnCIE6/RVFOZc4xoiZKoGLLIYy6Ckq3SNRdbvmZqEoZHENB89DMA S99lNHMA==; Received: by mailhub-cam-d.mythic-beasts.com with esmtpa (Exim 4.94.2) (envelope-from ) id 1qlyDb-001Et6-Hh; Thu, 28 Sep 2023 22:06:43 +0100 MIME-Version: 1.0 Date: Thu, 28 Sep 2023 22:06:24 +0100 From: Jamie Lentin To: Martin Kepplinger Cc: jikos@kernel.org, benjamin.tissoires@redhat.com, linux-kernel@vger.kernel.org, linux-input@vger.kernel.org Subject: Re: [RFC PATCH 2/2] hid: lenovo: move type checks to lenovo_features_set_cptkbd() In-Reply-To: <137ee9ed434fe98fd773cd27895afc564f92a23c.camel@posteo.de> References: <140b721bc345a846863a37ebf17c3174@lentin.co.uk> <20230925102302.13094-1-martink@posteo.de> <20230925102302.13094-2-martink@posteo.de> <137ee9ed434fe98fd773cd27895afc564f92a23c.camel@posteo.de> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <6adc3e66402f38258eae3a044db9ee11@lentin.co.uk> X-Sender: jm@lentin.co.uk Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 14:07:23 -0700 (PDT) On 2023-09-27 12:20, Martin Kepplinger wrote: > Am Mittwoch, dem 27.09.2023 um 09:19 +0100 schrieb Jamie Lentin: >> On 2023-09-25 11:23, Martin Kepplinger wrote: >> > These custom commands will be sent to both the USB keyboard & mouse >> > devices but only the mouse will respond. Avoid sending known- >> > useless >> > messages by always prepending the filter before sending them. >> > >> > Suggested-by: Jamie Lentin >> > Signed-off-by: Martin Kepplinger >> > --- >> >  drivers/hid/hid-lenovo.c | 27 +++++++++------------------ >> >  1 file changed, 9 insertions(+), 18 deletions(-) >> > >> > diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c >> > index 29aa6d372bad..922f3e5462f4 100644 >> > --- a/drivers/hid/hid-lenovo.c >> > +++ b/drivers/hid/hid-lenovo.c >> > @@ -521,6 +521,14 @@ static void lenovo_features_set_cptkbd(struct >> > hid_device *hdev) >> >         int ret; >> >         struct lenovo_drvdata *cptkbd_data = hid_get_drvdata(hdev); >> > >> > +       /* All the custom action happens on the USBMOUSE device for >> > USB */ >> > +       if (((hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD) || >> > +           (hdev->product == USB_DEVICE_ID_LENOVO_TPIIUSBKBD)) && >> > +           hdev->type != HID_TYPE_USBMOUSE) { >> > +               hid_dbg(hdev, "Ignoring keyboard half of >> > device\n"); >> > +               return; >> > +       } >> > + >> >         /* >> >          * Tell the keyboard a driver understands it, and turn F7, >> > F9, F11 >> > into >> >          * regular keys >> > @@ -1122,14 +1130,6 @@ static int lenovo_probe_cptkbd(struct >> > hid_device >> > *hdev) >> >         int ret; >> >         struct lenovo_drvdata *cptkbd_data; >> > >> > -       /* All the custom action happens on the USBMOUSE device for >> > USB */ >> > -       if (((hdev->product == USB_DEVICE_ID_LENOVO_CUSBKBD) || >> > -           (hdev->product == USB_DEVICE_ID_LENOVO_TPIIUSBKBD)) && >> > -           hdev->type != HID_TYPE_USBMOUSE) { >> > -               hid_dbg(hdev, "Ignoring keyboard half of >> > device\n"); >> > -               return 0; >> > -       } >> > - >> >> I like the idea of doing it once then forgetting about it, but >> removing >> this will mean that the "keyboard half" will have it's own set of >> non-functional sysfs parameters I think? Currently:- >> >> # evtest >>    . . . >> /dev/input/event10:     ThinkPad Compact Bluetooth Keyboard with >> TrackPoint >> /dev/input/event11:     Lenovo ThinkPad Compact USB Keyboard with >> TrackPoint >> /dev/input/event12:     Lenovo ThinkPad Compact USB Keyboard with >> TrackPoint >> >> # ls -1 /sys/class/input/event*/device/device/fn_lock >> /sys/class/input/event10/device/device/fn_lock >> /sys/class/input/event12/device/device/fn_lock >> >> (note 11 is missing.) >> >> I think the easiest (but ugly) thing to do is to copy-paste this lump >> of >> code to the top of lenovo_reset_resume. >> Cheers, >> >> >         cptkbd_data = devm_kzalloc(&hdev->dev, >> >                                         sizeof(*cptkbd_data), >> >                                         GFP_KERNEL); >> > @@ -1264,16 +1264,7 @@ static int lenovo_probe(struct hid_device >> > *hdev, >> >  #ifdef CONFIG_PM >> >  static int lenovo_reset_resume(struct hid_device *hdev) >> >  { >> > -       switch (hdev->product) { >> > -       case USB_DEVICE_ID_LENOVO_CUSBKBD: >> > -               if (hdev->type == HID_TYPE_USBMOUSE) { >> > -                       lenovo_features_set_cptkbd(hdev); >> > -               } >> > - >> > -               break; >> > -       default: >> > -               break; >> > -       } >> > +       lenovo_features_set_cptkbd(hdev); > > ok. ignore my change (this whole patch) and look at your addition here, > don't you already make sure only the mouse-part gets the messages? you > just write switch()case instead of if(); what do you think is missing > here? Correct, this switch statement() that you're removing in this patch already does exactly this, so replacing it with the if()-and-return-early block would result in equivalent code (ignoring the Trackpoint keyboard II). That suggestion wasn't the most helpful of mine, sorry! The reason I originally used a switch here is for symmetry with lenovo_probe(), lenovo_remove(), etc. It might some day be useful to add something like: case USB_DEVICE_ID_LENOVO_X1_TAB: lenovo_reset_resume_tp10ubkbd(hdev); break; ...to the switch. For completeness, lenovo_reset_resume() should probably call a separate lenovo_reset_resume_cptkbd() that does the work. For just 3 lines of code it didn't seem worth it at the time though. Cheers, > > thanks, > martin > >> > >> >         return 0; >> >  }