]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - drivers/usb/storage/transport.c
Merge 3.18-rc4 into usb-next.
[mirror_ubuntu-zesty-kernel.git] / drivers / usb / storage / transport.c
index b1d815eb6d0bb34d8edeff31581eafd1ad983a0c..540add24a12ffa428bda0e7a0db07650ecd29eab 100644 (file)
@@ -1035,9 +1035,20 @@ int usb_stor_Bulk_max_lun(struct us_data *us)
        usb_stor_dbg(us, "GetMaxLUN command result is %d, data is %d\n",
                     result, us->iobuf[0]);
 
-       /* if we have a successful request, return the result */
-       if (result > 0)
-               return us->iobuf[0];
+       /*
+        * If we have a successful request, return the result if valid. The
+        * CBW LUN field is 4 bits wide, so the value reported by the device
+        * should fit into that.
+        */
+       if (result > 0) {
+               if (us->iobuf[0] < 16) {
+                       return us->iobuf[0];
+               } else {
+                       dev_info(&us->pusb_intf->dev,
+                                "Max LUN %d is not valid, using 0 instead",
+                                us->iobuf[0]);
+               }
+       }
 
        /*
         * Some devices don't like GetMaxLUN.  They may STALL the control