Return-Path: Received: from omzsmtpe03.verizonbusiness.com ([199.249.25.208]:28750 "EHLO omzsmtpe03.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752102AbdITEqx (ORCPT ); Wed, 20 Sep 2017 00:46:53 -0400 From: "Levin, Alexander (Sasha Levin)" Cc: Johan Hovold , "Levin, Alexander (Sasha Levin)" To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH review for 3.18 14/30] USB: serial: mos7840: fix control-message error handling Date: Wed, 20 Sep 2017 04:45:53 +0000 Message-ID: <20170920044542.7571-14-alexander.levin@verizon.com> References: <20170920044542.7571-1-alexander.levin@verizon.com> In-Reply-To: <20170920044542.7571-1-alexander.levin@verizon.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Johan Hovold [ Upstream commit cd8db057e93ddaacbec025b567490555d2bca280 ] Make sure to detect short transfers when reading a device register. The modem-status handling had sufficient error checks in place, but move handling of short transfers into the register accessor function itself for consistency. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold Signed-off-by: Sasha Levin --- drivers/usb/serial/mos7840.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c index 0b547d9e2aeb..a0dca81dfaca 100644 --- a/drivers/usb/serial/mos7840.c +++ b/drivers/usb/serial/mos7840.c @@ -285,9 +285,15 @@ static int mos7840_get_reg_sync(struct usb_serial_port= *port, __u16 reg, ret =3D usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, MCS_RD_RTYPE, 0, reg, buf, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); + if (ret < VENDOR_READ_LENGTH) { + if (ret >=3D 0) + ret =3D -EIO; + goto out; + } + *val =3D buf[0]; dev_dbg(&port->dev, "%s offset is %x, return val %x\n", __func__, reg, *v= al); - +out: kfree(buf); return ret; } @@ -353,8 +359,13 @@ static int mos7840_get_uart_reg(struct usb_serial_port= *port, __u16 reg, ret =3D usb_control_msg(dev, usb_rcvctrlpipe(dev, 0), MCS_RDREQ, MCS_RD_RTYPE, Wval, reg, buf, VENDOR_READ_LENGTH, MOS_WDR_TIMEOUT); + if (ret < VENDOR_READ_LENGTH) { + if (ret >=3D 0) + ret =3D -EIO; + goto out; + } *val =3D buf[0]; - +out: kfree(buf); return ret; } @@ -1518,10 +1529,10 @@ static int mos7840_tiocmget(struct tty_struct *tty) return -ENODEV; =20 status =3D mos7840_get_uart_reg(port, MODEM_STATUS_REGISTER, &msr); - if (status !=3D 1) + if (status < 0) return -EIO; status =3D mos7840_get_uart_reg(port, MODEM_CONTROL_REGISTER, &mcr); - if (status !=3D 1) + if (status < 0) return -EIO; result =3D ((mcr & MCR_DTR) ? TIOCM_DTR : 0) | ((mcr & MCR_RTS) ? TIOCM_RTS : 0) --=20 2.11.0