Received: by 10.223.176.5 with SMTP id f5csp1129426wra; Fri, 2 Feb 2018 11:42:33 -0800 (PST) X-Google-Smtp-Source: AH8x226h0PGtNahs8yki3sikdeCVPQ/Dp2Qhw4p0zZkIZa6+xyPzV7j3ZOdLXbo0kQ62XWaqpqof X-Received: by 2002:a17:902:be09:: with SMTP id r9-v6mr36310195pls.234.1517600553258; Fri, 02 Feb 2018 11:42:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517600553; cv=none; d=google.com; s=arc-20160816; b=HIXvUTY0CpgX8TXi/oLwpcrzcrVUCGSYJn1tHjHLEXL4HMEqkanZV7QGCBp7eUn0NR mJclyaw6VvxhXcbN/JYLy3g/EorWMOVsSyfsgLkH57TjZm0vdtqD91slJkw/Yt/tClof TN9RPunhOEZLHk2tqF1mFtPIU4YGoSIdG16QGreMDuZNN0pby2Rq10hF81aoB2MqI1lB DKlgs3lpoxDWsvQXYmkduEhfQ/e7X/4GZU/93h2bNT7tHrknr/y0ojthmNXDA90I1vZN sOlDkw5uRad5isW0gEb70LvrpNHg1n11e8LvJqlvpyBJMx7uon87hOoQfpTobwcjO7hr sQgw== 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=xb43s24Xe1qtUraR/Vn6R2jirYsqnb6Sief1VM4NZ8Y=; b=fIaU7KkdD2KIrdV4P3DNImtm/sS/jAPA2Y10HQhved3ntJk1Nyg7myPH/CwswWgydI p7eeEFpZjz1Q4MvMAnp6jsMyq3hgYefOI+Dq4oTAHI5zzuI/SjjKI7iMwryimdYEoEJY PkACF0EZAEzIX/LSpciF84JopGIDkrCC20U2sGQ+9Vg80qFpbGp2y6ds4lpf+AVVal6m mSRHkxLcDmPA9bgu8mLHOYN21WHNfdzIvRi4328KyUKhYnZc6K3uOkLLThxtj5r03vUn 8rfRaq/cxIESpl264qyrrCWfkCdwTqp4rzv2eQsOs+icQwTSveTd4TkcG4Bvk2FhUIXn xRbg== 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 1-v6si2370914plw.164.2018.02.02.11.42.17; Fri, 02 Feb 2018 11:42:33 -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 S1754186AbeBBSPT (ORCPT + 99 others); Fri, 2 Feb 2018 13:15:19 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36620 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752714AbeBBRFt (ORCPT ); Fri, 2 Feb 2018 12:05:49 -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 212A3E3B; Fri, 2 Feb 2018 17:05:47 +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.9 68/86] usb: gadget: dont dereference g until after it has been null checked Date: Fri, 2 Feb 2018 17:58:28 +0100 Message-Id: <20180202140828.936895918@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140822.679101338@linuxfoundation.org> References: <20180202140822.679101338@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.9-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; }