[PATCH] USB: usbip: fix stub_dev hub disconnect

Jonas Blixt posted 1 patch 2 years, 7 months ago
There is a newer version of this series
drivers/usb/usbip/stub_dev.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] USB: usbip: fix stub_dev hub disconnect
Posted by Jonas Blixt 2 years, 7 months ago
If a hub is disconnected that has device(s) that's attached to the usbip layer
the disconnect function might fail because it tries to release the port
on an already disconnected hub.

Fixes: 6080cd0e9239 ("staging: usbip: claim ports used by shared devices")
Signed-off-by: Jonas Blixt <jonas.blixt@actia.se>
---
 drivers/usb/usbip/stub_dev.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
index 2305d425e6c9..257861787cdf 100644
--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -427,8 +427,12 @@ static void stub_disconnect(struct usb_device *udev)
 	/* release port */
 	rc = usb_hub_release_port(udev->parent, udev->portnum,
 				  (struct usb_dev_state *) udev);
-	if (rc) {
-		dev_dbg(&udev->dev, "unable to release port\n");
+	/*
+	 * NOTE: If a HUB disconnect triggered disconnect of the down stream
+	 * device usb_hub_release_port will return -ENODEV.
+	 */
+	if (rc && (rc != -ENODEV)) {
+		dev_dbg(&udev->dev, "unable to release port (%i)\n", rc);
 		return;
 	}
 
-- 
2.25.1
Re: [PATCH] USB: usbip: fix stub_dev hub disconnect
Posted by Greg KH 2 years, 7 months ago
On Tue, Jun 13, 2023 at 11:29:18AM +0200, Jonas Blixt wrote:
> If a hub is disconnected that has device(s) that's attached to the usbip layer
> the disconnect function might fail because it tries to release the port
> on an already disconnected hub.
> 
> Fixes: 6080cd0e9239 ("staging: usbip: claim ports used by shared devices")
> Signed-off-by: Jonas Blixt <jonas.blixt@actia.se>
> ---
>  drivers/usb/usbip/stub_dev.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
> index 2305d425e6c9..257861787cdf 100644
> --- a/drivers/usb/usbip/stub_dev.c
> +++ b/drivers/usb/usbip/stub_dev.c
> @@ -427,8 +427,12 @@ static void stub_disconnect(struct usb_device *udev)
>  	/* release port */
>  	rc = usb_hub_release_port(udev->parent, udev->portnum,
>  				  (struct usb_dev_state *) udev);
> -	if (rc) {
> -		dev_dbg(&udev->dev, "unable to release port\n");
> +	/*
> +	 * NOTE: If a HUB disconnect triggered disconnect of the down stream
> +	 * device usb_hub_release_port will return -ENODEV.

How about adding, "so we can safely ignore that error here."

thanks,

greg k-h
Re: [PATCH] USB: usbip: fix stub_dev hub disconnect
Posted by Jonas Blixt 2 years, 7 months ago
On Tue, Jun 13, 2023 at 11:50:31AM +0200, Greg KH wrote:
> On Tue, Jun 13, 2023 at 11:29:18AM +0200, Jonas Blixt wrote:
> > If a hub is disconnected that has device(s) that's attached to the usbip layer
> > the disconnect function might fail because it tries to release the port
> > on an already disconnected hub.
> > 
> > Fixes: 6080cd0e9239 ("staging: usbip: claim ports used by shared devices")
> > Signed-off-by: Jonas Blixt <jonas.blixt@actia.se>
> > ---
> >  drivers/usb/usbip/stub_dev.c | 8 ++++++--
> >  1 file changed, 6 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/usb/usbip/stub_dev.c b/drivers/usb/usbip/stub_dev.c
> > index 2305d425e6c9..257861787cdf 100644
> > --- a/drivers/usb/usbip/stub_dev.c
> > +++ b/drivers/usb/usbip/stub_dev.c
> > @@ -427,8 +427,12 @@ static void stub_disconnect(struct usb_device *udev)
> >  	/* release port */
> >  	rc = usb_hub_release_port(udev->parent, udev->portnum,
> >  				  (struct usb_dev_state *) udev);
> > -	if (rc) {
> > -		dev_dbg(&udev->dev, "unable to release port\n");
> > +	/*
> > +	 * NOTE: If a HUB disconnect triggered disconnect of the down stream
> > +	 * device usb_hub_release_port will return -ENODEV.
> 
> How about adding, "so we can safely ignore that error here."
> 
> thanks,
> 
> greg k-h

Yes, I'll update the comment and prepare a V2 patch.

Jonas