Skip to content

Commit 965003b

Browse files
AlanSterngregkh
authored andcommitted
USB: usbfs: compute urb->actual_length for isochronous
commit 2ef47001b3ee3ded579b7532ebdcf8680e4d8c54 upstream. The USB kerneldoc says that the actual_length field "is read in non-iso completion functions", but the usbfs driver uses it for all URB types in processcompl(). Since not all of the host controller drivers set actual_length for isochronous URBs, programs using usbfs with some host controllers don't work properly. For example, Minas reports that a USB camera controlled by libusb doesn't work properly with a dwc2 controller. It doesn't seem worthwhile to change the HCDs and the documentation, since the in-kernel USB class drivers evidently don't rely on actual_length for isochronous transfers. The easiest solution is for usbfs to calculate the actual_length value for itself, by adding up the lengths of the individual packets in an isochronous transfer. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> CC: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com> Reported-and-tested-by: wlf <wulf@rock-chips.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 834a5d8 commit 965003b

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

drivers/usb/core/devio.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,13 +1653,26 @@ static int proc_unlinkurb(struct usb_dev_state *ps, void __user *arg)
16531653
return 0;
16541654
}
16551655

1656+
static void compute_isochronous_actual_length(struct urb *urb)
1657+
{
1658+
unsigned int i;
1659+
1660+
if (urb->number_of_packets > 0) {
1661+
urb->actual_length = 0;
1662+
for (i = 0; i < urb->number_of_packets; i++)
1663+
urb->actual_length +=
1664+
urb->iso_frame_desc[i].actual_length;
1665+
}
1666+
}
1667+
16561668
static int processcompl(struct async *as, void __user * __user *arg)
16571669
{
16581670
struct urb *urb = as->urb;
16591671
struct usbdevfs_urb __user *userurb = as->userurb;
16601672
void __user *addr = as->userurb;
16611673
unsigned int i;
16621674

1675+
compute_isochronous_actual_length(urb);
16631676
if (as->userbuffer && urb->actual_length) {
16641677
if (copy_urb_data_to_user(as->userbuffer, urb))
16651678
goto err_out;
@@ -1829,6 +1842,7 @@ static int processcompl_compat(struct async *as, void __user * __user *arg)
18291842
void __user *addr = as->userurb;
18301843
unsigned int i;
18311844

1845+
compute_isochronous_actual_length(urb);
18321846
if (as->userbuffer && urb->actual_length) {
18331847
if (copy_urb_data_to_user(as->userbuffer, urb))
18341848
return -EFAULT;

0 commit comments

Comments
 (0)