From patchwork Fri Dec 1 18:29:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 172622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1331995vqy; Fri, 1 Dec 2023 10:32:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYv8G9g4quEQnLgS8ZaM4xAEpnjYn84wRZbFv/QqNEOUPifSLB0nS2liu7uvhFfJIDVorM X-Received: by 2002:a17:902:ea05:b0:1cf:d52a:2247 with SMTP id s5-20020a170902ea0500b001cfd52a2247mr23839141plg.13.1701455526002; Fri, 01 Dec 2023 10:32:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701455525; cv=none; d=google.com; s=arc-20160816; b=StPq95xz0OL0Ov+O3xvu8SYlngHo1iTtyhMotOzy1NUeDStElfY1mhwUHAv4bnqHNm i6cSKDKw/KFUKlQUPI92OrpthgazL00R8Y/0h/wGBQm3wwZtW/7gRaJbX+YMv638YJux x/Ip8mL02QznJdCXyNVL8D+eeI5TEjJ55UrAecnHYOvJQzvRn3PMjo5zmRq5o0h+ZjFV lmewv8TYHI15Q/Rt8Lf+lVTqN6qJzStEOPp2fOiZeepZNByt51M4YNozdsxU8ljlvQsA 7WcPfv+svej148RR6h41ew8hqAI+9JCFYrk8vwxipPU0ZY9yxP8MDyXp7JFujZTV8HET n5mQ== 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=V5Q+AM+DhOXR89Ju18vzTGC3wrGXus7g2e66yEQ6u/o=; fh=pnJJeP49VWXD+260X8SBmIMRXj/Czcwqqd/QjqxfLjM=; b=sIZz+up7xyx0wAb/2QL2VjQfpAWTKCw0j6hJL9nqikdGbLNktr738G4VvNnNqzAN1n mPp9jBjcD8d39MPpDvzB17XkX5icpQIYLFmjeZ7L26BU0fKWo/7rntIWdZf2jJk3Br/t wPEY05paP8lIumW7N5AtCGRG2HxjSZIWRVZBG6sKv81K9eYqdUMwYiAia0GtwXrwL642 oVj/SJEgaJd4oFDtNsRY3mk3Pp8V8AYltlDdB78NLATQE5bb0PHTyTzXpaX2qrjB0C8L 7y+JWyaoaE1Akl3g5E8xIEY7++tD7l8tv5JxdBn3Ta/rAQaBPYNbhvXxT6+Xn7GmG7eO NeuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=bqnAI4pb; 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 z4-20020a170902ee0400b001cc47d6f4absi506819plb.107.2023.12.01.10.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 10:32:05 -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=bqnAI4pb; 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 4E477812D235; Fri, 1 Dec 2023 10:31:48 -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 S1379252AbjLASb0 (ORCPT + 99 others); Fri, 1 Dec 2023 13:31:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230364AbjLASbZ (ORCPT ); Fri, 1 Dec 2023 13:31:25 -0500 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26AE312A for ; Fri, 1 Dec 2023 10:31:31 -0800 (PST) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6cbd24d9557so1979018b3a.1 for ; Fri, 01 Dec 2023 10:31:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1701455490; x=1702060290; 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=V5Q+AM+DhOXR89Ju18vzTGC3wrGXus7g2e66yEQ6u/o=; b=bqnAI4pbt/2JXEGzsxEb82qCt80IXSahvoeovzNLUMK3RKJ0eZpYZpeeMkPrTFuYHw wkzmYMAFMBigaGHIToD8H1Mzq0zB/CkB/TVRC16pPdJv/mCV8h9Q5OlsfYWx5L71pKKL 4yBrFGesWjwRfQAOW6UCMTq29cHFFT1JMtw7s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701455490; x=1702060290; 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=V5Q+AM+DhOXR89Ju18vzTGC3wrGXus7g2e66yEQ6u/o=; b=oe5k/BSSdfZSX46DuJY1PPQglscX9HdM4OA2fq6TiFJYGL1U5WiNO9I92nUXWtizEY yF8O2EXqFpeN88SD1xrhJsPe5vP9Vxa8Kw8OvXBHomDmbkGOsQaIMOxMcpNAVLOKmIg5 EU4OnqJxLGsemQnRtu74o/9kACGUl3mx8+qNkRyQ0V5kqQwY+c0A4iDwy5mOQyW4/LmI TxEeAqW0qCm2eTJnVu2EXuDnZksArD31JUi305Bcm0Z3v2lOu8jnvoddVxsSMDk2L97o YkgiB9owuwS/w/Xkp7AOwOV0Zo0Za3IBQ55vaDruBkF//vG4+601REEUDh+vknxKiX5v 9EeA== X-Gm-Message-State: AOJu0Yy0Tje+4+LtaiIOIcQ5KCv1ff/g6HJaAhgA1nT3UmbjnUpnaMca D3naoz1CEceuVa0c7blzpSSaYg== X-Received: by 2002:a05:6a00:23c4:b0:6cb:cd66:2102 with SMTP id g4-20020a056a0023c400b006cbcd662102mr35720154pfc.4.1701455490601; Fri, 01 Dec 2023 10:31:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 10:31:30 -0800 (PST) From: Douglas Anderson To: linux-usb@vger.kernel.org, Greg Kroah-Hartman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Grant Grundler , Hayes Wang , Simon Horman , =?utf-8?q?Bj=C3=B8rn_Mork?= , netdev@vger.kernel.org, Brian Geffon , Alan Stern , Douglas Anderson , Hans de Goede , Heikki Krogerus , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe() Date: Fri, 1 Dec 2023 10:29:50 -0800 Message-ID: <20231201102946.v2.1.I7ea0dd55ee2acdb48b0e6d28c1a704ab2c29206f@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 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=unavailable 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: 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:31:49 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784105429736670288 X-GMAIL-MSGID: 1784105429736670288 There's no real reason that subclassed USB drivers _need_ to define probe() since they might want to subclass for some other reason. Make it optional to define probe() if we're a generic_subclass. Signed-off-by: Douglas Anderson Reviewed-by: Alan Stern Reviewed-by: Grant Grundler --- Changes in v2: - ("Don't force USB generic_subclass drivers to define ...") new for v2. drivers/usb/core/driver.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c index f58a0299fb3b..1dc0c0413043 100644 --- a/drivers/usb/core/driver.c +++ b/drivers/usb/core/driver.c @@ -290,7 +290,10 @@ static int usb_probe_device(struct device *dev) * specialised device drivers prior to setting the * use_generic_driver bit. */ - error = udriver->probe(udev); + if (udriver->probe) + error = udriver->probe(udev); + else if (!udriver->generic_subclass) + error = -EINVAL; if (error == -ENODEV && udriver != &usb_generic_driver && (udriver->id_table || udriver->match)) { udev->use_generic_driver = 1; From patchwork Fri Dec 1 18:29:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 172621 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp1331868vqy; Fri, 1 Dec 2023 10:31:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IHntOZjlGTAthwbfDNZOkJus9Hrhfm7BYmtoI4xXEXQCjboACKtOkD0iTrOu5AIzEPF3YuK X-Received: by 2002:a05:6a20:94cc:b0:18b:b02d:8b6 with SMTP id ht12-20020a056a2094cc00b0018bb02d08b6mr28458754pzb.23.1701455511725; Fri, 01 Dec 2023 10:31:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701455511; cv=none; d=google.com; s=arc-20160816; b=PX3HVtY4/MRtWzzyMe0Z8uFVUMbv+U8ybdoKgvAIB38y2PvG09lyoGxdYBylpnwxU8 C0ireTHrOTZsOxy1GQyKGEfi7Fyu1ceJGTFGmDHfwuFIAfqSWdq0yFZoDaQkSmWNSIQH IhxgWnTDKp4fkHyGekI3pPLXCr/Nxl1vaUi65TpcDJoCWjUgGGsSZ0F8rZ70cjurWmNZ MgFlh4tWluGsnAn+aaNo3v9yvyp+DhXH5AGU0C+Z5cKLNpJnz7P3laVOFWgbKTdEv/0q XOVNjH3XgTn8GhGBRx+zsGMwSppcvzT2Nwg8ncs477IoheaxkeQrPByC0oRcw6mYpLil dovQ== 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=sb01GRQ68eUgyc84/+R565jrsla/E08IXGMB+9OJhaQ=; fh=iXSZ4+xgje+bvqbZKxdNFAZWhAASZfFqGHQJnibrNCU=; b=ZGvSi9FOQC72BGa6JW2JhvOwkw7ZSfpavXSAL3Akas2VyyBQuHt+xNUQ47exWUbw3i wudrGCifcM4byy4LVdo1lWMnYYGZeXnDm9fOYfWbkuDTN9VnwWTyCzZ7V1LRf3mlg0f5 qQ7l6a0q5GEc37sRGBG92npRhaDQBwTyYCXr55GUqDlgfOrDGn2+NqVTBR6fRVs/7Xx1 zo6IwHB+G67lCN27/4wslBOs21S4PppPZRlZmVZ4LjyK6R5Sca1ea16PIbju4dCYEDM8 aS52PF1zWZZ5xjOBVRewCUm/e/oT/tWY0nCmBOIJHFyeAbdWIbdH2Ec14ds5aQ7eXYm4 +RyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CDMaHPE9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id h10-20020a056a00218a00b006cdf584699fsi2684720pfi.336.2023.12.01.10.31.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 10:31:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=CDMaHPE9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 1721B827A707; Fri, 1 Dec 2023 10:31:47 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232391AbjLASbh (ORCPT + 99 others); Fri, 1 Dec 2023 13:31:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379323AbjLASb2 (ORCPT ); Fri, 1 Dec 2023 13:31:28 -0500 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43F17129 for ; Fri, 1 Dec 2023 10:31:34 -0800 (PST) Received: by mail-pf1-x429.google.com with SMTP id d2e1a72fcca58-6cdd9c53282so2193100b3a.3 for ; 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=sb01GRQ68eUgyc84/+R565jrsla/E08IXGMB+9OJhaQ=; b=CDMaHPE9v+9nZO1+SszfsPXIqd5f9EKU4uSBGbv1Y4TY0nJrfMWfAWojTNRklK2zbC hR+5Yj8xV5FTAQgFbGKrhcgCqH2GfoamqawzP3Yk2fZV5Mz3MRIe3bJvEdBIV8bghoNk hZXDMoPP+Xpadr+B1n0cyypEy99oKiAsU5V0Y= 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=sb01GRQ68eUgyc84/+R565jrsla/E08IXGMB+9OJhaQ=; b=s76i6TRzBZjDDVwkabF4SQEgRXbEe3M1oJ5gFYJNsAzImTJQlMofJ76AQFEzVBOrOV +G3aR5i8ndhoy3ub4Obyq3riK/ShJWO7CUwPthiJcWmX1il0nstauraMWWy0P7HMLFb7 jol/JXSc8XS9RMkDmuNkOGb31as0KtKIrlDZTwSQWIK4AWRQUWFpm6dTQpzKC42fCWz/ nv8vaXk3CONysMT1eN/z7V5uvu3dAGTgV/jaM5tJIiuQntYJ8LQ1htQtwk9OtD8hcjQ9 oqyXF5u7EK8JtUvw+U/ghIqAY5J/h6DgN8AAQAAH51JaeGULh5PeeM3dPVbxww9AlVPQ bBUw== X-Gm-Message-State: AOJu0YyUp2ou98d60i6zKyHq34D7bNBfoEX28eoQR1VqKv8EO9Z8I6Su mWJb3E/yVqLy/Peu9PLaAvpg+A== X-Received: by 2002:a05:6a00:3016:b0:6cd:dc2e:a444 with SMTP id ay22-20020a056a00301600b006cddc2ea444mr8860209pfb.27.1701455492435; Fri, 01 Dec 2023 10:31:32 -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.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 10:31:31 -0800 (PST) From: Douglas Anderson To: linux-usb@vger.kernel.org, Greg Kroah-Hartman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Grant Grundler , Hayes Wang , Simon Horman , =?utf-8?q?Bj=C3=B8rn_Mork?= , netdev@vger.kernel.org, Brian Geffon , Alan Stern , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration() Date: Fri, 1 Dec 2023 10:29:51 -0800 Message-ID: <20231201102946.v2.2.Iade5fa31997f1a0ca3e1dec0591633b02471df12@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 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 groat.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 (groat.vger.email [0.0.0.0]); Fri, 01 Dec 2023 10:31:47 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784105414754993561 X-GMAIL-MSGID: 1784105414754993561 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; From patchwork Fri Dec 1 18:29:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 172623 Return-Path: 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 + 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 ); 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 ; Fri, 1 Dec 2023 10:31:34 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6cde14ff73bso1993202b3a.0 for ; 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 To: linux-usb@vger.kernel.org, Greg Kroah-Hartman , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Grant Grundler , Hayes Wang , Simon Horman , =?utf-8?q?Bj=C3=B8rn_Mork?= , netdev@vger.kernel.org, Brian Geffon , Alan Stern , Douglas Anderson , 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 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: 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 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 Signed-off-by: Douglas Anderson Reviewed-by: Grant Grundler Acked-by: Jakub Kicinski --- 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, };