Received: by 10.223.176.46 with SMTP id f43csp271366wra; Tue, 23 Jan 2018 20:45:25 -0800 (PST) X-Google-Smtp-Source: AH8x225ns+iwUN6JlD0uyZXbX86qS220fRrmaXmH2u+mMFfrnGrQFPcsrzYVSuFJZyKJbKpablCe X-Received: by 10.99.126.89 with SMTP id o25mr3210975pgn.161.1516769125460; Tue, 23 Jan 2018 20:45:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516769125; cv=none; d=google.com; s=arc-20160816; b=A9mvthhX4YpvH/dZ7A9C+8Wq/GmZLnNABDiUgQof5/ZAxednrohuMLh3b/n7QvzWrb cjn4YBG8eNgSGkzwMDX2ed01Un71TL7OjvHTMoSdQ2SX/gQuqMH2sm58N4C+s4fgsWPh WJzBy+8OR9l8CVcd4r2crtSxC0GBBMDNx96tKVo14lyIzAZ9GyhSyz3MXiSU1qep3XHT MuheSbflpuwVAWv77yiy2l/VAi+oI6L9HQwnnvmj2QBDUxdQqEMs/7Eq0JQ0BFVJ6WI7 tZcXLgip3UTZXlTAenqLQF0BjaK7cxXRqZNJk4io8uW2RykDb8VVdu6QwhMR+RevUibe NmHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=JMSQo/WxCgTMiMYQYaOwa1Pl/TfJ9okfSVypkS9jJBc=; b=WarXdGdifhP/FiZgVem/mKCzdNCWgTCMWjUD58kUSNBo1dcKPTvZW00sJdAOiK2tUq DvoDY8RdAiWcksr0PJ42eHLjHPt27SUgCOraZ6XW9kdj0x4rJdadUpK353zq8uYbeKvZ rpyaJ1jJtr/M6QRrkTaLaAvMUmwsMaXxlfrsdrI3SbUPb9DWKhb3+gdPyG4sDAuZ7xF8 d0aDpTr7Eq4x4CCnQ3h7N5ExjdIY9S7AFYCGnOZ2K1jN87y7rOfAnnYSohLTrZASAT4T Qq58gkUGzbILAy60TEF+HQrdvNlx4ASwAcm2zkU4JV4T4wBbGczVcS0XeTBfY4ElFvmq hkNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=SvGPJ9lk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f63si2276238pfc.226.2018.01.23.20.45.12; Tue, 23 Jan 2018 20:45:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=SvGPJ9lk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932900AbeAXEoN (ORCPT + 99 others); Tue, 23 Jan 2018 23:44:13 -0500 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=JMSQo/WxCgTMiMYQYaOwa1Pl/TfJ9okfSVypkS9jJBc=; b=SvGPJ9lkFTHdLzOE1QKiY7DLK+H0FQloaHtm+kLBz/3KMCliO1kKiul88asEwk9qRrnWGlXfdR3wJzkj5H3duK6uwxbEVuthHOm79O34XYAm3vLvVlY3s9diScob4LVYQIO+tbhtNh/46QUfRTVhbzIaVdIIUuvsRRkSiRwsVK8= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0727.namprd21.prod.outlook.com (10.167.110.39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.464.1; Wed, 24 Jan 2018 04:16:41 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::6485:b98:d15e:9da7%2]) with mapi id 15.20.0464.000; Wed, 24 Jan 2018 04:16:41 +0000 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 Thread-Topic: [PATCH AUTOSEL for 4.14 099/100] usb: gadget: don't dereference g until after it has been null checked Thread-Index: AQHTlMnw/XXYTDS0J0ylGvbm0k/AsA== 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> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0727;7:/jMNk8mf2ck+tahbm+IxCiz68YMjQvkEBj0fpf97gOTmCjDY6CE17aVVrw4HS9M0NBtO39ezbbQV5Devq+NTg0L8xHgo9xiecmDGQSntT7m046/Hld/tSNfl1DXHjD5qdSenfeleEwc2+Uq6a00VOdy2ULS/J+mGlhQwdGEFhbFB7/dEX8XbDTo7+SZtSLn68/LsFk0B1Srg1F3+xujENf3+YUWY8f/DkYdEq2yVSnN9oK1yjKehsMMdO4dNDnCP x-ms-office365-filtering-correlation-id: d37da803-f0d7-4c1e-4636-08d562e1456c x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(2017052603307)(7193020);SRVR:DM5PR2101MB0727; x-ms-traffictypediagnostic: DM5PR2101MB0727: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(198206253151910)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3231046)(2400081)(944501161)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041288)(20161123560045)(20161123558120)(20161123564045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB0727;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0727; x-forefront-prvs: 056297E276 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(396003)(366004)(39380400002)(39860400002)(376002)(189003)(199004)(86612001)(6506007)(106356001)(76176011)(6346003)(54906003)(575784001)(86362001)(2501003)(110136005)(1076002)(7736002)(5250100002)(3660700001)(316002)(26005)(102836004)(2950100002)(6666003)(99286004)(97736004)(22452003)(107886003)(6436002)(53936002)(478600001)(66066001)(14454004)(2900100001)(6512007)(2906002)(5660300001)(8936002)(4326008)(10290500003)(305945005)(10090500001)(68736007)(25786009)(81166006)(72206003)(36756003)(8676002)(81156014)(3846002)(6116002)(3280700002)(105586002)(6486002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0727;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: hBzex2TnzMrE72Hx9IVDrPQ61lfgOJv3Kf058rdYN16K/PS0yi3sMyzIURx8cawismf7Q+RGOEPHi1CBBNPFXQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d37da803-f0d7-4c1e-4636-08d562e1456c X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jan 2018 04:15:17.6335 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0727 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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