On Fri, Feb 19, 2010 at 12:03 PM, Alan Stern <stern@xxxxxxxxxxxxxxxxxxx> wrote: > On Fri, 19 Feb 2010, FEI YANG wrote: > >> Now if I do terminate the pending IN URB before calling >> usb_autopm_put_interface, the same situation would still occur as the >> driver doesn't really know if it's in the middle of an IN transfer or >> not. However, comparing to the implementation mentioned above, I did >> notice some difference. usb_kill_urb sometimes gives back the URB with >> urb->actual_length equals to a number that is not integer multiple of >> 512, this has never happened if the URB is terminated only by >> usb_hcd_flush_endpoint. So I'm confused if we really need to >> 1. call usb_kill_urb before calling usb_autopm_put_interface? >> 2. if yes to 1, why sometimes the actual_length is not multiple of >> 512, and how should we handle it. > > Question 2 is the important one. actual_length should always be a > multiple of 512. > > The value is computed in the first few lines of qtd_copy_status() in > drivers/usb/host/ehci-q.c. You could print out the values of > urb->actual_length, length, and QTD_LENGTH(token) at that point to see > what's going wrong. > Here are the values printed in qtd_copy_status() actual 108, lenght 15548, QTD 15440 And the actual_length seen in our driver is also 108, so the calculation seems to be correct, and there is no memory corruption. The question is still "why it is not multiple of 512". I'm thinking I might have mis-understood the EHCI spec. The spec says when suspending the bus, the hardware would guarantee the current transaction to be finished before bus suspend taking effect, but in our case the driver is actually killing the urb before suspending the bus, as usb_kill_urb is called in the driver's suspend function which gets called before bus suspend. Maybe killing URB doesn't guarantee the current transaction to be finished. The actual_length is not the only problem, afte usb_kill_urb the data in the buffer doesn't seem to be correct either, looks like the controller hasn't updated the buffer yet. Fei -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html