driver/usbdev: return -ENOTCONN when usbdev had been unbind

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This commit is contained in:
dongjiuzhu1 2023-11-08 12:17:55 +08:00 committed by Xiang Xiao
parent 20401c202e
commit 0b832fd127

View File

@ -568,6 +568,14 @@ static ssize_t usbdev_fs_read(FAR struct file *filep, FAR char *buffer,
return ret; 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 */ /* Check for available data */
if (sq_empty(&fs_ep->reqq)) if (sq_empty(&fs_ep->reqq))
@ -671,6 +679,14 @@ static ssize_t usbdev_fs_write(FAR struct file *filep,
return ret; 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 */ /* Check for available write request */
if (sq_empty(&fs_ep->reqq)) if (sq_empty(&fs_ep->reqq))
@ -774,6 +790,14 @@ static int usbdev_fs_poll(FAR struct file *filep, FAR struct pollfd *fds,
return ret; return ret;
} }
/* Check if the usbdev device has been unbind */
if (fs_ep->unlinked)
{
nxmutex_unlock(&fs_ep->lock);
return -ENOTCONN;
}
if (!setup) if (!setup)
{ {
/* This is a request to tear down the poll. */ /* This is a request to tear down the poll. */
@ -1004,6 +1028,11 @@ static void usbdev_fs_ep_unbind(FAR const char *devname,
unregister_driver(devname); unregister_driver(devname);
fs_ep->unlinked = true; 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) if (fs_ep->crefs <= 0)
{ {
nxmutex_destroy(&fs_ep->lock); nxmutex_destroy(&fs_ep->lock);