Commit 6d1bf48e240bde4e9c7313ccdd2fe32f37f67ad4

Authored by Johan Hovold
Committed by Greg Kroah-Hartman
1 parent 12e2e52cc5

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>

Showing 1 changed file with 21 additions and 22 deletions Side-by-side Diff

drivers/usb/serial/safe_serial.c
... ... @@ -218,7 +218,9 @@
218 218 struct usb_serial_port *port = urb->context;
219 219 unsigned char *data = urb->transfer_buffer;
220 220 unsigned char length = urb->actual_length;
  221 + int actual_length;
221 222 struct tty_struct *tty;
  223 + __u16 fcs;
222 224  
223 225 if (!length)
224 226 return;
225 227  
... ... @@ -227,30 +229,27 @@
227 229 if (!tty)
228 230 return;
229 231  
230   - if (safe) {
231   - __u16 fcs;
232   - fcs = fcs_compute10(data, length, CRC10_INITFCS);
233   - if (!fcs) {
234   - int actual_length = data[length - 2] >> 2;
235   - if (actual_length <= (length - 2)) {
236   - dev_info(&urb->dev->dev, "%s - actual: %d\n",
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);
  232 + if (!safe)
  233 + goto out;
  234 +
  235 + fcs = fcs_compute10(data, length, CRC10_INITFCS);
  236 + if (fcs) {
  237 + dev_err(&port->dev, "%s - bad CRC %x\n", __func__, fcs);
  238 + goto err;
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 253 tty_kref_put(tty);
255 254 }
256 255