diff options
| author | Johan Hovold <jhovold@gmail.com> | 2010-05-18 18:01:32 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-05-20 16:21:49 -0400 |
| commit | 6d1bf48e240bde4e9c7313ccdd2fe32f37f67ad4 (patch) | |
| tree | e2fd1e7a4d65f2ec1fd29f3aa26471a0f40c4833 | |
| parent | 12e2e52cc578714d5824a27dd1a131a5418d636b (diff) | |
USB: safe_serial: straighten out read processing
Clean up read processing logic.
Tested using a cp210x device in a loopback setup.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
| -rw-r--r-- | drivers/usb/serial/safe_serial.c | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c index d9af5c5ed9e8..a36e2313eed0 100644 --- a/drivers/usb/serial/safe_serial.c +++ b/drivers/usb/serial/safe_serial.c | |||
| @@ -218,7 +218,9 @@ static void safe_process_read_urb(struct urb *urb) | |||
| 218 | struct usb_serial_port *port = urb->context; | 218 | struct usb_serial_port *port = urb->context; |
| 219 | unsigned char *data = urb->transfer_buffer; | 219 | unsigned char *data = urb->transfer_buffer; |
| 220 | unsigned char length = urb->actual_length; | 220 | unsigned char length = urb->actual_length; |
| 221 | int actual_length; | ||
| 221 | struct tty_struct *tty; | 222 | struct tty_struct *tty; |
| 223 | __u16 fcs; | ||
| 222 | 224 | ||
| 223 | if (!length) | 225 | if (!length) |
| 224 | return; | 226 | return; |
| @@ -227,30 +229,27 @@ static void safe_process_read_urb(struct urb *urb) | |||
| 227 | if (!tty) | 229 | if (!tty) |
| 228 | return; | 230 | return; |
| 229 | 231 | ||
| 230 | if (safe) { | 232 | if (!safe) |
| 231 | __u16 fcs; | 233 | goto out; |
| 232 | fcs = fcs_compute10(data, length, CRC10_INITFCS); | 234 | |
| 233 | if (!fcs) { | 235 | fcs = fcs_compute10(data, length, CRC10_INITFCS); |
| 234 | int actual_length = data[length - 2] >> 2; | 236 | if (fcs) { |
| 235 | if (actual_length <= (length - 2)) { | 237 | dev_err(&port->dev, "%s - bad CRC %x\n", __func__, fcs); |
| 236 | dev_info(&urb->dev->dev, "%s - actual: %d\n", | 238 | goto err; |
| 237 | __func__, actual_length); | ||
| 238 | tty_insert_flip_string(tty, | ||
| 239 | data, actual_length); | ||
| 240 | tty_flip_buffer_push(tty); | ||
| 241 | } else { | ||
| 242 | dev_err(&port->dev, | ||
| 243 | "%s - inconsistent lengths %d:%d\n", | ||
| 244 | __func__, actual_length, length); | ||
| 245 | } | ||
| 246 | } else { | ||
| 247 | dev_err(&port->dev, "%s - bad CRC %x\n", __func__, fcs); | ||
| 248 | } | ||
| 249 | } else { | ||
| 250 | tty_insert_flip_string(tty, data, length); | ||
| 251 | tty_flip_buffer_push(tty); | ||
| 252 | } | 239 | } |
| 253 | 240 | ||
| 241 | actual_length = data[length - 2] >> 2; | ||
| 242 | if (actual_length > (length - 2)) { | ||
| 243 | dev_err(&port->dev, "%s - inconsistent lengths %d:%d\n", | ||
| 244 | __func__, actual_length, length); | ||
| 245 | goto err; | ||
| 246 | } | ||
| 247 | dev_info(&urb->dev->dev, "%s - actual: %d\n", __func__, actual_length); | ||
| 248 | length = actual_length; | ||
| 249 | out: | ||
| 250 | tty_insert_flip_string(tty, data, length); | ||
| 251 | tty_flip_buffer_push(tty); | ||
| 252 | err: | ||
| 254 | tty_kref_put(tty); | 253 | tty_kref_put(tty); |
| 255 | } | 254 | } |
| 256 | 255 | ||
