Skip to content

Commit

Permalink
driver/usbdev: return -ENOTCONN when usbdev had been unbind
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 Nov 11, 2023
1 parent 20401c2 commit 0b832fd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions drivers/usbdev/usbdev_fs.c
Expand Up @@ -568,6 +568,14 @@ static ssize_t usbdev_fs_read(FAR struct file *filep, FAR char *buffer,
return ret;
}

/* Check if the usbdev device has been unbind */

if (fs_ep->unlinked)
{
nxmutex_unlock(&fs_ep->lock);
return -ENOTCONN;
}

/* Check for available data */

if (sq_empty(&fs_ep->reqq))
Expand Down Expand Up @@ -671,6 +679,14 @@ static ssize_t usbdev_fs_write(FAR struct file *filep,
return ret;
}

/* Check if the usbdev device has been unbind */

if (fs_ep->unlinked)
{
nxmutex_unlock(&fs_ep->lock);
return -ENOTCONN;
}

/* Check for available write request */

if (sq_empty(&fs_ep->reqq))
Expand Down Expand Up @@ -774,6 +790,14 @@ static int usbdev_fs_poll(FAR struct file *filep, FAR struct pollfd *fds,
return ret;
}

/* Check if the usbdev device has been unbind */

if (fs_ep->unlinked)
{
nxmutex_unlock(&fs_ep->lock);
return -ENOTCONN;
}

if (!setup)
{
/* This is a request to tear down the poll. */
Expand Down Expand Up @@ -1004,6 +1028,11 @@ static void usbdev_fs_ep_unbind(FAR const char *devname,

unregister_driver(devname);
fs_ep->unlinked = true;

/* Notify the usbdev device has been unbind */

poll_notify(fs_ep->fds, CONFIG_USBDEV_FS_NPOLLWAITERS, POLLHUP | POLLERR);

if (fs_ep->crefs <= 0)
{
nxmutex_destroy(&fs_ep->lock);
Expand Down

0 comments on commit 0b832fd

Please sign in to comment.