@@ -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;
}
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(-)