Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4074144ybg; Mon, 21 Oct 2019 03:24:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqxQBpTCJsPgbOLb4siNZyLaMIY0x0+LHxUlr4HUVMfVzSr3spioQQ7fVHZh6r1CX1/I2Yet X-Received: by 2002:a17:906:4948:: with SMTP id f8mr20845806ejt.318.1571653474245; Mon, 21 Oct 2019 03:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571653474; cv=none; d=google.com; s=arc-20160816; b=oanx7pimarabebgVXDr0uf32IQRrF0dLIII7v/MvlmiSCj0X9jvFw+jMWmujAur21t ve/7tFq1Se/mg4DHny2Jgb5c0QVp9dfR1iMyMymyKJS/wsPC3Uqh9byWImi9lGlhPo50 LQPmeimDrY473XytjN3zDIm7pADCKGwNit62uHQ8PVLTqxbvayRo35s0uf2huHipnIXl k0GGcf2H2RS8MJvoIT1r5bdAl1rat0cdofH2kWQwzpUi1YrqWRWE6q0If55JaixprrDK qBrnjSU1yyXQrrK4HsdYbsyiB28okodyfZ9Xv9bYZUgj25qlIQokC8cLlqaSEOY57qeB 8PwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=CBZdmTDS+rulBmZEuwdHQaBQC/5kJ0DrnFySBDzVkNk=; b=lRS3HxbCYRRIgzfzlXWXm2lumSU1bUZSjPQxDvLhdkbkZTYB/XYbqWfOG4CawGz6uH psMZdLN90qqXqy9piByRLipRwjHQM4BGpRDJfBXBfCyjOtzOJzFxJmJ8D/f9wGndOTlv Ws9nbzoZ325SvO6HRzkaAuNpc0P2t7OKnEDLyKxdK9SnWNOXfHpB94Q+jlw5dTOLOIyf +2ENOivqw5IngA6o/8rkCZQ9ko74nqi3OnvaOQ0QupwhU3SActE8nR+Y76gCc8RKRKFF aW9HC5XaC6w+2ce+2T8bycgp/nzdosrqUUfB6K1t4RzodggibN+TcgFTBmAO51Dv69zJ 8MPQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si4629112edb.341.2019.10.21.03.24.11; Mon, 21 Oct 2019 03:24:34 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728162AbfJUKVZ (ORCPT + 99 others); Mon, 21 Oct 2019 06:21:25 -0400 Received: from inva021.nxp.com ([92.121.34.21]:37272 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726725AbfJUKVY (ORCPT ); Mon, 21 Oct 2019 06:21:24 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 7689C200123; Mon, 21 Oct 2019 12:21:22 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 7A129200A5F; Mon, 21 Oct 2019 12:21:17 +0200 (CEST) Received: from localhost.localdomain (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 1190D402F0; Mon, 21 Oct 2019 18:21:10 +0800 (SGT) From: Yinbo Zhu To: Li Yang , Felipe Balbi Cc: yinbo.zhu@nxp.com, xiaobo.xie@nxp.com, jiafei.pan@nxp.com, Greg Kroah-Hartman , linux-usb@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Ran Wang , Nikhil Badola Subject: [PATCH v1] usb: gadget: Correct NULL pointer checking in fsl gadget Date: Mon, 21 Oct 2019 18:21:53 +0800 Message-Id: <20191021102153.16435-3-yinbo.zhu@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191021102153.16435-1-yinbo.zhu@nxp.com> References: <20191021102153.16435-1-yinbo.zhu@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nikhil Badola Correct NULL pointer checking for endpoint descriptor before it gets dereferenced Signed-off-by: Nikhil Badola Signed-off-by: Ran Wang Reviewed-by: Peter Chen --- drivers/usb/gadget/udc/fsl_udc_core.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c b/drivers/usb/gadget/udc/fsl_udc_core.c index 381fdff12d4e..980cb1382851 100644 --- a/drivers/usb/gadget/udc/fsl_udc_core.c +++ b/drivers/usb/gadget/udc/fsl_udc_core.c @@ -1052,10 +1052,11 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep) u32 bitmask; struct ep_queue_head *qh; - ep = container_of(_ep, struct fsl_ep, ep); - if (!_ep || (!ep->ep.desc && ep_index(ep) != 0)) + if (!_ep || _ep->desc || !(_ep->desc->bEndpointAddress&0xF)) return -ENODEV; + ep = container_of(_ep, struct fsl_ep, ep); + udc = (struct fsl_udc *)ep->udc; if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) -- 2.17.1