Skip to content

Commit a2fa8a1

Browse files
oneukumgregkh
authored andcommitted
usb: chaoskey: fix locking for O_NONBLOCK
A failure to take a lock with O_NONBLOCK needs to result in -EAGAIN. Change it. Fixes: 66e3e59 ("usb: Add driver for Altus Metrum ChaosKey device (v2)") Signed-off-by: Oliver Neukum <oneukum@suse.com> Link: https://patch.msgid.link/20251030093918.2248104-1-oneukum@suse.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7ebbd0a commit a2fa8a1

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

drivers/usb/misc/chaoskey.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,19 @@ static ssize_t chaoskey_read(struct file *file,
444444
goto bail;
445445
mutex_unlock(&dev->rng_lock);
446446

447-
result = mutex_lock_interruptible(&dev->lock);
448-
if (result)
449-
goto bail;
447+
if (file->f_flags & O_NONBLOCK) {
448+
result = mutex_trylock(&dev->lock);
449+
if (result == 0) {
450+
result = -EAGAIN;
451+
goto bail;
452+
} else {
453+
result = 0;
454+
}
455+
} else {
456+
result = mutex_lock_interruptible(&dev->lock);
457+
if (result)
458+
goto bail;
459+
}
450460
if (dev->valid == dev->used) {
451461
result = _chaoskey_fill(dev);
452462
if (result < 0) {

0 commit comments

Comments
 (0)