[net,v2,3/3] r8152: Choose our USB config with choose_configuration() rather than probe()
Message ID | 20231201102946.v2.3.Ie00e07f07f87149c9ce0b27ae4e26991d307e14b@changeid |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1332021vqy; Fri, 1 Dec 2023 10:32:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IEI7wEUpXnu4Oj7WGRLSC8SEEzEqAo94BVjzKrp/NEdWRTt/gZgwixR9l4aANKhDWhOZWTZ X-Received: by 2002:a05:6a00:1913:b0:6ce:d5f:dd62 with SMTP id y19-20020a056a00191300b006ce0d5fdd62mr1677433pfi.14.1701455528671; Fri, 01 Dec 2023 10:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701455528; cv=none; d=google.com; s=arc-20160816; b=WrFyZPTg4bweMxIohXoLMZO3jo8WReZf5KBEKnw0pUCvnQ3et+BVrXqztFmdiBgn3p gqz1LCphtJ7CPI68Kq+KXS/53GMplVMXmiC6nTTeHuJrWvDM17JOGcFkW1FD6tbVnSja 0ymTWSuTYyRb9Ic7oQq5kDKEp0POhEBwjcaso2XEqefZs/4k23Gz2fwBfMDYli6EaiAC 5VHNncPAqJqkLw3R96Wio53iiFbRycjVASFeW7MVdd1WGcP+y0VNmo9/xhoC62qdGdCe LnFpiYdjixpEDP2id29QgcUUjTMej/3VycAdRBilza0mS/g3HHoq7H/LGNWofc9OH6k9 o+EA== 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 :dkim-signature; bh=4QGkTsdRERlNpczcwqSp2Og8v+XNs9gRL2qzJvnknds=; fh=iXSZ4+xgje+bvqbZKxdNFAZWhAASZfFqGHQJnibrNCU=; b=nj+iGzrTsG4LqIy23TDYNX2VSUiXVFIxxQcULqNkk204Ny+//tcs262wy5gtTnhc2I m55SmHh7Mwx1PrOcXh2Pa0Oc98Ta4aZizEhajbWEYOYgHnqHOBg+4jbZBzXkGVDOP/y4 KmT6HJaPHV45PUwZfXmiS2mA8GEmqmfF345uEpTglbxj+dHfFeuwqaEkQOcrz4cBBRS8 BuTTrhZzBkXp2/ml0tGnQ/m1of8H2Uv9XTiUBM/GNHsSpNpye1427gBKdIxhm2eMWt+8 VqrfCugcS74O+C4eQH0vJoRdxN07MAqZrZ4TpYvVlG55kLtX29lfaToPYjENT2zWBref vLTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NAm7TJYY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u8-20020a6540c8000000b005add209e106si3481779pgp.442.2023.12.01.10.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 10:32:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NAm7TJYY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8F391812D23D; Fri, 1 Dec 2023 10:32:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbjLASbk (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Fri, 1 Dec 2023 13:31:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379334AbjLASb3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 1 Dec 2023 13:31:29 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDB58194 for <linux-kernel@vger.kernel.org>; Fri, 1 Dec 2023 10:31:34 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6cde14ff73bso1993202b3a.0 for <linux-kernel@vger.kernel.org>; Fri, 01 Dec 2023 10:31:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701455494; x=1702060294; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4QGkTsdRERlNpczcwqSp2Og8v+XNs9gRL2qzJvnknds=; b=NAm7TJYYWKXNyXJQqhfgCjmvkRz0pVGCxouKfwO38mMJeiJ23rVzMICF/GVfMZ8ppf XDm6mJRBLudjMjQjlp47m2wVOs4IifZCBN/9iMaEIbDOoAiAPXb3AFkjVjvVTzWBlTiZ GkP5lpvIVvdufNP1MS3ttUlFaQMJJJEgB4Q1g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701455494; x=1702060294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4QGkTsdRERlNpczcwqSp2Og8v+XNs9gRL2qzJvnknds=; b=LDCEHU328gzqq+mHG8TU7bbXMA7B8cHRsTLDy7CMiAOmLgxq46s0YjozfYLs5hXnpY A1nqnAMFOfU6Um4IGut3pR0kvK/Ot/OEnkphztktoI8uyPsP340iunUlYIPgjFP0JL7w lWpHuLFM4mQpM3KPzVhuSJQ+tQYjxbsnQ2sKucA/w3PqBZo56I77Ge4apQ9/jyZGuXcm PYgfOTVy+TQDPDRf+ASORaXCswNXosLhot1teivDaZrUxBmZ5MPmAKHr8Y5XEs7OiapF psW9REALrFtWVsYps9vwIV2a1i3NBsVnBI2RmdqjIB/qHUJro5r6i1Q8gnLW0QKMwP5H vYAA== X-Gm-Message-State: AOJu0YzincsHJsW4ZWejqZdr2wXMlB9Ln1Oz0nEaX2YYvXGtWv7q9cZh yz6HWb98elWGZzuWrWTM/sfHyA== X-Received: by 2002:a05:6a00:430e:b0:6cd:fe6e:ac9b with SMTP id cb14-20020a056a00430e00b006cdfe6eac9bmr3530436pfb.0.1701455494239; Fri, 01 Dec 2023 10:31:34 -0800 (PST) Received: from tictac2.mtv.corp.google.com ([2620:15c:9d:2:11eb:92ac:94e:c791]) by smtp.gmail.com with ESMTPSA id g11-20020a056a00078b00b006cdda10bdafsm3306926pfu.183.2023.12.01.10.31.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 10:31:33 -0800 (PST) From: Douglas Anderson <dianders@chromium.org> To: linux-usb@vger.kernel.org, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "David S . Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: Grant Grundler <grundler@chromium.org>, Hayes Wang <hayeswang@realtek.com>, Simon Horman <horms@kernel.org>, =?utf-8?q?Bj=C3=B8rn_Mork?= <bjorn@mork.no>, netdev@vger.kernel.org, Brian Geffon <bgeffon@google.com>, Alan Stern <stern@rowland.harvard.edu>, Douglas Anderson <dianders@chromium.org>, linux-kernel@vger.kernel.org Subject: [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe() Date: Fri, 1 Dec 2023 10:29:52 -0800 Message-ID: <20231201102946.v2.3.Ie00e07f07f87149c9ce0b27ae4e26991d307e14b@changeid> X-Mailer: git-send-email 2.43.0.rc2.451.g8631bc7472-goog In-Reply-To: <20231201183113.343256-1-dianders@chromium.org> References: <20231201183113.343256-1-dianders@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 01 Dec 2023 10:32:01 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784105432255359060 X-GMAIL-MSGID: 1784105432255359060 |
Series |
net: usb: r8152: Fix lost config across deauthorize+authorize
|
|
Commit Message
Doug Anderson
Dec. 1, 2023, 6:29 p.m. UTC
If you deauthorize the r8152 device (by writing 0 to the "authorized"
field in sysfs) and then reauthorize it (by writing a 1) then it no
longer works. This is because when you do the above we lose the
special configuration that we set in rtl8152_cfgselector_probe().
Deauthorizing causes the config to be set to -1 and then reauthorizing
runs the default logic for choosing the best config.
I made an attempt to fix it so that the config is kept across
deauthorizing / reauthorizing [1] but it was a bit ugly.
Let's instead use the new USB core feature to override
choose_configuration().
This patch relies upon the patches ("usb: core: Don't force USB
generic_subclass drivers to define probe()") and ("usb: core: Allow
subclassed USB drivers to override usb_choose_configuration()")
[1] https://lore.kernel.org/r/20231130154337.1.Ie00e07f07f87149c9ce0b27ae4e26991d307e14b@changeid
Fixes: ec51fbd1b8a2 ("r8152: add USB device driver for config selection")
Suggested-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---
Changes in v2:
- ("Choose our USB config with choose_configuration()...) new for v2.
drivers/net/usb/r8152.c | 16 +++++-----------
1 file changed, 5 insertions(+), 11 deletions(-)
Comments
On Fri, Dec 1, 2023 at 10:31 AM Douglas Anderson <dianders@chromium.org> wrote: > > If you deauthorize the r8152 device (by writing 0 to the "authorized" > field in sysfs) and then reauthorize it (by writing a 1) then it no > longer works. This is because when you do the above we lose the > special configuration that we set in rtl8152_cfgselector_probe(). > Deauthorizing causes the config to be set to -1 and then reauthorizing > runs the default logic for choosing the best config. > > I made an attempt to fix it so that the config is kept across > deauthorizing / reauthorizing [1] but it was a bit ugly. > > Let's instead use the new USB core feature to override > choose_configuration(). > > This patch relies upon the patches ("usb: core: Don't force USB > generic_subclass drivers to define probe()") and ("usb: core: Allow > subclassed USB drivers to override usb_choose_configuration()") > > [1] https://lore.kernel.org/r/20231130154337.1.Ie00e07f07f87149c9ce0b27ae4e26991d307e14b@changeid > > Fixes: ec51fbd1b8a2 ("r8152: add USB device driver for config selection") > Suggested-by: Alan Stern <stern@rowland.harvard.edu> > Signed-off-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: Grant Grundler <grundler@chromium.org> > --- > > Changes in v2: > - ("Choose our USB config with choose_configuration()...) new for v2. > > drivers/net/usb/r8152.c | 16 +++++----------- > 1 file changed, 5 insertions(+), 11 deletions(-) > > diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c > index 2c5c1e91ded6..0da723d11326 100644 > --- a/drivers/net/usb/r8152.c > +++ b/drivers/net/usb/r8152.c > @@ -10053,7 +10053,7 @@ static struct usb_driver rtl8152_driver = { > .disable_hub_initiated_lpm = 1, > }; > > -static int rtl8152_cfgselector_probe(struct usb_device *udev) > +static int rtl8152_cfgselector_choose_configuration(struct usb_device *udev) > { > struct usb_host_config *c; > int i, num_configs; > @@ -10080,19 +10080,13 @@ static int rtl8152_cfgselector_probe(struct usb_device *udev) > if (i == num_configs) > return -ENODEV; > > - if (usb_set_configuration(udev, c->desc.bConfigurationValue)) { > - dev_err(&udev->dev, "Failed to set configuration %d\n", > - c->desc.bConfigurationValue); > - return -ENODEV; > - } > - > - return 0; > + return c->desc.bConfigurationValue; > } > > static struct usb_device_driver rtl8152_cfgselector_driver = { > - .name = MODULENAME "-cfgselector", > - .probe = rtl8152_cfgselector_probe, > - .id_table = rtl8152_table, > + .name = MODULENAME "-cfgselector", > + .choose_configuration = rtl8152_cfgselector_choose_configuration, > + .id_table = rtl8152_table, > .generic_subclass = 1, > .supports_autosuspend = 1, > }; > -- > 2.43.0.rc2.451.g8631bc7472-goog >
On Fri, 1 Dec 2023 10:29:52 -0800 Douglas Anderson wrote: > If you deauthorize the r8152 device (by writing 0 to the "authorized" > field in sysfs) and then reauthorize it (by writing a 1) then it no > longer works. This is because when you do the above we lose the > special configuration that we set in rtl8152_cfgselector_probe(). > Deauthorizing causes the config to be set to -1 and then reauthorizing > runs the default logic for choosing the best config. > > I made an attempt to fix it so that the config is kept across > deauthorizing / reauthorizing [1] but it was a bit ugly. > > Let's instead use the new USB core feature to override > choose_configuration(). > > This patch relies upon the patches ("usb: core: Don't force USB > generic_subclass drivers to define probe()") and ("usb: core: Allow > subclassed USB drivers to override usb_choose_configuration()") Acked-by: Jakub Kicinski <kuba@kernel.org>
diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 2c5c1e91ded6..0da723d11326 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -10053,7 +10053,7 @@ static struct usb_driver rtl8152_driver = { .disable_hub_initiated_lpm = 1, }; -static int rtl8152_cfgselector_probe(struct usb_device *udev) +static int rtl8152_cfgselector_choose_configuration(struct usb_device *udev) { struct usb_host_config *c; int i, num_configs; @@ -10080,19 +10080,13 @@ static int rtl8152_cfgselector_probe(struct usb_device *udev) if (i == num_configs) return -ENODEV; - if (usb_set_configuration(udev, c->desc.bConfigurationValue)) { - dev_err(&udev->dev, "Failed to set configuration %d\n", - c->desc.bConfigurationValue); - return -ENODEV; - } - - return 0; + return c->desc.bConfigurationValue; } static struct usb_device_driver rtl8152_cfgselector_driver = { - .name = MODULENAME "-cfgselector", - .probe = rtl8152_cfgselector_probe, - .id_table = rtl8152_table, + .name = MODULENAME "-cfgselector", + .choose_configuration = rtl8152_cfgselector_choose_configuration, + .id_table = rtl8152_table, .generic_subclass = 1, .supports_autosuspend = 1, };