You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/11/11 13:10:11 UTC
(nuttx) 05/05: driver/usbdev: return -ENOTCONN when usbdev had been unbind
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 0b832fd12761105edb04f8906aac55a96be66ed1
Author: dongjiuzhu1 <do...@xiaomi.com>
AuthorDate: Wed Nov 8 12:17:55 2023 +0800
driver/usbdev: return -ENOTCONN when usbdev had been unbind
Signed-off-by: dongjiuzhu1 <do...@xiaomi.com>
---
drivers/usbdev/usbdev_fs.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/drivers/usbdev/usbdev_fs.c b/drivers/usbdev/usbdev_fs.c
index e04c02e8ba..8701ae670f 100644
--- a/drivers/usbdev/usbdev_fs.c
+++ b/drivers/usbdev/usbdev_fs.c
@@ -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))
@@ -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))
@@ -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. */
@@ -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);