[PATCH] USB: usblp: Add device status detection in usblp_poll()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Zqiang <qiang.zhang@xxxxxxxxxxxxx>

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

Signed-off-by: Zqiang <qiang.zhang@xxxxxxxxxxxxx>
---
 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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux