Skip to content

Commit 2ef4700

Browse files
AlanSterngregkh
authored andcommitted
USB: usbfs: compute urb->actual_length for isochronous
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> CC: <stable@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d656fa3 commit 2ef4700

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

drivers/usb/core/devio.c

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

1823+
static void compute_isochronous_actual_length(struct urb *urb)
1824+
{
1825+
unsigned int i;
1826+
1827+
if (urb->number_of_packets > 0) {
1828+
urb->actual_length = 0;
1829+
for (i = 0; i < urb->number_of_packets; i++)
1830+
urb->actual_length +=
1831+
urb->iso_frame_desc[i].actual_length;
1832+
}
1833+
}
1834+
18231835
static int processcompl(struct async *as, void __user * __user *arg)
18241836
{
18251837
struct urb *urb = as->urb;
18261838
struct usbdevfs_urb __user *userurb = as->userurb;
18271839
void __user *addr = as->userurb;
18281840
unsigned int i;
18291841

1842+
compute_isochronous_actual_length(urb);
18301843
if (as->userbuffer && urb->actual_length) {
18311844
if (copy_urb_data_to_user(as->userbuffer, urb))
18321845
goto err_out;
@@ -1995,6 +2008,7 @@ static int processcompl_compat(struct async *as, void __user * __user *arg)
19952008
void __user *addr = as->userurb;
19962009
unsigned int i;
19972010

2011+
compute_isochronous_actual_length(urb);
19982012
if (as->userbuffer && urb->actual_length) {
19992013
if (copy_urb_data_to_user(as->userbuffer, urb))
20002014
return -EFAULT;

0 commit comments

Comments
 (0)