All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maxim Mikityanskiy <maxtram95@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
	"Bjørn Mork" <bjorn@mork.no>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Hayes Wang" <hayeswang@realtek.com>
Cc: Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Douglas Anderson <dianders@chromium.org>,
	Grant Grundler <grundler@chromium.org>,
	linux-usb@vger.kernel.org, netdev@vger.kernel.org,
	Maxim Mikityanskiy <maxtram95@gmail.com>
Subject: [PATCH net 2/2] r8152: Switch to using choose_configuration
Date: Sun, 24 Dec 2023 01:35:23 +0200	[thread overview]
Message-ID: <20231223233523.4411-3-maxtram95@gmail.com> (raw)
In-Reply-To: <20231223233523.4411-1-maxtram95@gmail.com>

With the introduction of r8152-cfgselector, the following regression
appeared on machines that use usbguard: the netdev appears only when the
USB device is inserted the first time (before the module is loaded), but
on the second and next insertions no netdev is registered.

It happens because the device is probed as unauthorized, and usbguard
gives it an authorization a moment later. If the module is not loaded,
it's normally loaded slower than the authorization is given, and
everything works. If the module is already loaded, the cfgselector's
probe function runs first, but then usb_authorize_device kicks in and
changes the configuration to something chosen by the standard
usb_choose_configuration. rtl8152_probe refuses to probe non-vendor
configurations, and the user ends up without a netdev.

The previous commit added possibility to override
usb_choose_configuration. Use it to fix the bug and pick the right
configuration on both probe and authorization.

Fixes: ec51fbd1b8a2 ("r8152: add USB device driver for config selection")
Signed-off-by: Maxim Mikityanskiy <maxtram95@gmail.com>
---
 drivers/net/usb/r8152.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 9bf2140fd0a1..f0ac31a94f3c 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -10070,6 +10070,11 @@ static struct usb_driver rtl8152_driver = {
 };
 
 static int rtl8152_cfgselector_probe(struct usb_device *udev)
+{
+	return 0;
+}
+
+static int rtl8152_cfgselector_choose_configuration(struct usb_device *udev)
 {
 	struct usb_host_config *c;
 	int i, num_configs;
@@ -10078,7 +10083,7 @@ static int rtl8152_cfgselector_probe(struct usb_device *udev)
 	 * driver supports it.
 	 */
 	if (__rtl_get_hw_ver(udev) == RTL_VER_UNKNOWN)
-		return 0;
+		return -EOPNOTSUPP;
 
 	/* The vendor mode is not always config #1, so to find it out. */
 	c = udev->config;
@@ -10094,20 +10099,15 @@ 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 -EOPNOTSUPP;
 
-	return 0;
+	return c->desc.bConfigurationValue;
 }
 
 static struct usb_device_driver rtl8152_cfgselector_driver = {
 	.name =		MODULENAME "-cfgselector",
 	.probe =	rtl8152_cfgselector_probe,
+	.choose_configuration = rtl8152_cfgselector_choose_configuration,
 	.id_table =	rtl8152_table,
 	.generic_subclass = 1,
 	.supports_autosuspend = 1,
-- 
2.43.0


  parent reply	other threads:[~2023-12-23 23:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-23 23:35 [PATCH net 0/2] r8152: Fix a regression with usbguard Maxim Mikityanskiy
2023-12-23 23:35 ` [PATCH net 1/2] USB: Allow usb_device_driver to override usb_choose_configuration Maxim Mikityanskiy
2023-12-23 23:35 ` Maxim Mikityanskiy [this message]
2023-12-26  7:18   ` [PATCH net 2/2] r8152: Switch to using choose_configuration Grant Grundler
2023-12-26  7:42     ` Grant Grundler
2023-12-26 10:21       ` Maxim Mikityanskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231223233523.4411-3-maxtram95@gmail.com \
    --to=maxtram95@gmail.com \
    --cc=bjorn@mork.no \
    --cc=davem@davemloft.net \
    --cc=dianders@chromium.org \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=grundler@chromium.org \
    --cc=hayeswang@realtek.com \
    --cc=kuba@kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.