Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp345747rwl; Thu, 6 Apr 2023 20:47:54 -0700 (PDT) X-Google-Smtp-Source: AKy350Zv0IEaLanWvLMhlHAZv/7WMjhs5XvMTp9gTXCVCgwkKJHHWf7StriXBQ/YkFxqvijBYZ+h X-Received: by 2002:a17:903:181:b0:19e:baa6:5860 with SMTP id z1-20020a170903018100b0019ebaa65860mr1278851plg.2.1680839274277; Thu, 06 Apr 2023 20:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680839274; cv=none; d=google.com; s=arc-20160816; b=1Isofj68EUCaeTfneTeVRK/BMB6m+wlKVMrMF8oF3ycwaPK0SOq4OXOVjqCXUelu69 CcFAM916iGVvPQ7M6gmWhnocxP9tUqzWgGLDltcK0iXBQjDg76CQ4GUjSAz3cfxA7y5a KcOF3jPI6xbGh5/UbpnIvm3r7mtVSgKYlJS5UocCbRJFyLxPvYuT77vZ1GNG8qlCBzKs 4YkVU1Wiy5u7PyDP0iKt+HX8me3G9yOb35nrRtLhFlYxveEANq28ETklLD/0t1AXlIay lkuTfAoVvUUsMJMDiTxw2k40f35fyZ3FnjW+6YfKjb+e5yBFGWfDDxVVbVgAVd6gKHPk SgNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=Jny1t4aP2MW1cAWhzQxvg7zKF2Kee9upIHXowqdJtzI=; b=kCUVTaaIo6BARIC+emtE/teYWbytW13m3pxOZUlwfBLQV6z9OBv+F5GdJUyZJUD0Mv h671phPwl/RadbQ88o91xlQd/hZGsHzLB5aJoKtgz4lHtXqHYoxPJoeCKqxnnB76jWet J8FiVjKEiPQPLT+YTBJzyV8I90+lzeGUlfnOh6DbYZIkuL/nzWmiSPLhqtb8vsbBkCFP uvR3QgrQ8nEg/KSIIFktA0FULxIIf2JlKLbDxqHehlHTSS7OXli2/S5RGjuAaWxcnYFA nHNUfEXtH2+atsu6rsFdo+srN93LyztQtXQqNvXFh77AhtfoO5DXC/aye+K3yC6n55+O tfJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="j/Ti1ynq"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c22-20020a170902849600b00195f4f578fasi2899691plo.564.2023.04.06.20.47.42; Thu, 06 Apr 2023 20:47:54 -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=@google.com header.s=20210112 header.b="j/Ti1ynq"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236387AbjDGDHx (ORCPT + 99 others); Thu, 6 Apr 2023 23:07:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231712AbjDGDHs (ORCPT ); Thu, 6 Apr 2023 23:07:48 -0400 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5C457EFE for ; Thu, 6 Apr 2023 20:07:47 -0700 (PDT) Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-62628f72048so27225b3a.0 for ; Thu, 06 Apr 2023 20:07:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1680836867; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Jny1t4aP2MW1cAWhzQxvg7zKF2Kee9upIHXowqdJtzI=; b=j/Ti1ynqQJNmTjDS+d8GP8j7a8fO3W54VaSvCYm3y57BC/lIFchkeRUCVUYrIMTz5S bAKFNhZJbMxSySvVJlESv83ufYCSMUuekE6UbVGXTh1OahC9umRU7s0B1eyaGNiIZBk0 taAjAjGptagveCpB9A7MGpqhnUgzcC5yzUzQB84ERisnVvExLmxDvlD5A7z53ptFrz+X rpudp/J10VHnWYkam4OcMttS9ISDPZPtOxso3bOaj5tfQ4s1J7XGjQdvc9LkNHp5P0c6 o9SiGkeflfe8Hk1Z/NCKiqsn9NS4IaGDR1BYjCz3KM+Aflx6Kxu338navntTFKn3kgwW SM8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680836867; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Jny1t4aP2MW1cAWhzQxvg7zKF2Kee9upIHXowqdJtzI=; b=IM84ACg1WQRhE2gYQdbKdghf49NCZEjvonNhw/w3e0NiJGh7WWiyTYdHx2nB85Vplr n0SVm63uBiLkA8Plv+sfEI1UDrphe0FUF+SJNRyWG8RpAig0EYWlbaBmq/lFZJZQ34iL F6A2DLXs6kgSLYAwr2N5XWUiz4T7L3+bunwEkYAIKaXYlYRKL7e6Mos3zAoJnw3GZ797 9R1eKRboJgwjv+TCyL1kBSrxnwYWbgn1BUi8lB7GPGtyT9zyCmbNxz6tdVKIv49J69zr GjxSfxpmu9FsI3rrcYNxj2IF6QN11YUlRoAokSv2CysJs/oWWFMgnqc8rsC6mLgw1xzV Ca4g== X-Gm-Message-State: AAQBX9dDiiO2bHkTcn/mv6P6+EtOGNR37SiHqYz/BDtNtLThDagnokI7 unzUhpqwXAJkq9b45hkzx/WvHLPS6bQ= X-Received: from badhri.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:6442]) (user=badhri job=sendgmr) by 2002:a05:6a00:2da9:b0:625:cda5:c28c with SMTP id fb41-20020a056a002da900b00625cda5c28cmr570625pfb.6.1680836867446; Thu, 06 Apr 2023 20:07:47 -0700 (PDT) Date: Fri, 7 Apr 2023 03:07:41 +0000 In-Reply-To: <20230407030741.3163220-1-badhri@google.com> Mime-Version: 1.0 References: <20230407030741.3163220-1-badhri@google.com> X-Mailer: git-send-email 2.40.0.577.gac1e443424-goog Message-ID: <20230407030741.3163220-2-badhri@google.com> Subject: [PATCH v4 2/2] usb: gadget: udc: core: Prevent redundant calls to pullup From: Badhri Jagan Sridharan To: gregkh@linuxfoundation.org, stern@rowland.harvard.edu, colin.i.king@gmail.com, xuetao09@huawei.com, quic_eserrao@quicinc.com, water.zhangjiantao@huawei.com, peter.chen@freescale.com, balbi@ti.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Badhri Jagan Sridharan Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 usb_gadget_connect calls gadget->ops->pullup without checking whether gadget->connected was previously set. Make this symmetric to usb_gadget_disconnect by returning early if gadget->connected is already set. Cc: stable@vger.kernel.org Fixes: 5a1da544e572 ("usb: gadget: core: do not try to disconnect gadget if it is not connected") Signed-off-by: Badhri Jagan Sridharan --- Changes since v3: * none Changes since v2: * none Changes since v1: * Fixed commit message comments. --- drivers/usb/gadget/udc/core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index af92c2e8e10c..1c5403ce9e7c 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -703,6 +703,9 @@ static int usb_gadget_connect_locked(struct usb_gadget *gadget) goto out; } + if (gadget->connected) + goto out; + if (gadget->deactivated || !gadget->udc->started) { /* * If gadget is deactivated we only save new state. -- 2.40.0.577.gac1e443424-goog