From b1f633ec25dbf46e639bd2b88e3c49a6cfd3ab96 Mon Sep 17 00:00:00 2001 From: dongjiuzhu1 Date: Wed, 8 Nov 2023 12:17:55 +0800 Subject: [PATCH] driver/usbdev: return -ENOTCONN when usbdev had been unbind Signed-off-by: dongjiuzhu1 --- 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 e04c02e8bafc1..8701ae670f03f 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);