linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] USB: usblp: Add device status detection in usblp_poll()
@ 2021-03-01  4:03 qiang.zhang
  2021-03-01  8:00 ` Greg KH
  0 siblings, 1 reply; 13+ messages in thread
From: qiang.zhang @ 2021-03-01  4:03 UTC (permalink / raw)
  To: zaitcev, gregkh; +Cc: linux-usb

From: Zqiang <qiang.zhang@windriver.com>

If usblp device has been disconnected, direct return
'EPOLLHUP | EPOLLERR' in usblp_poll().

Signed-off-by: Zqiang <qiang.zhang@windriver.com>
---
 drivers/usb/class/usblp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index c9f6e9758288..40095c8826d2 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -498,6 +498,12 @@ static __poll_t usblp_poll(struct file *file, struct poll_table_struct *wait)
 	unsigned long flags;
 
 	struct usblp *usblp = file->private_data;
+	mutex_lock(&usblp->mut);
+	if (!usblp->present) {
+		ret = EPOLLHUP | EPOLLERR;
+		goto no_poll;
+	}
+
 	/* Should we check file->f_mode & FMODE_WRITE before poll_wait()? */
 	poll_wait(file, &usblp->rwait, wait);
 	poll_wait(file, &usblp->wwait, wait);
@@ -505,6 +511,8 @@ static __poll_t usblp_poll(struct file *file, struct poll_table_struct *wait)
 	ret = ((usblp->bidir && usblp->rcomplete) ? EPOLLIN  | EPOLLRDNORM : 0) |
 	   ((usblp->no_paper || usblp->wcomplete) ? EPOLLOUT | EPOLLWRNORM : 0);
 	spin_unlock_irqrestore(&usblp->lock, flags);
+no_poll:
+	mutex_unlock(&usblp->mut);
 	return ret;
 }
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2021-03-04  0:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-01  4:03 [PATCH] USB: usblp: Add device status detection in usblp_poll() qiang.zhang
2021-03-01  8:00 ` Greg KH
2021-03-01  8:26   ` 回复: " Zhang, Qiang
2021-03-01  8:32     ` Greg KH
2021-03-01  8:52       ` 回复: " Zhang, Qiang
2021-03-02  7:04         ` Greg KH
2021-03-02  7:41           ` 回复: " Zhang, Qiang
2021-03-03  5:12             ` Pete Zaitcev
2021-03-03  6:12               ` 回复: " Zhang, Qiang
2021-03-03  6:56                 ` Greg KH
2021-03-03  7:15                 ` Zhang, Qiang
2021-03-03 15:57                   ` Pete Zaitcev
2021-03-03 17:13               ` Alan Stern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).