Skip to content

Commit

Permalink
usb: gadget: dummy_hcd: move the transfer part into its own function
Browse files Browse the repository at this point in the history
This patch moves the part of the code which does the bare transfer into
its function. It is a preparion for the implementation of sg support.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Jan 24, 2012
1 parent c688419 commit a04ce20
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions drivers/usb/gadget/dummy_hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,23 @@ static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
return rc;
}

static int dummy_perform_transfer(struct urb *urb, struct dummy_request *req,
u32 len)
{
void *ubuf, *rbuf;
int to_host;

to_host = usb_pipein(urb->pipe);
rbuf = req->req.buf + req->req.actual;
ubuf = urb->transfer_buffer + urb->actual_length;

if (to_host)
memcpy(ubuf, rbuf, len);
else
memcpy(rbuf, ubuf, len);
return len;
}

/* transfer up to a frame's worth; caller must own lock */
static int
transfer(struct dummy *dum, struct urb *urb, struct dummy_ep *ep, int limit,
Expand Down Expand Up @@ -1164,8 +1181,6 @@ transfer(struct dummy *dum, struct urb *urb, struct dummy_ep *ep, int limit,
if (unlikely (len == 0))
is_short = 1;
else {
char *ubuf, *rbuf;

/* not enough bandwidth left? */
if (limit < ep->ep.maxpacket && limit < len)
break;
Expand All @@ -1180,13 +1195,8 @@ transfer(struct dummy *dum, struct urb *urb, struct dummy_ep *ep, int limit,
}
is_short = (len % ep->ep.maxpacket) != 0;

/* else transfer packet(s) */
ubuf = urb->transfer_buffer + urb->actual_length;
rbuf = req->req.buf + req->req.actual;
if (to_host)
memcpy (ubuf, rbuf, len);
else
memcpy (rbuf, ubuf, len);
len = dummy_perform_transfer(urb, req, len);

ep->last_io = jiffies;

limit -= len;
Expand Down

0 comments on commit a04ce20

Please sign in to comment.