This algorithm is wrong. See the description under Case (4) or (5) in
6.7.2 of the Bulk-Only spec:
The device may send fill data to pad up to a total of
dCBWDataTransferLength.
So it's legal to have Lgot == Lasked and Lresid > 0. There are devices
which really do this.
(It may seem pointless to add the padding. However for reasons that
aren't clear, the spec requires the device to STALL the bulk-in
endpoint if the padding isn't present -- and many devices don't like to
STALL bulk endpoints. Similar reasoning applies to the case of OUT
transfers.)
I hope it's blacklisted!
Alan Stern
--