2007-02-21 21:40:35

by Simon Arlott

[permalink] [raw]
Subject: [PATCH 2/2] usbatm: Detect usb device shutdown and ignore failed urbs.

Detect usb device shutdown and ignore failed urbs. This happens when the driver is unloaded or the device is unplugged.

Signed-off-by: Simon Arlott <[email protected]>
---
drivers/usb/atm/usbatm.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index 83cea01..1f5faee 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -274,6 +274,10 @@ static void usbatm_complete(struct urb *
(!(channel->usbatm->flags & UDSL_IGNORE_EILSEQ) ||
urb->status != -EILSEQ ))
{
+ /* the module/device has probably been removed */
+ if (urb->status == -ESHUTDOWN)
+ return;
+
if (printk_ratelimit())
atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n",
__func__, urb, urb->status);
--
1.4.3.1


--
Simon Arlott


Attachments:
signature.asc (829.00 B)
OpenPGP digital signature

2007-02-22 10:52:11

by Duncan Sands

[permalink] [raw]
Subject: Re: [PATCH 2/2] usbatm: Detect usb device shutdown and ignore failed urbs.

> + /* the module/device has probably been removed */
> + if (urb->status == -ESHUTDOWN)
> + return;
> +
> if (printk_ratelimit())
> atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n",
> __func__, urb, urb->status);

I would rather just suppress the warning in this case, and still do the delayed
schedule of the tasklet, in case this error was spurious and we're not really
about to be disconnected.

Ciao,

Duncan.

PS: I plan to work on the drivers this weekend.

2007-02-22 23:55:00

by Pete Zaitcev

[permalink] [raw]
Subject: Re: [PATCH 2/2] usbatm: Detect usb device shutdown and ignore failed urbs.

On Thu, 22 Feb 2007 11:43:38 +0100, Duncan Sands <[email protected]> wrote:

> > + /* the module/device has probably been removed */
> > + if (urb->status == -ESHUTDOWN)
> > + return;
> > +
> > if (printk_ratelimit())
> > atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n",
> > __func__, urb, urb->status);
>
> I would rather just suppress the warning in this case, and still do the delayed
> schedule of the tasklet, in case this error was spurious and we're not really
> about to be disconnected.

I disagree. If ESHUTDOWN is received, the endpoint is definitely gone.
I can see why you might want to retry EPROTO, ELISEQ, etc. but this
case is different.

-- Pete

2007-02-23 09:36:34

by Duncan Sands

[permalink] [raw]
Subject: Re: [PATCH 2/2] usbatm: Detect usb device shutdown and ignore failed urbs.

Hi Pete,

On Friday 23 February 2007 00:53:18 Pete Zaitcev wrote:
> On Thu, 22 Feb 2007 11:43:38 +0100, Duncan Sands <[email protected]> wrote:
> > > + /* the module/device has probably been removed */
> > > + if (urb->status == -ESHUTDOWN)
> > > + return;
> > > +
> > > if (printk_ratelimit())
> > > atm_warn(channel->usbatm, "%s: urb 0x%p failed (%d)!\n",
> > > __func__, urb, urb->status);
> >
> > I would rather just suppress the warning in this case, and still do the delayed
> > schedule of the tasklet, in case this error was spurious and we're not really
> > about to be disconnected.
>
> I disagree. If ESHUTDOWN is received, the endpoint is definitely gone.
> I can see why you might want to retry EPROTO, ELISEQ, etc. but this
> case is different.

if you get ESHUTDOWN, does that mean that you are about to be disconnected,
i.e. the disconnect method is about to be called? Or is it possible for the
device to just sit there disabled, but not disconnected?

Thanks,

Duncan.

2007-02-23 16:16:28

by Alan Stern

[permalink] [raw]
Subject: Re: [linux-usb-devel] [PATCH 2/2] usbatm: Detect usb device shutdown and ignore failed urbs.

On Fri, 23 Feb 2007, Duncan Sands wrote:

> if you get ESHUTDOWN, does that mean that you are about to be disconnected,
> i.e. the disconnect method is about to be called? Or is it possible for the
> device to just sit there disabled, but not disconnected?

It is possible to receive ESHUTDOWN without being disconnected. For
instance, a race with suspend could cause it to happen (although if your
driver is written correctly that race should never occur). Another more
likely scenario is that you have an active URB while calling
usb_set_interface(); the endpoints for the old altsetting get disabled and
the URB returns with an ESHUTDOWN error.

Alan Stern

2007-02-23 17:05:26

by Duncan Sands

[permalink] [raw]
Subject: Re: [linux-usb-devel] [PATCH 2/2] usbatm: Detect usb device shutdown and ignore failed urbs.

On Friday 23 February 2007 17:16:24 Alan Stern wrote:
> On Fri, 23 Feb 2007, Duncan Sands wrote:
>
> > if you get ESHUTDOWN, does that mean that you are about to be disconnected,
> > i.e. the disconnect method is about to be called? Or is it possible for the
> > device to just sit there disabled, but not disconnected?
>
> It is possible to receive ESHUTDOWN without being disconnected. For
> instance, a race with suspend could cause it to happen (although if your
> driver is written correctly that race should never occur). Another more
> likely scenario is that you have an active URB while calling
> usb_set_interface(); the endpoints for the old altsetting get disabled and
> the URB returns with an ESHUTDOWN error.

Thanks Alan. The original question was: if an urb fails with an error,
is there any point in resubmitting it after a delay (which is what the
driver usually does) if the error was -ESHUTDOWN? It sounds like there
is no point to it. And if the device is not disconnected, then it could
even be harmful since the urb will be resubmitted endlessly... While on
the topic, are there any other error codes for which an urb should not be
resubmitted?

Thanks again,

Duncan.

2007-02-23 18:12:01

by Alan Stern

[permalink] [raw]
Subject: Re: [linux-usb-devel] [PATCH 2/2] usbatm: Detect usb device shutdown and ignore failed urbs.

On Fri, 23 Feb 2007, Duncan Sands wrote:

> Thanks Alan. The original question was: if an urb fails with an error,
> is there any point in resubmitting it after a delay (which is what the
> driver usually does) if the error was -ESHUTDOWN? It sounds like there
> is no point to it.

No, there isn't.

> And if the device is not disconnected, then it could
> even be harmful since the urb will be resubmitted endlessly... While on
> the topic, are there any other error codes for which an urb should not be
> resubmitted?

Let's see... ENOENT and ECONNRESET indicate the URB was unlinked, so you
probably don't want to resubmit it. EPIPE indicates a problem on the
device end, so you would want to fix the problem before resubmitting (at
the very least you would want to clear the halt). EOVERFLOW is
questionable; if the device sent too much data once then it might do so
again. Ditto for EREMOTEIO (the device sent too little data). ENODEV
means the device was removed, so you definitely don't want to resubmit.

Alan Stern