Author: hselasky
Date: Mon Jul 30 09:18:45 2018
New Revision: 336885
URL: https://svnweb.freebsd.org/changeset/base/336885

Log:
  MFC r335669:
  Improve the userspace USB string reading function in LibUSB.
  Some USB devices does not allow a partial descriptor readout.
  
  Found by:             bz @
  Sponsored by:         Mellanox Technologies

Modified:
  stable/9/lib/libusb/libusb20.c
Directory Properties:
  stable/9/lib/   (props changed)
  stable/9/lib/libusb/   (props changed)

Modified: stable/9/lib/libusb/libusb20.c
==============================================================================
--- stable/9/lib/libusb/libusb20.c      Mon Jul 30 09:16:47 2018        
(r336884)
+++ stable/9/lib/libusb/libusb20.c      Mon Jul 30 09:18:45 2018        
(r336885)
@@ -783,6 +783,7 @@ libusb20_dev_req_string_sync(struct libusb20_device *p
 {
        struct LIBUSB20_CONTROL_SETUP_DECODED req;
        int error;
+       int flags;
 
        /* make sure memory is initialised */
        memset(ptr, 0, len);
@@ -809,22 +810,24 @@ libusb20_dev_req_string_sync(struct libusb20_device *p
        error = libusb20_dev_request_sync(pdev, &req,
            ptr, NULL, 1000, LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK);
        if (error) {
-               return (error);
+               /* try to request full string */
+               req.wLength = 255;
+               flags = 0;
+       } else {
+               /* extract length and request full string */
+               req.wLength = *(uint8_t *)ptr;
+               flags = LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK;
        }
-       req.wLength = *(uint8_t *)ptr;  /* bytes */
        if (req.wLength > len) {
                /* partial string read */
                req.wLength = len;
        }
-       error = libusb20_dev_request_sync(pdev, &req,
-           ptr, NULL, 1000, LIBUSB20_TRANSFER_SINGLE_SHORT_NOT_OK);
-
-       if (error) {
+       error = libusb20_dev_request_sync(pdev, &req, ptr, NULL, 1000, flags);
+       if (error)
                return (error);
-       }
-       if (((uint8_t *)ptr)[1] != LIBUSB20_DT_STRING) {
+
+       if (((uint8_t *)ptr)[1] != LIBUSB20_DT_STRING)
                return (LIBUSB20_ERROR_OTHER);
-       }
        return (0);                     /* success */
 }
 
_______________________________________________
svn-src-stable-9@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-stable-9
To unsubscribe, send any mail to "svn-src-stable-9-unsubscr...@freebsd.org"

Reply via email to