diff options
author | Johan Hovold <jhovold@gmail.com> | 2013-12-29 13:23:03 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-03 15:31:47 -0500 |
commit | 383d19c58729e34b3b94e47da20aa7fe4970a577 (patch) | |
tree | 3aada09765cfa3b58a605ef82cb6f3039d34ad16 | |
parent | a6ec8245bf09fd51a0561ff372a12473b48d269b (diff) |
USB: pl2303: add error handling to line requests
Refactor and add error handling to line requests.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/serial/pl2303.c | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c index 1fe8545e9926..28b10cfcb4d3 100644 --- a/drivers/usb/serial/pl2303.c +++ b/drivers/usb/serial/pl2303.c | |||
@@ -344,6 +344,52 @@ static void pl2303_encode_baudrate(struct tty_struct *tty, | |||
344 | dev_dbg(&port->dev, "baud set = %d\n", baud); | 344 | dev_dbg(&port->dev, "baud set = %d\n", baud); |
345 | } | 345 | } |
346 | 346 | ||
347 | static int pl2303_get_line_request(struct usb_serial_port *port, | ||
348 | unsigned char buf[7]) | ||
349 | { | ||
350 | struct usb_device *udev = port->serial->dev; | ||
351 | int ret; | ||
352 | |||
353 | ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), | ||
354 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
355 | 0, 0, buf, 7, 100); | ||
356 | if (ret != 7) { | ||
357 | dev_err(&port->dev, "%s - failed: %d\n", __func__, ret); | ||
358 | |||
359 | if (ret > 0) | ||
360 | ret = -EIO; | ||
361 | |||
362 | return ret; | ||
363 | } | ||
364 | |||
365 | dev_dbg(&port->dev, "%s - %7ph\n", __func__, buf); | ||
366 | |||
367 | return 0; | ||
368 | } | ||
369 | |||
370 | static int pl2303_set_line_request(struct usb_serial_port *port, | ||
371 | unsigned char buf[7]) | ||
372 | { | ||
373 | struct usb_device *udev = port->serial->dev; | ||
374 | int ret; | ||
375 | |||
376 | ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), | ||
377 | SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, | ||
378 | 0, 0, buf, 7, 100); | ||
379 | if (ret != 7) { | ||
380 | dev_err(&port->dev, "%s - failed: %d\n", __func__, ret); | ||
381 | |||
382 | if (ret > 0) | ||
383 | ret = -EIO; | ||
384 | |||
385 | return ret; | ||
386 | } | ||
387 | |||
388 | dev_dbg(&port->dev, "%s - %7ph\n", __func__, buf); | ||
389 | |||
390 | return 0; | ||
391 | } | ||
392 | |||
347 | static void pl2303_set_termios(struct tty_struct *tty, | 393 | static void pl2303_set_termios(struct tty_struct *tty, |
348 | struct usb_serial_port *port, struct ktermios *old_termios) | 394 | struct usb_serial_port *port, struct ktermios *old_termios) |
349 | { | 395 | { |
@@ -352,7 +398,7 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
352 | struct pl2303_private *priv = usb_get_serial_port_data(port); | 398 | struct pl2303_private *priv = usb_get_serial_port_data(port); |
353 | unsigned long flags; | 399 | unsigned long flags; |
354 | unsigned char *buf; | 400 | unsigned char *buf; |
355 | int i; | 401 | int ret; |
356 | u8 control; | 402 | u8 control; |
357 | 403 | ||
358 | if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) | 404 | if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) |
@@ -366,10 +412,7 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
366 | return; | 412 | return; |
367 | } | 413 | } |
368 | 414 | ||
369 | i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 415 | pl2303_get_line_request(port, buf); |
370 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
371 | 0, 0, buf, 7, 100); | ||
372 | dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); | ||
373 | 416 | ||
374 | switch (C_CSIZE(tty)) { | 417 | switch (C_CSIZE(tty)) { |
375 | case CS5: | 418 | case CS5: |
@@ -451,14 +494,8 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
451 | * only used in set_termios, which is serialised against itself. | 494 | * only used in set_termios, which is serialised against itself. |
452 | */ | 495 | */ |
453 | if (!old_termios || memcmp(buf, priv->line_settings, 7)) { | 496 | if (!old_termios || memcmp(buf, priv->line_settings, 7)) { |
454 | i = usb_control_msg(serial->dev, | 497 | ret = pl2303_set_line_request(port, buf); |
455 | usb_sndctrlpipe(serial->dev, 0), | 498 | if (!ret) |
456 | SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, | ||
457 | 0, 0, buf, 7, 100); | ||
458 | |||
459 | dev_dbg(&port->dev, "0x21:0x20:0:0 %d\n", i); | ||
460 | |||
461 | if (i == 7) | ||
462 | memcpy(priv->line_settings, buf, 7); | 499 | memcpy(priv->line_settings, buf, 7); |
463 | } | 500 | } |
464 | 501 | ||
@@ -478,10 +515,7 @@ static void pl2303_set_termios(struct tty_struct *tty, | |||
478 | } | 515 | } |
479 | 516 | ||
480 | memset(buf, 0, 7); | 517 | memset(buf, 0, 7); |
481 | i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), | 518 | pl2303_get_line_request(port, buf); |
482 | GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, | ||
483 | 0, 0, buf, 7, 100); | ||
484 | dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); | ||
485 | 519 | ||
486 | if (C_CRTSCTS(tty)) { | 520 | if (C_CRTSCTS(tty)) { |
487 | if (spriv->type == HX) | 521 | if (spriv->type == HX) |