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

USB: chaoskey: fix error case of a timeout

In case of a timeout or if a signal aborts a read
communication with the device needs to be ended
lest we overwrite an active URB the next time we
do IO to the device, as the URB may still be active.

Signed-off-by: Oliver Neukum <oneukum@suse.de>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20191107142856.16774-1-oneukum@suse.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Oliver Neukum and committed by
Greg Kroah-Hartman
92aa5986 c368a411

+21 -3
+21 -3
drivers/usb/misc/chaoskey.c
··· 384 384 !dev->reading, 385 385 (started ? NAK_TIMEOUT : ALEA_FIRST_TIMEOUT) ); 386 386 387 - if (result < 0) 387 + if (result < 0) { 388 + usb_kill_urb(dev->urb); 388 389 goto out; 390 + } 389 391 390 - if (result == 0) 392 + if (result == 0) { 391 393 result = -ETIMEDOUT; 392 - else 394 + usb_kill_urb(dev->urb); 395 + } else { 393 396 result = dev->valid; 397 + } 394 398 out: 395 399 /* Let the device go back to sleep eventually */ 396 400 usb_autopm_put_interface(dev->interface); ··· 530 526 531 527 static int chaoskey_resume(struct usb_interface *interface) 532 528 { 529 + struct chaoskey *dev; 530 + struct usb_device *udev = interface_to_usbdev(interface); 531 + 533 532 usb_dbg(interface, "resume"); 533 + dev = usb_get_intfdata(interface); 534 + 535 + /* 536 + * We may have lost power. 537 + * In that case the device that needs a long time 538 + * for the first requests needs an extended timeout 539 + * again 540 + */ 541 + if (le16_to_cpu(udev->descriptor.idVendor) == ALEA_VENDOR_ID) 542 + dev->reads_started = false; 543 + 534 544 return 0; 535 545 } 536 546 #else