Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp968394rwb; Thu, 18 Aug 2022 16:02:37 -0700 (PDT) X-Google-Smtp-Source: AA6agR7VRmD6Mt0KdVTATuQ6UAGKoWy9cUDKBZ73VsJlm8CcNOminY2DnHeBjScEwmryGNDcppZT X-Received: by 2002:a63:5916:0:b0:41d:2c8c:7492 with SMTP id n22-20020a635916000000b0041d2c8c7492mr3998639pgb.81.1660863757522; Thu, 18 Aug 2022 16:02:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660863757; cv=none; d=google.com; s=arc-20160816; b=hHTRPZj44oTcnUXO3PcjonWn1r4t6G4VXa3IH/wKOqmkQodb3yIiZMIbEa+g3cR1tM 2AVOrnFgXE8PcR1pKLsqNKKuW5xNH5dwZEz0afOqDYOeFXZwSi9ChEuZ72ks5wEtMrAa zxJ29orYdlWOSrL0MGgSYrsQ29pjMIswKiyt05pmX/xIr3ZME3RlBYK6XgV0lwauhKPN Xb5OPCd8fQmfaHPk8Dxoud78GAjh+05CtaUHgzChag7dMFpA7Q4ujnvk4WzEdU7FU7nF YtPaci/k6nBrpJ5tATuxCrD9DLfoXGo5QCg+wpa0rLgT8ogbXvxKLjLgo2feMzvZgKT4 JLkA== 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=wwRwc5gIzHue58sA/zSWFhsK6CQ+nASbE2ZgmtvaNyA=; b=nz4xKMWmnUOvVOzIR5JdtBPUnJ70XZfo5F6OxgdGxsE/bACjwAno+pozDcpmLrBZmk tzd0Nk1gS5K46IO7RVWNqj/BUDRvv4x5nUUrmJiq2lPBwft5C3aTIIf5kmi7jUDMRCDu 6GxAW6l1gX5oigaQ48UZyVa9ItkdLLmQzUYvi3+ytrELL5Mww68e28choBIS7J+gbTmK gwp9ROw88Tazef16tb1OQ9DXRX9meiheECVIIQ1bQuX49TVS/6B7oVqu3F1wl/+2sxN5 pxReM5csotv5UJ89Yjg5S8dQoUliv7bpcC8NjmKn/n7DtO5vO9CUb+fBe+KdTzqTMqUk V9DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lIe9SVUC; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rm2-20020a17090b3ec200b001f3e54ca93asi544633pjb.76.2022.08.18.16.02.25; Thu, 18 Aug 2022 16:02:37 -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=@kernel.org header.s=k20201202 header.b=lIe9SVUC; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241453AbiHRWvL (ORCPT + 99 others); Thu, 18 Aug 2022 18:51:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239101AbiHRWvJ (ORCPT ); Thu, 18 Aug 2022 18:51:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6A19D4BF4; Thu, 18 Aug 2022 15:51:07 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 4599B61713; Thu, 18 Aug 2022 22:51:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EA1CC433C1; Thu, 18 Aug 2022 22:51:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660863066; bh=uTUn0Xma80oIh9ZmKSbaaDbBfbuNhdPmQu5lpQjlqhw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lIe9SVUCfOiikxCxqBe7fublJ3f3F07IaHWvFhRtyecZYv6LLNEUnYCVgrm+o13p3 P+uCi92d1AP2pjfEHCQaHCK5p+ClrnscWpcqu2xV99Zs1VFZ73T+w4mdxOH61gF20V dLYU/osoFA93RlkQNldGxCZvRO8Sncbn4O1JOh9D199zyXeg+Jzk0iIfIa2SvBcISw q3zBtXm1lbTzklNqXQbNPL8ujiG07oreK7/ACsmo1+j0wuscTL9J8g09roJnR7Gybn uB8XDLKHHDL++CD/K1raHlaO6/Sy5sAi9Y79bV8C2BkB2t5xBM4A6X5kKxp3pdWh+G tuVemndJAmrtg== Date: Fri, 19 Aug 2022 06:51:00 +0800 From: Peter Chen To: Nathan Chancellor Cc: Greg Kroah-Hartman , Pawel Laszczak , Roger Quadros , Aswath Govindraju , Nick Desaulniers , Tom Rix , Andrey Strachuk , Linus Torvalds , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] usb: cdns3: Don't use priv_dev uninitialized in cdns3_gadget_ep_enable() Message-ID: <20220818225100.GA237489@Peter> References: <20220803162422.2981308-1-nathan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220803162422.2981308-1-nathan@kernel.org> X-Spam-Status: No, score=-7.1 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 22-08-03 09:24:22, Nathan Chancellor wrote: > Clang warns: > > drivers/usb/cdns3/cdns3-gadget.c:2290:11: error: variable 'priv_dev' is uninitialized when used here [-Werror,-Wuninitialized] > dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); > ^~~~~~~~ > include/linux/dev_printk.h:155:18: note: expanded from macro 'dev_dbg' > dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__) > ^~~ > include/linux/dynamic_debug.h:167:7: note: expanded from macro 'dynamic_dev_dbg' > dev, fmt, ##__VA_ARGS__) > ^~~ > include/linux/dynamic_debug.h:152:56: note: expanded from macro '_dynamic_func_call' > __dynamic_func_call(__UNIQUE_ID(ddebug), fmt, func, ##__VA_ARGS__) > ^~~~~~~~~~~ > include/linux/dynamic_debug.h:134:15: note: expanded from macro '__dynamic_func_call' > func(&id, ##__VA_ARGS__); \ > ^~~~~~~~~~~ > drivers/usb/cdns3/cdns3-gadget.c:2278:31: note: initialize the variable 'priv_dev' to silence this warning > struct cdns3_device *priv_dev; > ^ > = NULL > 1 error generated. > > The priv_dev assignment was moved below the if statement to avoid > potentially dereferencing ep before it was checked but priv_dev is used > in the dev_dbg() call. > > To fix this, move the priv_dev and comp_desc assignments back to their > original spot and hoist the ep check above those assignments with a call > to pr_debug() instead of dev_dbg(). > > Fixes: c3ffc9c4ca44 ("usb: cdns3: change place of 'priv_ep' assignment in cdns3_gadget_ep_dequeue(), cdns3_gadget_ep_enable()") > Link: https://github.com/ClangBuiltLinux/linux/issues/1680 > Signed-off-by: Nathan Chancellor Acked-by: Peter Chen > --- > drivers/usb/cdns3/cdns3-gadget.c | 12 ++++++++---- > 1 file changed, 8 insertions(+), 4 deletions(-) > > diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c > index 9ac7d0a8c5da..d21b69997e75 100644 > --- a/drivers/usb/cdns3/cdns3-gadget.c > +++ b/drivers/usb/cdns3/cdns3-gadget.c > @@ -2284,16 +2284,20 @@ static int cdns3_gadget_ep_enable(struct usb_ep *ep, > int ret = 0; > int val; > > + if (!ep) { > + pr_debug("usbss: ep not configured?\n"); > + return -EINVAL; > + } > + > priv_ep = ep_to_cdns3_ep(ep); > + priv_dev = priv_ep->cdns3_dev; > + comp_desc = priv_ep->endpoint.comp_desc; > > - if (!ep || !desc || desc->bDescriptorType != USB_DT_ENDPOINT) { > + if (!desc || desc->bDescriptorType != USB_DT_ENDPOINT) { > dev_dbg(priv_dev->dev, "usbss: invalid parameters\n"); > return -EINVAL; > } > > - comp_desc = priv_ep->endpoint.comp_desc; > - priv_dev = priv_ep->cdns3_dev; > - > if (!desc->wMaxPacketSize) { > dev_err(priv_dev->dev, "usbss: missing wMaxPacketSize\n"); > return -EINVAL; > > base-commit: 8288c99fc263bcafc5df5fa8c278b2eb8106364e > -- > 2.37.1 > -- Thanks, Peter Chen