USB: serial: digi_acceleport: fix incomplete rx sanity check
[pandora-kernel.git] / drivers / usb / serial / digi_acceleport.c
index e59bd95..4499bda 100644 (file)
@@ -1660,25 +1660,30 @@ static int digi_read_inb_callback(struct urb *urb)
        struct usb_serial_port *port = urb->context;
        struct tty_struct *tty;
        struct digi_port *priv = usb_get_serial_port_data(port);
-       int opcode = ((unsigned char *)urb->transfer_buffer)[0];
-       int len = ((unsigned char *)urb->transfer_buffer)[1];
-       int port_status = ((unsigned char *)urb->transfer_buffer)[2];
-       unsigned char *data = ((unsigned char *)urb->transfer_buffer) + 3;
+       unsigned char *buf = urb->transfer_buffer;
+       int opcode;
+       int len;
+       int port_status;
+       unsigned char *data;
        int flag, throttled;
-       int status = urb->status;
-
-       /* do not process callbacks on closed ports */
-       /* but do continue the read chain */
-       if (urb->status == -ENOENT)
-               return 0;
 
        /* short/multiple packet check */
+       if (urb->actual_length < 2) {
+               dev_warn(&port->dev, "short packet received\n");
+               return -1;
+       }
+
+       opcode = buf[0];
+       len = buf[1];
+
        if (urb->actual_length != len + 2) {
-               dev_err(&port->dev, "%s: INCOMPLETE OR MULTIPLE PACKET, "
-                       "status=%d, port=%d, opcode=%d, len=%d, "
-                       "actual_length=%d, status=%d\n", __func__, status,
-                       priv->dp_port_num, opcode, len, urb->actual_length,
-                       port_status);
+               dev_err(&port->dev, "malformed packet received: port=%d, opcode=%d, len=%d, actual_length=%u\n",
+                       priv->dp_port_num, opcode, len, urb->actual_length);
+               return -1;
+       }
+
+       if (opcode == DIGI_CMD_RECEIVE_DATA && len < 1) {
+               dev_err(&port->dev, "malformed data packet received\n");
                return -1;
        }
 
@@ -1693,6 +1698,9 @@ static int digi_read_inb_callback(struct urb *urb)
 
        /* receive data */
        if (tty && opcode == DIGI_CMD_RECEIVE_DATA) {
+               port_status = buf[2];
+               data = &buf[3];
+
                /* get flag from port_status */
                flag = 0;
 
@@ -1746,6 +1754,7 @@ static int digi_read_oob_callback(struct urb *urb)
        struct usb_serial *serial = port->serial;
        struct tty_struct *tty;
        struct digi_port *priv = usb_get_serial_port_data(port);
+       unsigned char *buf = urb->transfer_buffer;
        int opcode, line, status, val;
        int i;
        unsigned int rts;
@@ -1753,12 +1762,15 @@ static int digi_read_oob_callback(struct urb *urb)
        dbg("digi_read_oob_callback: port=%d, len=%d",
                        priv->dp_port_num, urb->actual_length);
 
+       if (urb->actual_length < 4)
+               return -1;
+
        /* handle each oob command */
-       for (i = 0; i < urb->actual_length - 3;) {
-               opcode = ((unsigned char *)urb->transfer_buffer)[i++];
-               line = ((unsigned char *)urb->transfer_buffer)[i++];
-               status = ((unsigned char *)urb->transfer_buffer)[i++];
-               val = ((unsigned char *)urb->transfer_buffer)[i++];
+       for (i = 0; i < urb->actual_length - 3; i += 4) {
+               opcode = buf[i];
+               line = buf[i + 1];
+               status = buf[i + 2];
+               val = buf[i + 3];
 
                dbg("digi_read_oob_callback: opcode=%d, line=%d, status=%d, val=%d",
                        opcode, line, status, val);