Skip to content

Commit

Permalink
drivers/usbdev: support read ZLP packet
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
  • Loading branch information
Donny9 authored and xiaoxiang781216 committed Apr 23, 2024
1 parent 4bcad61 commit 4433067
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions drivers/usbdev/usbdev_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,6 @@ static ssize_t usbdev_fs_read(FAR struct file *filep, FAR char *buffer,
irqstate_t flags;
int ret;

assert(len > 0 && buffer != NULL);

ret = nxmutex_lock(&fs_ep->lock);
if (ret < 0)
{
Expand Down Expand Up @@ -600,7 +598,7 @@ static ssize_t usbdev_fs_read(FAR struct file *filep, FAR char *buffer,

/* Device ready for read */

while (!sq_empty(&fs_ep->reqq) && len > 0)
while (!sq_empty(&fs_ep->reqq))
{
FAR struct usbdev_fs_req_s *container;
uint16_t reqlen;
Expand All @@ -616,16 +614,24 @@ static ssize_t usbdev_fs_read(FAR struct file *filep, FAR char *buffer,
{
/* Output buffer full */

memcpy(&buffer[retlen],
&container->req->buf[container->offset],
len);
if (buffer != NULL)
{
memcpy(&buffer[retlen],
&container->req->buf[container->offset],
len);
}

container->offset += len;
retlen += len;
break;
}

memcpy(&buffer[retlen],
&container->req->buf[container->offset], reqlen);
if (buffer != NULL)
{
memcpy(&buffer[retlen],
&container->req->buf[container->offset], reqlen);
}

retlen += reqlen;
len -= reqlen;

Expand Down

0 comments on commit 4433067

Please sign in to comment.