Return-Path: Received: from mail-sn1nam01on0134.outbound.protection.outlook.com ([104.47.32.134]:5532 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932639AbeAXEQr (ORCPT ); Tue, 23 Jan 2018 23:16:47 -0500 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Colin Ian King , Felipe Balbi , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 099/100] usb: gadget: don't dereference g until after it has been null checked Date: Wed, 24 Jan 2018 04:15:17 +0000 Message-ID: <20180124041414.32065-99-alexander.levin@microsoft.com> References: <20180124041414.32065-1-alexander.levin@microsoft.com> In-Reply-To: <20180124041414.32065-1-alexander.levin@microsoft.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: Colin Ian King [ Upstream commit b2fc059fa549fe6881d4c1f8d698b0f50bcd16ec ] Avoid dereferencing pointer g until after g has been sanity null checked; move the assignment of cdev much later when it is required into a more local scope. Detected by CoverityScan, CID#1222135 ("Dereference before null check") Fixes: b785ea7ce662 ("usb: gadget: composite: fix ep->maxburst initializati= on") Signed-off-by: Colin Ian King Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/gadget/composite.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.= c index 5d061b3d8224..ed9346f0b000 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -150,7 +150,6 @@ int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f, struct usb_ep *_ep) { - struct usb_composite_dev *cdev =3D get_gadget_data(g); struct usb_endpoint_descriptor *chosen_desc =3D NULL; struct usb_descriptor_header **speed_desc =3D NULL; =20 @@ -229,8 +228,12 @@ ep_found: _ep->maxburst =3D comp_desc->bMaxBurst + 1; break; default: - if (comp_desc->bMaxBurst !=3D 0) + if (comp_desc->bMaxBurst !=3D 0) { + struct usb_composite_dev *cdev; + + cdev =3D get_gadget_data(g); ERROR(cdev, "ep0 bMaxBurst must be 0\n"); + } _ep->maxburst =3D 1; break; } --=20 2.11.0