Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Johan Hovold and committed by
Greg Kroah-Hartman
6d1bf48e 12e2e52c

+21 -22
+21 -22
drivers/usb/serial/safe_serial.c
··· 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; ··· 229 227 if (!tty) 230 228 return; 231 229 232 - if (safe) { 233 - __u16 fcs; 234 - fcs = fcs_compute10(data, length, CRC10_INITFCS); 235 - if (!fcs) { 236 - int actual_length = data[length - 2] >> 2; 237 - if (actual_length <= (length - 2)) { 238 - dev_info(&urb->dev->dev, "%s - actual: %d\n", 239 - __func__, actual_length); 240 - tty_insert_flip_string(tty, 241 - data, actual_length); 242 - tty_flip_buffer_push(tty); 243 - } else { 244 - dev_err(&port->dev, 245 - "%s - inconsistent lengths %d:%d\n", 246 - __func__, actual_length, length); 247 - } 248 - } else { 249 - dev_err(&port->dev, "%s - bad CRC %x\n", __func__, fcs); 250 - } 251 - } else { 252 - tty_insert_flip_string(tty, data, length); 253 - tty_flip_buffer_push(tty); 230 + if (!safe) 231 + goto out; 232 + 233 + fcs = fcs_compute10(data, length, CRC10_INITFCS); 234 + if (fcs) { 235 + dev_err(&port->dev, "%s - bad CRC %x\n", __func__, fcs); 236 + goto err; 254 237 } 255 238 239 + actual_length = data[length - 2] >> 2; 240 + if (actual_length > (length - 2)) { 241 + dev_err(&port->dev, "%s - inconsistent lengths %d:%d\n", 242 + __func__, actual_length, length); 243 + goto err; 244 + } 245 + dev_info(&urb->dev->dev, "%s - actual: %d\n", __func__, actual_length); 246 + length = actual_length; 247 + out: 248 + tty_insert_flip_string(tty, data, length); 249 + tty_flip_buffer_push(tty); 250 + err: 256 251 tty_kref_put(tty); 257 252 } 258 253