Return-Path: Received: from omzsmtpe03.verizonbusiness.com ([199.249.25.208]:46803 "EHLO omzsmtpe03.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976AbdITEqd (ORCPT ); Wed, 20 Sep 2017 00:46:33 -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 13/30] USB: serial: mos7720: fix control-message error handling Date: Wed, 20 Sep 2017 04:45:53 +0000 Message-ID: <20170920044542.7571-13-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 0d130367abf582e7cbf60075c2a7ab53817b1d14 ] Make sure to log an error on short transfers when reading a device register. Also clear the provided buffer (which if often an uninitialised automatic variable) on errors as the driver currently does not bother to check for errors. Reviewed-by: Greg Kroah-Hartman Signed-off-by: Johan Hovold Signed-off-by: Sasha Levin --- drivers/usb/serial/mos7720.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c index c3b8ae360424..5e3a609fbab4 100644 --- a/drivers/usb/serial/mos7720.c +++ b/drivers/usb/serial/mos7720.c @@ -236,11 +236,16 @@ static int read_mos_reg(struct usb_serial *serial, un= signed int serial_portnum, =20 status =3D usb_control_msg(usbdev, pipe, request, requesttype, value, index, buf, 1, MOS_WDR_TIMEOUT); - if (status =3D=3D 1) + if (status =3D=3D 1) { *data =3D *buf; - else if (status < 0) + } else { dev_err(&usbdev->dev, "mos7720: usb_control_msg() failed: %d\n", status); + if (status >=3D 0) + status =3D -EIO; + *data =3D 0; + } + kfree(buf); =20 return status; --=20 2.11.0