Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp273800iog; Thu, 30 Jun 2022 00:03:06 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sdCyLIBHjjtPTjqFB269/2r5Cn077wcocM7mBeCQJ4ktxJD60lez80x8TU/IJ04CS5XUm9 X-Received: by 2002:a17:906:c154:b0:711:ce44:a0a0 with SMTP id dp20-20020a170906c15400b00711ce44a0a0mr7500471ejc.420.1656572586399; Thu, 30 Jun 2022 00:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656572586; cv=none; d=google.com; s=arc-20160816; b=HxCnV1ZH8te2DXTvJoBxxGTrMiRI34Nimizhcd0zx7mdFtvChjiBsHJXV05BlVEoU3 mWunsd0F2r6kydDknA4jx0k75igpfK1SoEFMyE7BoEmQPr61Hc39edX0QQ+ffm2Ka5iK vNmWt+hcpKXPjHrACfWK+wOoOLfJcELbiOMKnePfxEsjishiDc06soZyRUqp95iwNrwp loODeiYw1vShRFRC3X/fg4xCOud/A8Pny+ElfcF5vZNVrewDbaPnNiQuq2gJy6rUrZPL 3funF4cXXdkncXUCQ5ofsxvzRwHeJL0QvFIehgguyM0z59ydxjRgQj2hv4YjezlTi6Lu M2+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=HMM2Gyt3yjSffnJn0wznjUrE/ilBXloNJILfet1+hec=; b=UGnfoF52dUbhjZUoJJDpXMtu4h6O/a75ANTZZb6ZGJB/TdaziBk2cneT9r0sdHvEbI io8M5h5Q3GDgEeQ545QnMLC0OopXQwsLr3/jkOinBfZosNLa/Iem6+QHozeJEbLwiPRJ k9ceP6VGjYNU+H+Z0sUigVRJ5Elpw/ZBP/IUQ/ofCYH4LubJyF9zDQ1K7jGoYOWY3vGa ehHMD3FqR5y3xENdWruUM7I2mWuqi2KrTCUh+MhZ/dDmYuSK8uJtO4b/UmN+5Fmz7DvE mRcUfQmw2SqnytaDvrMzCRrhAE8YnmvmFe/ZMXFAlGNwwN+lpUKD4BlzuG5g0kBpRX18 8YnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JdCXLXAF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd9-20020a170907968900b00722fc5e328asi26228061ejc.321.2022.06.30.00.02.17; Thu, 30 Jun 2022 00:03:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JdCXLXAF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232838AbiF3GyM (ORCPT + 99 others); Thu, 30 Jun 2022 02:54:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229529AbiF3GyL (ORCPT ); Thu, 30 Jun 2022 02:54:11 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05DBD20BF5; Wed, 29 Jun 2022 23:54:10 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 7049ECE2A65; Thu, 30 Jun 2022 06:54:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D5F2C34115; Thu, 30 Jun 2022 06:54:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656572047; bh=AoZZBIOZ6lxp4R1mhcbQkpMM8z6raWKSubTBxc3uKjQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=JdCXLXAFdIVNttvrE3zYW5gc495EVxTjSxKY3PzJbtg3xdpmjqtTQH9IioyspcVZZ +Ur+l2PNgwu/YRulMcltk2W2KqOP8/zvvDM3bif4NooRhihc2IzocSGAbvFKOjjE/9 pqK9K2B7S2w/DbcFADGiZMhG1fjVZEzAxxzOlhdE= Date: Thu, 30 Jun 2022 08:54:04 +0200 From: Greg Kroah-Hartman To: Sebin Sebastian Cc: kernel test robot , Neal Liu , Felipe Balbi , Joel Stanley , Andrew Jeffery , linux-aspeed@lists.ozlabs.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 -next] usb: gadget: dereference before null check Message-ID: References: <20220630044706.10772-1-mailmesebin00@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220630044706.10772-1-mailmesebin00@gmail.com> X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 30, 2022 at 10:17:06AM +0530, Sebin Sebastian wrote: > Fix coverity warning dereferencing before null check. _ep and desc is > dereferenced on all paths until the check for null. Move the > initializations after the check for null. How can those values ever be NULL? > Coverity issue: 1518209 > > Reported-by: kernel test robot kernel test robot did not find this issue. > Signed-off-by: Sebin Sebastian What commit id does this change fix? > --- > Changes since v1: Fix the build errors and warnings due to first patch. > Fix the undeclared 'ep' and 'maxpacket' error. Fix the ISO C90 warning. > > drivers/usb/gadget/udc/aspeed_udc.c | 21 ++++++++++++++------- > 1 file changed, 14 insertions(+), 7 deletions(-) > > diff --git a/drivers/usb/gadget/udc/aspeed_udc.c b/drivers/usb/gadget/udc/aspeed_udc.c > index d75a4e070bf7..a43cf8dde2a8 100644 > --- a/drivers/usb/gadget/udc/aspeed_udc.c > +++ b/drivers/usb/gadget/udc/aspeed_udc.c > @@ -341,26 +341,33 @@ static void ast_udc_stop_activity(struct ast_udc_dev *udc) > static int ast_udc_ep_enable(struct usb_ep *_ep, > const struct usb_endpoint_descriptor *desc) > { > - u16 maxpacket = usb_endpoint_maxp(desc); > - struct ast_udc_ep *ep = to_ast_ep(_ep); checking that ep is NULL here is an impossible thing on its own. You did change this so that you didn't check this anymore, which is odd as you did not mention that in the changelog text :( > - struct ast_udc_dev *udc = ep->udc; > - u8 epnum = usb_endpoint_num(desc); > unsigned long flags; > u32 ep_conf = 0; > u8 dir_in; > u8 type; > + u16 maxpacket; > + struct ast_udc_ep *ep; > + struct ast_udc_dev *udc; > + u8 epnum; Why did you reorder these? > > - if (!_ep || !ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT || > - maxpacket == 0 || maxpacket > ep->ep.maxpacket) { > + if (!_ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { > EP_DBG(ep, "Failed, invalid EP enable param\n"); > return -EINVAL; > } > - Why did you remove this line? Also, your To: line is messed up somehow, please fix your email client... thanks, gre gk-h