Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3026772rwb; Mon, 15 Aug 2022 16:24:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR73isyDemJqprCdhlJnEWSiiD0uFAt6VUuJnz8kGhz8dIjcWZ302tQT09TeO6vamD53Xoky X-Received: by 2002:a17:907:87b0:b0:731:3dfd:bc8d with SMTP id qv48-20020a17090787b000b007313dfdbc8dmr11334970ejc.607.1660605792077; Mon, 15 Aug 2022 16:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605792; cv=none; d=google.com; s=arc-20160816; b=plD9Zs+4OWtYrvTuGLTTWPJHy1d4U1Wi3FnuxXrmXWdOvQpSX1WT6AJYONx360rYR8 YuIBfXp/9U5j3RD3NbGTK5JbUzQ/DiuBBODXcxMe8NxImY7MvR8avmxFxCUUeFpxNu7n ZCeHQDYqrfKqk3xa8eDQiblU3Xlth6cf0tFuJkazz9d88prFuONE5iA3jWNdBVhbfdlI FoJDnmJItAFQBKkmgMKXUAHLbYyYDuOhIZkW7805iGo54trWsRgDpuMOJxJDGgaAku9i isvi+3wco+dNqvgiuZQLZbWy9mxfu4VlveR9/wmt7OPBkZh29SOZtLcsbzN+pSFK14hs rgUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=g8Y2VLdQhmHnuLgPI0R36vvH0pApF+jO0v9RFT8+9eQ=; b=CeU8FlMXXFc5Kdw2detJGdI0SPUts7EwAvXiDD293Juo8Plkz/uIbTKFNgKw5zj80E zK1Fy6mq2iNfJwtvuxp/qZPviOFe/2vhG+YEL9HpgcNH9DGmK9pTvn5QKYXcAAUPIeiH oXPNwh6XA5aMXFBMNe45Yv/+xtm8ZQACYjPoHbNI1g/8AagcVI66iDpsvwS1nO40XTF3 SmV+PsC4PxQse2VPGk9FgKdDYjcdkTEYJTndC1xaEQDSgdTjIZ6QY7IR537SOU5eTY+N X1SA8zW24Qm2mdLpOSTtoKiZ1AmcL+uCuhMw9U/gEAR2MFQgLdMYyeAr2GAUR09SjDCj duPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=v67NsUBB; 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 ds3-20020a170907724300b00730fdb36019si10035165ejc.21.2022.08.15.16.22.47; Mon, 15 Aug 2022 16:23:12 -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=v67NsUBB; 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 S1351040AbiHOWhc (ORCPT + 99 others); Mon, 15 Aug 2022 18:37:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349654AbiHOWbD (ORCPT ); Mon, 15 Aug 2022 18:31:03 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F073B12AD24; Mon, 15 Aug 2022 12:48:15 -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 ams.source.kernel.org (Postfix) with ESMTPS id CD278B80EAD; Mon, 15 Aug 2022 19:48:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20267C433C1; Mon, 15 Aug 2022 19:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592892; bh=TyFNt0yGMX+HCgNReElfeOZCISJv3dIiyMGCwZjmTq8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v67NsUBBvRVZkArEPzYrsobbJKwOTLt2y2VOOuvkaIMpLLGKjgb89wZBLshbk21st 57GQvrmwSLeFt27Ty0bkge2YdN6h0W8uWG+npOz4O+3TCzGSOh9DB0Z+7iNQzFY5uN FAMRK6okZs58eTi8EOsnT5KFZhJSeLcUXxk+xOTI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nathan Chancellor , Linus Torvalds , Sasha Levin Subject: [PATCH 5.18 0825/1095] usb: cdns3: Dont use priv_dev uninitialized in cdns3_gadget_ep_enable() Date: Mon, 15 Aug 2022 20:03:44 +0200 Message-Id: <20220815180503.436147661@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 From: Nathan Chancellor [ Upstream commit 78acd4ca433425e6dd4032cfc2156c60e34931f2 ] 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 Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- 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 e0cf62e65075..ae049eb28b93 100644 --- a/drivers/usb/cdns3/cdns3-gadget.c +++ b/drivers/usb/cdns3/cdns3-gadget.c @@ -2280,16 +2280,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; -- 2.35.1