scsa2usb should ignore dubious residue in command status wrapper
scsa2usb driver (USB mass storage through the SCSI framework) has a facility for managing behavioural quirks in some hardware. One such quirk is marked by
SCSA2USB_ATTRS_USE_CSW_RESIDUE, which if disabled signals to the driver to ignore the residue field of the command status wrapper used in the USB mass storage bulk-only transport.
Presently, this quirk must be activated by static inclusion in the quirks table compiled into the driver on a product by product basis. On at least one device in the field where I have witnessed this quirk, we can actually detect it dynamically based on the CSW residue value for our initial successful INQUIRY response, where we can be reasonably sure that the host controller driver's report of a full transfer (of 36 bytes) is correct and the CSW residue is just wrong.
We should check for appropriately malformed INQUIRY responses in
scsa2usb_handle_csw_result() and, if one is detected, disable the
USE_CSW_RESIDUE attribute for this device. A cursory inspection of other operating systems suggests they use a similar heuristic.
My experimentation with a 4TB Toshiba Canvio Basics 2.5" USB 3.0 Hard Disk suggests this is sufficient to enable the drive to work without other apparent ill effects.