netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize
@ 2023-12-01 18:29 Douglas Anderson
  2023-12-01 18:29 ` [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe() Douglas Anderson
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Douglas Anderson @ 2023-12-01 18:29 UTC (permalink / raw)
  To: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Grant Grundler, Hayes Wang, Simon Horman, Bjørn Mork, netdev,
	Brian Geffon, Alan Stern, Douglas Anderson, Hans de Goede,
	Heikki Krogerus, Rafael J. Wysocki, linux-kernel


This series fixes problems introduced by commit ec51fbd1b8a2 ("r8152:
add USB device driver for config selection") where the r8152 device
would stop functioning if you deauthorized it (by writing 0 to the
"authorized" field in sysfs) and then reauthorized it (by writing a
1).

In v1 this was just a single patch [1], but it's now a 3-patch series
and solves the problem in a much cleaner way, as suggested by Alan
Stern.

Since these three patches straddle the USB subsystem and the
networking subsystem then maintainers will (obviously) need to work
out a way for them to land. I don't have any strong suggestions here
so I'm happy to let the maintainers propose what they think will work
best.

[1] https://lore.kernel.org/r/20231130154337.1.Ie00e07f07f87149c9ce0b27ae4e26991d307e14b@changeid

Changes in v2:
- ("Don't force USB generic_subclass drivers to define ...") new for v2.
- ("Allow subclassed USB drivers to override ...") new for v2.
- ("Choose our USB config with choose_configuration()...) new for v2.

Douglas Anderson (3):
  usb: core: Don't force USB generic_subclass drivers to define probe()
  usb: core: Allow subclassed USB drivers to override
    usb_choose_configuration()
  r8152: Choose our USB config with choose_configuration() rather than
    probe()

 drivers/net/usb/r8152.c    | 16 +++++-----------
 drivers/usb/core/driver.c  |  5 ++++-
 drivers/usb/core/generic.c |  7 +++++++
 include/linux/usb.h        |  6 ++++++
 4 files changed, 22 insertions(+), 12 deletions(-)

-- 
2.43.0.rc2.451.g8631bc7472-goog


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe()
  2023-12-01 18:29 [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Douglas Anderson
@ 2023-12-01 18:29 ` Douglas Anderson
  2023-12-01 19:28   ` Alan Stern
  2023-12-02  2:14   ` Grant Grundler
  2023-12-01 18:29 ` [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration() Douglas Anderson
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 12+ messages in thread
From: Douglas Anderson @ 2023-12-01 18:29 UTC (permalink / raw)
  To: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Grant Grundler, Hayes Wang, Simon Horman, Bjørn Mork, netdev,
	Brian Geffon, Alan Stern, Douglas Anderson, Hans de Goede,
	Heikki Krogerus, Rafael J. Wysocki, linux-kernel

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 <dianders@chromium.org>
---

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;
-- 
2.43.0.rc2.451.g8631bc7472-goog


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration()
  2023-12-01 18:29 [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Douglas Anderson
  2023-12-01 18:29 ` [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe() Douglas Anderson
@ 2023-12-01 18:29 ` Douglas Anderson
  2023-12-01 19:30   ` Alan Stern
  2023-12-02 19:11   ` Bjørn Mork
  2023-12-01 18:29 ` [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe() Douglas Anderson
  2023-12-05  2:27 ` [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Jakub Kicinski
  3 siblings, 2 replies; 12+ messages in thread
From: Douglas Anderson @ 2023-12-01 18:29 UTC (permalink / raw)
  To: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Grant Grundler, Hayes Wang, Simon Horman, Bjørn Mork, netdev,
	Brian Geffon, Alan Stern, Douglas Anderson, linux-kernel

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 <stern@rowland.harvard.edu>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
---

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


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe()
  2023-12-01 18:29 [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Douglas Anderson
  2023-12-01 18:29 ` [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe() Douglas Anderson
  2023-12-01 18:29 ` [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration() Douglas Anderson
@ 2023-12-01 18:29 ` Douglas Anderson
  2023-12-02  6:28   ` Grant Grundler
  2023-12-05  2:27   ` Jakub Kicinski
  2023-12-05  2:27 ` [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Jakub Kicinski
  3 siblings, 2 replies; 12+ messages in thread
From: Douglas Anderson @ 2023-12-01 18:29 UTC (permalink / raw)
  To: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: Grant Grundler, Hayes Wang, Simon Horman, Bjørn Mork, netdev,
	Brian Geffon, Alan Stern, Douglas Anderson, linux-kernel

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(-)

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


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe()
  2023-12-01 18:29 ` [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe() Douglas Anderson
@ 2023-12-01 19:28   ` Alan Stern
  2023-12-02  2:14   ` Grant Grundler
  1 sibling, 0 replies; 12+ messages in thread
From: Alan Stern @ 2023-12-01 19:28 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Grant Grundler, Hayes Wang,
	Simon Horman, Bjørn Mork, netdev, Brian Geffon,
	Hans de Goede, Heikki Krogerus, Rafael J. Wysocki, linux-kernel

On Fri, Dec 01, 2023 at 10:29:50AM -0800, Douglas Anderson wrote:
> 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 <dianders@chromium.org>
> ---

Reviewed-by: Alan Stern <stern@rowland.harvard.edu>

> 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;
> -- 
> 2.43.0.rc2.451.g8631bc7472-goog
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration()
  2023-12-01 18:29 ` [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration() Douglas Anderson
@ 2023-12-01 19:30   ` Alan Stern
  2023-12-02 19:11   ` Bjørn Mork
  1 sibling, 0 replies; 12+ messages in thread
From: Alan Stern @ 2023-12-01 19:30 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Grant Grundler, Hayes Wang,
	Simon Horman, Bjørn Mork, netdev, Brian Geffon, linux-kernel

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 <stern@rowland.harvard.edu>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>
> ---

Reviewed-by: Alan Stern <stern@rowland.harvard.edu>

> 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
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe()
  2023-12-01 18:29 ` [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe() Douglas Anderson
  2023-12-01 19:28   ` Alan Stern
@ 2023-12-02  2:14   ` Grant Grundler
  1 sibling, 0 replies; 12+ messages in thread
From: Grant Grundler @ 2023-12-02  2:14 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Grant Grundler, Hayes Wang,
	Simon Horman, Bjørn Mork, netdev, Brian Geffon, Alan Stern,
	Hans de Goede, Heikki Krogerus, Rafael J. Wysocki, linux-kernel

On Fri, Dec 1, 2023 at 10:31 AM Douglas Anderson <dianders@chromium.org> wrote:
>
> 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 <dianders@chromium.org>

Reviewed-by: Grant Grundler <grundler@chromium.org>

Thanks for pursuing this Doug!

cheers,
grant

> ---
>
> 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;
> --
> 2.43.0.rc2.451.g8631bc7472-goog
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe()
  2023-12-01 18:29 ` [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe() Douglas Anderson
@ 2023-12-02  6:28   ` Grant Grundler
  2023-12-05  2:27   ` Jakub Kicinski
  1 sibling, 0 replies; 12+ messages in thread
From: Grant Grundler @ 2023-12-02  6:28 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Grant Grundler, Hayes Wang,
	Simon Horman, Bjørn Mork, netdev, Brian Geffon, Alan Stern,
	linux-kernel

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
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration()
  2023-12-01 18:29 ` [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration() Douglas Anderson
  2023-12-01 19:30   ` Alan Stern
@ 2023-12-02 19:11   ` Bjørn Mork
  1 sibling, 0 replies; 12+ messages in thread
From: Bjørn Mork @ 2023-12-02 19:11 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Grant Grundler, Hayes Wang,
	Simon Horman, netdev, Brian Geffon, Alan Stern, linux-kernel

Douglas Anderson <dianders@chromium.org> writes:

> 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 <stern@rowland.harvard.edu>
> Signed-off-by: Douglas Anderson <dianders@chromium.org>

Brilliant!  Thanks for doing this.  It is obviously what I should have
done in the first place if I had been smart enough.


Bjørn

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize
  2023-12-01 18:29 [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Douglas Anderson
                   ` (2 preceding siblings ...)
  2023-12-01 18:29 ` [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe() Douglas Anderson
@ 2023-12-05  2:27 ` Jakub Kicinski
  2023-12-05  2:34   ` Greg Kroah-Hartman
  3 siblings, 1 reply; 12+ messages in thread
From: Jakub Kicinski @ 2023-12-05  2:27 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Paolo Abeni, Grant Grundler, Hayes Wang, Simon Horman,
	Bjørn Mork, netdev, Brian Geffon, Alan Stern, Hans de Goede,
	Heikki Krogerus, Rafael J. Wysocki, linux-kernel

On Fri,  1 Dec 2023 10:29:49 -0800 Douglas Anderson wrote:
> Since these three patches straddle the USB subsystem and the
> networking subsystem then maintainers will (obviously) need to work
> out a way for them to land. I don't have any strong suggestions here
> so I'm happy to let the maintainers propose what they think will work
> best.

No strong preference here, on a quick read it seems more like a USB
change than networking change, tho, so I'll defer to Greg unless told
otherwise.
-- 
pw-bot: not-applicable

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe()
  2023-12-01 18:29 ` [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe() Douglas Anderson
  2023-12-02  6:28   ` Grant Grundler
@ 2023-12-05  2:27   ` Jakub Kicinski
  1 sibling, 0 replies; 12+ messages in thread
From: Jakub Kicinski @ 2023-12-05  2:27 UTC (permalink / raw)
  To: Douglas Anderson
  Cc: linux-usb, Greg Kroah-Hartman, David S . Miller, Eric Dumazet,
	Paolo Abeni, Grant Grundler, Hayes Wang, Simon Horman,
	Bjørn Mork, netdev, Brian Geffon, Alan Stern, linux-kernel

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>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize
  2023-12-05  2:27 ` [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Jakub Kicinski
@ 2023-12-05  2:34   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 12+ messages in thread
From: Greg Kroah-Hartman @ 2023-12-05  2:34 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: Douglas Anderson, linux-usb, David S . Miller, Eric Dumazet,
	Paolo Abeni, Grant Grundler, Hayes Wang, Simon Horman,
	Bjørn Mork, netdev, Brian Geffon, Alan Stern, Hans de Goede,
	Heikki Krogerus, Rafael J. Wysocki, linux-kernel

On Mon, Dec 04, 2023 at 06:27:27PM -0800, Jakub Kicinski wrote:
> On Fri,  1 Dec 2023 10:29:49 -0800 Douglas Anderson wrote:
> > Since these three patches straddle the USB subsystem and the
> > networking subsystem then maintainers will (obviously) need to work
> > out a way for them to land. I don't have any strong suggestions here
> > so I'm happy to let the maintainers propose what they think will work
> > best.
> 
> No strong preference here, on a quick read it seems more like a USB
> change than networking change, tho, so I'll defer to Greg unless told
> otherwise.

I took these in my tree already, sorry for not saying anything here.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-12-05  2:34 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-01 18:29 [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Douglas Anderson
2023-12-01 18:29 ` [PATCH v2 1/3] usb: core: Don't force USB generic_subclass drivers to define probe() Douglas Anderson
2023-12-01 19:28   ` Alan Stern
2023-12-02  2:14   ` Grant Grundler
2023-12-01 18:29 ` [PATCH v2 2/3] usb: core: Allow subclassed USB drivers to override usb_choose_configuration() Douglas Anderson
2023-12-01 19:30   ` Alan Stern
2023-12-02 19:11   ` Bjørn Mork
2023-12-01 18:29 ` [PATCH net v2 3/3] r8152: Choose our USB config with choose_configuration() rather than probe() Douglas Anderson
2023-12-02  6:28   ` Grant Grundler
2023-12-05  2:27   ` Jakub Kicinski
2023-12-05  2:27 ` [PATCH v2 0/3] net: usb: r8152: Fix lost config across deauthorize+authorize Jakub Kicinski
2023-12-05  2:34   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).