aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/safe_serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/serial/safe_serial.c')
-rw-r--r--drivers/usb/serial/safe_serial.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index 3fe98a52b914..e6acac49a9c8 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -198,7 +198,6 @@ static void safe_read_bulk_callback (struct urb *urb)
198 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 198 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
199 unsigned char *data = urb->transfer_buffer; 199 unsigned char *data = urb->transfer_buffer;
200 unsigned char length = urb->actual_length; 200 unsigned char length = urb->actual_length;
201 int i;
202 int result; 201 int result;
203 int status = urb->status; 202 int status = urb->status;
204 203
@@ -227,16 +226,10 @@ static void safe_read_bulk_callback (struct urb *urb)
227 if (safe) { 226 if (safe) {
228 __u16 fcs; 227 __u16 fcs;
229 if (!(fcs = fcs_compute10 (data, length, CRC10_INITFCS))) { 228 if (!(fcs = fcs_compute10 (data, length, CRC10_INITFCS))) {
230
231 int actual_length = data[length - 2] >> 2; 229 int actual_length = data[length - 2] >> 2;
232
233 if (actual_length <= (length - 2)) { 230 if (actual_length <= (length - 2)) {
234
235 info ("%s - actual: %d", __func__, actual_length); 231 info ("%s - actual: %d", __func__, actual_length);
236 232 tty_insert_flip_string(port->tty, data, actual_length);
237 for (i = 0; i < actual_length; i++) {
238 tty_insert_flip_char (port->tty, data[i], 0);
239 }
240 tty_flip_buffer_push (port->tty); 233 tty_flip_buffer_push (port->tty);
241 } else { 234 } else {
242 err ("%s - inconsistent lengths %d:%d", __func__, 235 err ("%s - inconsistent lengths %d:%d", __func__,
@@ -246,9 +239,7 @@ static void safe_read_bulk_callback (struct urb *urb)
246 err ("%s - bad CRC %x", __func__, fcs); 239 err ("%s - bad CRC %x", __func__, fcs);
247 } 240 }
248 } else { 241 } else {
249 for (i = 0; i < length; i++) { 242 tty_insert_flip_string(port->tty, data, length);
250 tty_insert_flip_char (port->tty, data[i], 0);
251 }
252 tty_flip_buffer_push (port->tty); 243 tty_flip_buffer_push (port->tty);
253 } 244 }
254 245
@@ -260,6 +251,7 @@ static void safe_read_bulk_callback (struct urb *urb)
260 251
261 if ((result = usb_submit_urb (urb, GFP_ATOMIC))) { 252 if ((result = usb_submit_urb (urb, GFP_ATOMIC))) {
262 err ("%s - failed resubmitting read urb, error %d", __func__, result); 253 err ("%s - failed resubmitting read urb, error %d", __func__, result);
254 /* FIXME: Need a mechanism to retry later if this happens */
263 } 255 }
264} 256}
265 257
@@ -275,7 +267,7 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
275 267
276 if (!port->write_urb) { 268 if (!port->write_urb) {
277 dbg ("%s - write urb NULL", __func__); 269 dbg ("%s - write urb NULL", __func__);
278 return (0); 270 return 0;
279 } 271 }
280 272
281 dbg ("safe_write write_urb: %d transfer_buffer_length", 273 dbg ("safe_write write_urb: %d transfer_buffer_length",
@@ -283,11 +275,11 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
283 275
284 if (!port->write_urb->transfer_buffer_length) { 276 if (!port->write_urb->transfer_buffer_length) {
285 dbg ("%s - write urb transfer_buffer_length zero", __func__); 277 dbg ("%s - write urb transfer_buffer_length zero", __func__);
286 return (0); 278 return 0;
287 } 279 }
288 if (count == 0) { 280 if (count == 0) {
289 dbg ("%s - write request of 0 bytes", __func__); 281 dbg ("%s - write request of 0 bytes", __func__);
290 return (0); 282 return 0;
291 } 283 }
292 spin_lock_bh(&port->lock); 284 spin_lock_bh(&port->lock);
293 if (port->write_urb_busy) { 285 if (port->write_urb_busy) {
@@ -359,18 +351,21 @@ static int safe_write (struct usb_serial_port *port, const unsigned char *buf, i
359 351
360static int safe_write_room (struct usb_serial_port *port) 352static int safe_write_room (struct usb_serial_port *port)
361{ 353{
362 int room = 0; // Default: no room 354 int room = 0; /* Default: no room */
355 unsigned long flags;
363 356
364 dbg ("%s", __func__); 357 dbg ("%s", __func__);
365 358
359 spin_lock_irqsave(&port->lock, flags);
366 if (port->write_urb_busy) 360 if (port->write_urb_busy)
367 room = port->bulk_out_size - (safe ? 2 : 0); 361 room = port->bulk_out_size - (safe ? 2 : 0);
362 spin_unlock_irqrestore(&port->lock, flags);
368 363
369 if (room) { 364 if (room) {
370 dbg ("safe_write_room returns %d", room); 365 dbg ("safe_write_room returns %d", room);
371 } 366 }
372 367
373 return (room); 368 return room;
374} 369}
375 370
376static int safe_startup (struct usb_serial *serial) 371static int safe_startup (struct usb_serial *serial)