USB: serial: mos7720: fix control-message error handling
authorJohan Hovold <johan@kernel.org>
Thu, 12 Jan 2017 13:56:17 +0000 (14:56 +0100)
committerJohan Hovold <johan@kernel.org>
Mon, 16 Jan 2017 15:38:56 +0000 (16:38 +0100)
Make sure to log an error on short transfers when reading a device
register.

Also clear the provided buffer (which if often an uninitialised
automatic variable) on errors as the driver currently does not bother to
check for errors.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Johan Hovold <johan@kernel.org>
drivers/usb/serial/mos7720.c

index 91bc170b408a08a59c49786e2cb5753149ce2425..acf431e026990e6027919094c77be173a45a9c19 100644 (file)
@@ -234,11 +234,16 @@ static int read_mos_reg(struct usb_serial *serial, unsigned int serial_portnum,
 
        status = usb_control_msg(usbdev, pipe, request, requesttype, value,
                                     index, buf, 1, MOS_WDR_TIMEOUT);
-       if (status == 1)
+       if (status == 1) {
                *data = *buf;
-       else if (status < 0)
+       } else {
                dev_err(&usbdev->dev,
                        "mos7720: usb_control_msg() failed: %d\n", status);
+               if (status >= 0)
+                       status = -EIO;
+               *data = 0;
+       }
+
        kfree(buf);
 
        return status;