diff options
author | Johan Hovold <jhovold@gmail.com> | 2013-12-29 19:23:03 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-03 12:31:47 -0800 |
commit | 383d19c58729e34b3b94e47da20aa7fe4970a577 (patch) | |
tree | 3aada09765cfa3b58a605ef82cb6f3039d34ad16 /drivers/usb/serial | |
parent | a6ec8245bf09fd51a0561ff372a12473b48d269b (diff) | |
download | linux-383d19c58729e34b3b94e47da20aa7fe4970a577.tar.bz2 |
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>
Diffstat (limited to 'drivers/usb/serial')
-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, dev_dbg(&port->dev, "baud set = %d\n", baud); } +static int pl2303_get_line_request(struct usb_serial_port *port, + unsigned char buf[7]) +{ + struct usb_device *udev = port->serial->dev; + int ret; + + ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), + GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, + 0, 0, buf, 7, 100); + if (ret != 7) { + dev_err(&port->dev, "%s - failed: %d\n", __func__, ret); + + if (ret > 0) + ret = -EIO; + + return ret; + } + + dev_dbg(&port->dev, "%s - %7ph\n", __func__, buf); + + return 0; +} + +static int pl2303_set_line_request(struct usb_serial_port *port, + unsigned char buf[7]) +{ + struct usb_device *udev = port->serial->dev; + int ret; + + ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), + SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, + 0, 0, buf, 7, 100); + if (ret != 7) { + dev_err(&port->dev, "%s - failed: %d\n", __func__, ret); + + if (ret > 0) + ret = -EIO; + + return ret; + } + + dev_dbg(&port->dev, "%s - %7ph\n", __func__, buf); + + return 0; +} + static void pl2303_set_termios(struct tty_struct *tty, struct usb_serial_port *port, struct ktermios *old_termios) { @@ -352,7 +398,7 @@ static void pl2303_set_termios(struct tty_struct *tty, struct pl2303_private *priv = usb_get_serial_port_data(port); unsigned long flags; unsigned char *buf; - int i; + int ret; u8 control; if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios)) @@ -366,10 +412,7 @@ static void pl2303_set_termios(struct tty_struct *tty, return; } - i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, - 0, 0, buf, 7, 100); - dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); + pl2303_get_line_request(port, buf); switch (C_CSIZE(tty)) { case CS5: @@ -451,14 +494,8 @@ static void pl2303_set_termios(struct tty_struct *tty, * only used in set_termios, which is serialised against itself. */ if (!old_termios || memcmp(buf, priv->line_settings, 7)) { - i = usb_control_msg(serial->dev, - usb_sndctrlpipe(serial->dev, 0), - SET_LINE_REQUEST, SET_LINE_REQUEST_TYPE, - 0, 0, buf, 7, 100); - - dev_dbg(&port->dev, "0x21:0x20:0:0 %d\n", i); - - if (i == 7) + ret = pl2303_set_line_request(port, buf); + if (!ret) memcpy(priv->line_settings, buf, 7); } @@ -478,10 +515,7 @@ static void pl2303_set_termios(struct tty_struct *tty, } memset(buf, 0, 7); - i = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), - GET_LINE_REQUEST, GET_LINE_REQUEST_TYPE, - 0, 0, buf, 7, 100); - dev_dbg(&port->dev, "0xa1:0x21:0:0 %d - %7ph\n", i, buf); + pl2303_get_line_request(port, buf); if (C_CRTSCTS(tty)) { if (spriv->type == HX) |