Received: by 10.223.176.5 with SMTP id f5csp1022790wra; Fri, 2 Feb 2018 09:52:32 -0800 (PST) X-Google-Smtp-Source: AH8x226qBcy/7FYCsad5rLEfU29e3OuAV6nZvSADXd1U3hv81K4Bt5AhTT2E0PR3XaLxddLGRGCe X-Received: by 2002:a17:902:60c7:: with SMTP id k7-v6mr7065510pln.316.1517593952272; Fri, 02 Feb 2018 09:52:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517593952; cv=none; d=google.com; s=arc-20160816; b=gfn82Ydft0nFmsUO8gizSPfu6yzNAkQmFse2QYCc+rShBd1K11YilO1muQsehotvGi 5sTkiAAPDBeW8cdcqx8OZgaTgcEruXJ484CsKl78wYfsAgLsF3G5VuHtcp2e4bVw1cMJ KPxevcazIdMN95CDLs9FJ5+FKGEpYqV9HMEneK8XWR+vZ0izgo9fxBFEK1mk/7xQEkBS ur228eFVKDbE5YiZr8WyoMml9HzNfomRXi0IMuChks2xgdGxd22j2s1ZycBC4J1lUvAc QA+tZYbMZqo4Xr5nR+NDI4ygtXDAx2DqS8MSLMwmap3HJxUJz7CP7Zj26yjkvlbu2pje G14w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=JOqKCXtePEpv7/DuG4GE0cq/habkACRNuvmaOqT9N8M=; b=VENxkuMZ3duG8QNpSFxKgxRyt9Zz1i6JTwITXy3Oz6l/mhniq+qdPlC8lEb0GPhV3q XhL1lK7f22uKwm+86zwUStHNkcWBCb6SMc2Jdmj0625mmY6EV8GYBNZullSD3lxGSH1G /+CGYO6s50typjWZ1804tIgdikOZDKTgjs32At3qtOkSzI/FxZbOXG/j1KCjqb7vYK3o B21V0bzjc3gZ8LhjX0PqDS518ptJtRk4vKKybsRc0Zz9r87uK1X3DRYNWXAAPz9Oreak JVZ8WGA9UdbUcYJCkw0+3joHbfz6TiscqkE0VWcM9xChBKOPTInHKtJXxdC6HtUvexbW AHJA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o18si2108677pfa.407.2018.02.02.09.52.17; Fri, 02 Feb 2018 09:52:32 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753766AbeBBRuL (ORCPT + 99 others); Fri, 2 Feb 2018 12:50:11 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39134 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753375AbeBBRMv (ORCPT ); Fri, 2 Feb 2018 12:12:51 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 79654EF7; Fri, 2 Feb 2018 17:12:50 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Colin Ian King , Felipe Balbi , Sasha Levin Subject: [PATCH 4.14 125/156] usb: gadget: dont dereference g until after it has been null checked Date: Fri, 2 Feb 2018 17:58:26 +0100 Message-Id: <20180202140846.036004738@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ 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 initialization") Signed-off-by: Colin Ian King Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/composite.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -150,7 +150,6 @@ int config_ep_by_speed(struct usb_gadget struct usb_function *f, struct usb_ep *_ep) { - struct usb_composite_dev *cdev = get_gadget_data(g); struct usb_endpoint_descriptor *chosen_desc = NULL; struct usb_descriptor_header **speed_desc = NULL; @@ -229,8 +228,12 @@ ep_found: _ep->maxburst = comp_desc->bMaxBurst + 1; break; default: - if (comp_desc->bMaxBurst != 0) + if (comp_desc->bMaxBurst != 0) { + struct usb_composite_dev *cdev; + + cdev = get_gadget_data(g); ERROR(cdev, "ep0 bMaxBurst must be 0\n"); + } _ep->maxburst = 1; break; }