Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: chaoskey: fix locking for O_NONBLOCK

A failure to take a lock with O_NONBLOCK needs to result
in -EAGAIN. Change it.

Fixes: 66e3e591891da ("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>

authored by

Oliver Neukum and committed by
Greg Kroah-Hartman
a2fa8a12 7ebbd0a5

+13 -3
+13 -3
drivers/usb/misc/chaoskey.c
··· 444 444 goto bail; 445 445 mutex_unlock(&dev->rng_lock); 446 446 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 + } 450 460 if (dev->valid == dev->used) { 451 461 result = _chaoskey_fill(dev); 452 462 if (result < 0) {