Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1280542rdb; Fri, 1 Dec 2023 11:37:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHzd7it+nrusgCXgch+NNfv9Hk1a9UOmoUYTeeOWE5dFVmGCRCPYshNGUelQePBgKgeN09k X-Received: by 2002:a17:90b:38c8:b0:285:a179:7177 with SMTP id nn8-20020a17090b38c800b00285a1797177mr31912pjb.44.1701459076431; Fri, 01 Dec 2023 11:31:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701459076; cv=none; d=google.com; s=arc-20160816; b=iyAv0ICufxCSWWfkh15l8XsS9zUTf0+jBwrmN8xiilCUi8Bgde8XT5+IfqHmUuPeOi oyKNySGFI+TzHMJJJ1rJeIW21rPqsP97pwrMlrlytDBtkJXYCFLk5QjI1FXR97Cqn1CT 9ZYvuLhNIx4MliKrj/m+gq17EOpA8vwG69/usPL3mbQcGjvMKfk1lZky0As/0LyelPCh knrY0Mf3gvRM47Kjle2wF5axcHSBfvt+nn9j69Qofsha8iwFyiNmdelUHyIl3mlEvuqE /NDW0Sok+NOUTVDlTm8+PSoN2ywfy/YSgdb404qRxXvnxgrg/ZvP4xSKD35U7Y54w8nm DtBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=oQhax8HmaO4KSHkd1l+8SuBSnKVWOqBpGYH1jT1oUiA=; fh=lf0n/QS9klCyicBDvlWHAnp4/yFiGP+S/N1+TL2ZW80=; b=YLQEnyHwVK4BRPPHoICkmJqWCqRSNzHQFOb1jDaPum1KD3zddAuyUPo8ACXsfBC3tm Xt8Kng4Yv3XZ0OaaLO5RVzPe2cQ1UDQxVuWztZm0aO/Cn+1r2GIT3krwgrSxdjmbuh4z qnbcCIhirZYkAJu+Rjb5udehok8hxDRQk8LTz3PKYLXQLo6Q2dFuLro+ryNWAU3wGUg6 0in2P8o+GmIhP4ifZ5tS8E2MW4mfKtIrKHe7uAhakdw4Yyp9iHn01PVqtOyWd3rCOJwD rDWaWygS7wgTMW1ojsv5dQ94Z4a+6WooJE9+zgs4bIEQgwmpZBMwaYVJiMkOc5kN97Mv G6hw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id ci1-20020a17090afc8100b0028665a21ec8si271605pjb.41.2023.12.01.11.31.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 11:31:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=harvard.edu Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id CD21A8250DFE; Fri, 1 Dec 2023 11:30:55 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379522AbjLATag (ORCPT + 99 others); Fri, 1 Dec 2023 14:30:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379411AbjLATaf (ORCPT ); Fri, 1 Dec 2023 14:30:35 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 09494128 for ; Fri, 1 Dec 2023 11:30:41 -0800 (PST) Received: (qmail 298611 invoked by uid 1000); 1 Dec 2023 14:30:41 -0500 Date: Fri, 1 Dec 2023 14:30:41 -0500 From: Alan Stern To: Douglas Anderson Cc: linux-usb@vger.kernel.org, Greg Kroah-Hartman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Grant Grundler , Hayes Wang , Simon Horman , =?iso-8859-1?Q?Bj=F8rn?= Mork , netdev@vger.kernel.org, Brian Geffon , linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration() Message-ID: <0ca93d42-d650-405f-8acd-075132b8ac14@rowland.harvard.edu> References: <20231201183113.343256-1-dianders@chromium.org> <20231201102946.v2.2.Iade5fa31997f1a0ca3e1dec0591633b02471df12@changeid> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231201102946.v2.2.Iade5fa31997f1a0ca3e1dec0591633b02471df12@changeid> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 fry.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 (fry.vger.email [0.0.0.0]); Fri, 01 Dec 2023 11:30:56 -0800 (PST) On Fri, Dec 01, 2023 at 10:29:51AM -0800, Douglas Anderson wrote: > For some USB devices we might want to do something different for > usb_choose_configuration(). One example here is the r8152 driver where > we want to end up using the vendor driver with the preferred > interface. > > The r8152 driver tried to make things work by implementing a USB > generic_subclass driver and then overriding the normal config > selection after it happened. This is less than ideal and also caused > breakage if someone deauthorized and re-authorized the USB device > because the USB core ended up going back to it's default logic for > choosing the best config. I made an attempt to fix this [1] but it was > a bit ugly. > > Let's do this better and allow USB generic_subclass drivers to > override usb_choose_configuration(). > > [1] https://lore.kernel.org/r/20231130154337.1.Ie00e07f07f87149c9ce0b27ae4e26991d307e14b@changeid > > Suggested-by: Alan Stern > Signed-off-by: Douglas Anderson > --- Reviewed-by: Alan Stern > Changes in v2: > - ("Allow subclassed USB drivers to override ...") new for v2. > > drivers/usb/core/generic.c | 7 +++++++ > include/linux/usb.h | 6 ++++++ > 2 files changed, 13 insertions(+) > > diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c > index 740342a2812a..dcb897158228 100644 > --- a/drivers/usb/core/generic.c > +++ b/drivers/usb/core/generic.c > @@ -59,10 +59,17 @@ int usb_choose_configuration(struct usb_device *udev) > int num_configs; > int insufficient_power = 0; > struct usb_host_config *c, *best; > + struct usb_device_driver *udriver = to_usb_device_driver(udev->dev.driver); > > if (usb_device_is_owned(udev)) > return 0; > > + if (udriver->choose_configuration) { > + i = udriver->choose_configuration(udev); > + if (i >= 0) > + return i; > + } > + > best = NULL; > c = udev->config; > num_configs = udev->descriptor.bNumConfigurations; > diff --git a/include/linux/usb.h b/include/linux/usb.h > index 8c61643acd49..618e5a0b1a22 100644 > --- a/include/linux/usb.h > +++ b/include/linux/usb.h > @@ -1264,6 +1264,9 @@ struct usb_driver { > * module is being unloaded. > * @suspend: Called when the device is going to be suspended by the system. > * @resume: Called when the device is being resumed by the system. > + * @choose_configuration: If non-NULL, called instead of the default > + * usb_choose_configuration(). If this returns an error then we'll go > + * on to call the normal usb_choose_configuration(). > * @dev_groups: Attributes attached to the device that will be created once it > * is bound to the driver. > * @drvwrap: Driver-model core structure wrapper. > @@ -1287,6 +1290,9 @@ struct usb_device_driver { > > int (*suspend) (struct usb_device *udev, pm_message_t message); > int (*resume) (struct usb_device *udev, pm_message_t message); > + > + int (*choose_configuration) (struct usb_device *udev); > + > const struct attribute_group **dev_groups; > struct usbdrv_wrap drvwrap; > const struct usb_device_id *id_table; > -- > 2.43.0.rc2.451.g8631bc7472-goog >