diff mbox series

[RFT,4/4] chaoskey: request data asynchronously

Message ID 20200921113732.11524-5-oneukum@suse.com
State New
Headers show
Series [RFT,1/4] chaoskey: O_NONBLOCK in concurrent reads | expand

Commit Message

Oliver Neukum Sept. 21, 2020, 11:37 a.m. UTC
This requests more data if a read has exhausted the buffer
just to have it ready sooner.

Signed-off-by: Oliver Neukum <oneukum@suse.com>
---
 drivers/usb/misc/chaoskey.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/usb/misc/chaoskey.c b/drivers/usb/misc/chaoskey.c
index 0d80cba162a4..5773cf477e4d 100644
--- a/drivers/usb/misc/chaoskey.c
+++ b/drivers/usb/misc/chaoskey.c
@@ -358,6 +358,9 @@  static int chaoskey_request_fill(struct chaoskey *dev)
 		return -ENODEV;
 	}
 
+	if (dev->reading)
+		return -EBUSY;
+
 	/* Make sure the device is awake */
 	result = usb_autopm_get_interface(dev->interface);
 	if (result) {
@@ -500,13 +503,16 @@  static ssize_t chaoskey_read(struct file *file,
 		dev->used += this_time;
 		mutex_unlock(&dev->lock);
 	}
+	/* request data on suspicion that it will eventually be used */
+	if (dev->valid == dev->used)
+		(void)chaoskey_request_fill(dev);
 bail:
 	if (read_count) {
 		usb_dbg(dev->interface, "read %zu bytes", read_count);
 		return read_count;
 	}
 	usb_dbg(dev->interface, "empty read, result %d", result);
-	if (result == -ETIMEDOUT)
+	if (result == -ETIMEDOUT || result == -EBUSY)
 		result = -EAGAIN;
 	return result;
 }