Skip to content

Commit

Permalink
libusbhost: Limit bulk transfer requests to 16384 bytes
Browse files Browse the repository at this point in the history
Otherwise the kernel will return an EINVAL error

Change-Id: I906472a4128eb26c5be7865142bc4a52464cf5f8
Bug: 4065217

Signed-off-by: Mike Lockwood <lockwood@android.com>
  • Loading branch information
mikeandroid committed Mar 12, 2011
1 parent 5db0897 commit c4c00d8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion libusbhost/usbhost.c
Expand Up @@ -53,6 +53,9 @@
#define USB_FS_ID_SCANNER "/dev/bus/usb/%d/%d"
#define USB_FS_ID_FORMAT "/dev/bus/usb/%03d/%03d"

// From drivers/usb/core/devio.c
// I don't know why this isn't in a kernel header
#define MAX_USBFS_BUFFER_SIZE 16384

struct usb_host_context {
int fd;
Expand Down Expand Up @@ -477,6 +480,10 @@ int usb_device_bulk_transfer(struct usb_device *device,
{
struct usbdevfs_bulktransfer ctrl;

// need to limit request size to avoid EINVAL
if (length > MAX_USBFS_BUFFER_SIZE)
length = MAX_USBFS_BUFFER_SIZE;

memset(&ctrl, 0, sizeof(ctrl));
ctrl.ep = endpoint;
ctrl.len = length;
Expand Down Expand Up @@ -531,7 +538,11 @@ int usb_request_queue(struct usb_request *req)

urb->status = -1;
urb->buffer = req->buffer;
urb->buffer_length = req->buffer_length;
// need to limit request size to avoid EINVAL
if (req->buffer_length > MAX_USBFS_BUFFER_SIZE)
urb->buffer_length = MAX_USBFS_BUFFER_SIZE;
else
urb->buffer_length = req->buffer_length;

do {
res = ioctl(req->dev->fd, USBDEVFS_SUBMITURB, urb);
Expand Down

0 comments on commit c4c00d8

Please sign in to comment.