From 58484d7c6995ae57dfd8265e7a568af87d09a72d Mon Sep 17 00:00:00 2001 From: sgopal1 Date: Tue, 10 Jul 2018 09:31:33 +0530 Subject: [PATCH] UsbDescriptor: Add finite timeout to control transfer Using "0" as value for USB control transfer timeout results in an unlimited timeout in case of bad USB devices. In host kernels where hung task panic is enabled, this results in device reboot. So, add a finite timeout for USB control transfer. Test: manual run and test with bad USB devices. Change-Id: Ibc13ca4d8259a08ae7419bb3bcac9c161b1d3693 Signed-off-by: sgopal1 --- .../com/android/server/usb/descriptors/UsbDescriptor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java index 8c7565b790d2..686fdb4e8e4a 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java @@ -126,6 +126,9 @@ public abstract class UsbDescriptor implements Reporting { public static final int REQUEST_GET_CONFIGURATION = 0x08; public static final int REQUEST_SET_CONFIGURATION = 0x09; + // USB control transfer timeout + public static final int USB_CONTROL_TRANSFER_TIMEOUT_MS = 200; + /** * @throws IllegalArgumentException */ @@ -224,7 +227,7 @@ public abstract class UsbDescriptor implements Reporting { 0, sStringBuffer, 0xFF, - 0); + USB_CONTROL_TRANSFER_TIMEOUT_MS); if (rdo >= 0) { usbStr = new String(sStringBuffer, 2, rdo - 2, "UTF-16LE"); } else {