Message ID | 4809717.31r3eYUQgx@kreacher |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp73619wrr; Wed, 7 Dec 2022 01:23:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf6kWl0IJ3niEm/ikCnORqSsaZmkv+75j+GvhDlFIvBnj17y2TztU/Plc07g0cpzCJye5vbR X-Received: by 2002:a17:902:9a92:b0:189:9031:6758 with SMTP id w18-20020a1709029a9200b0018990316758mr13634650plp.138.1670404981536; Wed, 07 Dec 2022 01:23:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670404981; cv=none; d=google.com; s=arc-20160816; b=TLxvF3yxMhBB+ufzaLyjGbem0VMVvwo1G1gbiIMsIGbl0DxfhXqsfCxq607/0qWbWP B44vSjPNk/4stAAJRs/9s98rlTXd/irFyruSqUTj6wzB0msAZrIqHH/DlWajA7MfPIgZ 0OyJIOhe4IbmctaOrcA/4vVzQUEIQWGyv62suE8FhHdpbJz9rMXkCiUJVspDISllMRDW huKGl/uD/3s8anQYraFh9oNdYPZj31fkno5fzk8hIhXMZAZpj/R/513ElMezwpW3K8vL pmJPrI6qMjiiPQFOdoT+s/QiKGg7hgQRTBsE4i2IFnlFhii9PNQCNvJPMWBwwbvKY1rV 1ciQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LaFaI5kUp+ekQOEhR2qxNEZ4crNmcO/CaudvDetY2Z0=; b=MzPPeYjJm8vU2b0up0gPnMAW6GGU17xEXmMYACwbhcFMeZ6L5OS3JRVtPdGHsKkslZ piioAwSpEEts7AQceXFWr5TqhUPCC2gGOTyg93iVTMZBkiU/wsJUeREWh6Q+TJVcv/G+ R8IyAIxIiTL1dk+5uekygHlUqPIBKxTJ0lQQD3KdUfXOaAfLoJb5jqYw/oybgUb7RFqv fHwgTtrrbjTzoqbNiOYfzLdPggb4OL7TuoHRG/x530KHgovHNx+hPzLGouBiDhXvjlgH FYp6oHIKgxQl6VSctO5jE46h7xHXHj1z0sV2msRK7td+eoUWyIuaFXqnFn5YcB7kVpzr vEQw== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a22-20020a63e416000000b00478d902b3e1si5025803pgi.61.2022.12.07.01.22.45; Wed, 07 Dec 2022 01:23:01 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230163AbiLGJNx (ORCPT <rfc822;b08248@gmail.com> + 99 others); Wed, 7 Dec 2022 04:13:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230149AbiLGJNH (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 7 Dec 2022 04:13:07 -0500 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 753CC286F5; Wed, 7 Dec 2022 01:13:06 -0800 (PST) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.1.0) id 71a7a6d26ff50113; Wed, 7 Dec 2022 10:13:04 +0100 Received: from kreacher.localnet (unknown [213.134.169.108]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 22F24780872; Wed, 7 Dec 2022 10:13:04 +0100 (CET) Authentication-Results: v370.home.net.pl; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: v370.home.net.pl; spf=fail smtp.mailfrom=rjwysocki.net From: "Rafael J. Wysocki" <rjw@rjwysocki.net> To: Jiri Kosina <jikos@kernel.org>, Bastien Nocera <hadess@hadess.net> Cc: Filipe =?iso-8859-1?q?La=EDns?= <lains@riseup.net>, Benjamin Tissoires <benjamin.tissoires@redhat.com>, linux-input@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>, "Rafael J. Wysocki" <rafael@kernel.org>, Thorsten Leemhuis <regressions@leemhuis.info> Subject: [PATCH v1 1/2] HID: generic: Add ->match() check to __check_hid_generic() Date: Wed, 07 Dec 2022 10:11:50 +0100 Message-ID: <4809717.31r3eYUQgx@kreacher> In-Reply-To: <5647715.DvuYhMxLoT@kreacher> References: <2262737.ElGaqSPkdT@kreacher> <5647715.DvuYhMxLoT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 213.134.169.108 X-CLIENT-HOSTNAME: 213.134.169.108 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrudekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppedvudefrddufeegrdduieelrddutdeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvddufedrudefgedrudeiledruddtkedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepkedprhgtphhtthhopehjihhkohhssehkvghrnhgvlhdrohhrghdprhgtphhtthhopehhrgguvghssheshhgruggvshhsrdhnvghtpdhrtghpthhtoheplhgrihhnshesrhhishgvuhhprdhnvghtpdhrtghpthhtohepsggvnhhjrghmihhnrdhtihhsshhoihhrvghssehrvgguhhgrthdrtghomhdprhgtphhtthhopehlihhnuhigqdhinhhpuhhtsehvghgvrhdrkhgvrhhn vghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehrvghgrhgvshhsihhonhhssehlvggvmhhhuhhishdrihhnfhho X-DCC--Metrics: v370.home.net.pl 1024; Body=8 Fuz1=8 Fuz2=8 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham 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?1751546574043861452?= X-GMAIL-MSGID: =?utf-8?q?1751546574043861452?= |
Series |
HID: Fix regression resulting from commit 532223c8ac57
|
|
Commit Message
Rafael J. Wysocki
Dec. 7, 2022, 9:11 a.m. UTC
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Some special HID drivers (for example, hid-logitech-hidpp) use ->match() callbacks to reject specific devices that otherwise would match the driver's device ID list, with the expectation that those devices will be handled by some other drivers. However, this doesn't work if hid-generic is expected to bind to the given device, because its ->match() callback, hid_generic_match(), rejects all devices that match device ID lists of the other HID drivers regardless of what is returned by the other drivers' ->match() callbacks. To make it work, amend the function used by hid_generic_match() for checking an individual driver, __check_hid_generic(), with a check involving the given driver's ->match() callback, so 0 is returned when that callback rejects the device in question. Fixes: 532223c8ac57 ("HID: logitech-hidpp: Enable HID++ for all the Logitech Bluetooth devices") Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> --- drivers/hid/hid-generic.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Comments
On Wed, Dec 7, 2022 at 10:13 AM Rafael J. Wysocki <rjw@rjwysocki.net> wrote: > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > Some special HID drivers (for example, hid-logitech-hidpp) use ->match() > callbacks to reject specific devices that otherwise would match the > driver's device ID list, with the expectation that those devices will > be handled by some other drivers. However, this doesn't work if > hid-generic is expected to bind to the given device, because its > ->match() callback, hid_generic_match(), rejects all devices that match > device ID lists of the other HID drivers regardless of what is returned > by the other drivers' ->match() callbacks. Thanks Rafael for spotting that corner case in the ->match() processing. > > To make it work, amend the function used by hid_generic_match() for > checking an individual driver, __check_hid_generic(), with a check > involving the given driver's ->match() callback, so 0 is returned > when that callback rejects the device in question. Shouldn't we add that logic to hid_match_device() directly in hid-core.c instead? It feels wrong to have a function named "hid_match_device()" and have to manually call later "->match()" on the driver itself. Ack on the general idea anyway. > > Fixes: 532223c8ac57 ("HID: logitech-hidpp: Enable HID++ for all the Logitech Bluetooth devices") > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > --- > drivers/hid/hid-generic.c | 8 +++++++- > 1 file changed, 7 insertions(+), 1 deletion(-) > > Index: linux-pm/drivers/hid/hid-generic.c > =================================================================== > --- linux-pm.orig/drivers/hid/hid-generic.c > +++ linux-pm/drivers/hid/hid-generic.c > @@ -31,7 +31,13 @@ static int __check_hid_generic(struct de > if (hdrv == &hid_generic) > return 0; > > - return hid_match_device(hdev, hdrv) != NULL; > + if (!hid_match_device(hdev, hdrv)) > + return 0; > + > + if (hdrv->match) > + return hdrv->match(hdev, false); > + > + return 1; > } > > static bool hid_generic_match(struct hid_device *hdev, > > >
On Wed, Dec 7, 2022 at 10:27 AM Benjamin Tissoires <benjamin.tissoires@redhat.com> wrote: > > On Wed, Dec 7, 2022 at 10:13 AM Rafael J. Wysocki <rjw@rjwysocki.net> wrote: > > > > From: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > > > Some special HID drivers (for example, hid-logitech-hidpp) use ->match() > > callbacks to reject specific devices that otherwise would match the > > driver's device ID list, with the expectation that those devices will > > be handled by some other drivers. However, this doesn't work if > > hid-generic is expected to bind to the given device, because its > > ->match() callback, hid_generic_match(), rejects all devices that match > > device ID lists of the other HID drivers regardless of what is returned > > by the other drivers' ->match() callbacks. > > Thanks Rafael for spotting that corner case in the ->match() processing. > > > > > To make it work, amend the function used by hid_generic_match() for > > checking an individual driver, __check_hid_generic(), with a check > > involving the given driver's ->match() callback, so 0 is returned > > when that callback rejects the device in question. > > Shouldn't we add that logic to hid_match_device() directly in > hid-core.c instead? > It feels wrong to have a function named "hid_match_device()" and have > to manually call later "->match()" on the driver itself. Well, I've followed the pattern present in hid_device_probe(), where hid_match_device() is first called to check against the device ID list and then ->match() is invoked later only if that doesn't fail. Also changing hid_match_device() would change the way in which hid_bus_match() works and that may lead to subsequent regressions, potentially, so I'd rather avoid doing that ATM. > Ack on the general idea anyway. Thanks! > > > > Fixes: 532223c8ac57 ("HID: logitech-hidpp: Enable HID++ for all the Logitech Bluetooth devices") > > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> > > --- > > drivers/hid/hid-generic.c | 8 +++++++- > > 1 file changed, 7 insertions(+), 1 deletion(-) > > > > Index: linux-pm/drivers/hid/hid-generic.c > > =================================================================== > > --- linux-pm.orig/drivers/hid/hid-generic.c > > +++ linux-pm/drivers/hid/hid-generic.c > > @@ -31,7 +31,13 @@ static int __check_hid_generic(struct de > > if (hdrv == &hid_generic) > > return 0; > > > > - return hid_match_device(hdev, hdrv) != NULL; > > + if (!hid_match_device(hdev, hdrv)) > > + return 0; > > + > > + if (hdrv->match) > > + return hdrv->match(hdev, false); > > + > > + return 1; > > } > > > > static bool hid_generic_match(struct hid_device *hdev, > > > > > > >
Index: linux-pm/drivers/hid/hid-generic.c =================================================================== --- linux-pm.orig/drivers/hid/hid-generic.c +++ linux-pm/drivers/hid/hid-generic.c @@ -31,7 +31,13 @@ static int __check_hid_generic(struct de if (hdrv == &hid_generic) return 0; - return hid_match_device(hdev, hdrv) != NULL; + if (!hid_match_device(hdev, hdrv)) + return 0; + + if (hdrv->match) + return hdrv->match(hdev, false); + + return 1; } static bool hid_generic_match(struct hid_device *hdev,