Received: by 10.223.185.116 with SMTP id b49csp6342349wrg; Wed, 28 Feb 2018 07:53:41 -0800 (PST) X-Google-Smtp-Source: AG47ELv7/1e5eXG+CyT2hvgnifl9QJp9cLN29XRirCMc/bK8u5YQGRcsBup74a0HhugYBJR8zOvf X-Received: by 2002:a17:902:8489:: with SMTP id c9-v6mr8023810plo.439.1519833220939; Wed, 28 Feb 2018 07:53:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519833220; cv=none; d=google.com; s=arc-20160816; b=kr6fsebwnRg6hkqtzdzxElngnpz4/hLdbmksep8u7RsobunoPPjxS1CJBQMzsrxvws q1s3S7WXth5ku3/Rx+H19FryMyfhAOIdCTrG8ykne2a5upJv/uiZqahodNmRtu6UF9ZP G2P4RtFlbPFH5OH8moJhlqN5cZawu6dLRxrBdM5YqEkKyiIsHq3/IgCVc9E07ppJBEBy h14vC3TNDQin0Y5GHTBhcueX177Q5IDoCmA/lFXgonoOWSOEn89f+jp0o/sce3UozXcQ l1AwRJNs2x0LWXRbsIPeeU8gt8TpBGiK2b8FklOXuMuqJ5m79fQGCKOqC9CIW8lAjoGI +MBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=SH4O5bM8Mt4doxtgNUwXnZV2VLx6GM9MKH9494xvjYc=; b=fxlI0iH4sJ0u3Sz/tp/1PAJoF/7FxVM5BQpGlWDhu3lbZuqFYf5AgqQxMYvXqGpX7X Vu8o7MDAyO6R21RKBaxvCDrl3C+6+HWGU26cTv7TQSo1ISnIMM23jNLt+GWYaXF1M/UG jP8x0/kI+nXVc8+4m8dpJUYT8K7s2GGH+kl8qPoC1fgH7CvBwGy+RNpo5Z7iup8O++ui rTeNCyHVr2lieDThyb2S0yBqLYTkO98xV3xjmzbnkFK1zYAwHD06SWj0CeQEeWa0FPpM Xev27ihDPFwtMkNo9B/VHEbdO9pRnQOdq4BbXj3z7hkrNuqhWdjFd4Vr6NxuMS78CCHs xxrA== 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 n18si1415833pfj.58.2018.02.28.07.53.26; Wed, 28 Feb 2018 07:53:40 -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 S933877AbeB1Pwh (ORCPT + 99 others); Wed, 28 Feb 2018 10:52:37 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34402 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932426AbeB1Pwe (ORCPT ); Wed, 28 Feb 2018 10:52:34 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yv-0006Xl-3u; Wed, 28 Feb 2018 15:22:33 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yd-0008Ni-Er; Wed, 28 Feb 2018 15:22:15 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Felipe Balbi" , "Colin Ian King" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 020/254] usb: gadget: don't dereference g until after it has been null checked In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Colin Ian King commit b2fc059fa549fe6881d4c1f8d698b0f50bcd16ec upstream. 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: Ben Hutchings --- 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 @@ -103,7 +103,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; @@ -175,8 +174,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; }