From patchwork Fri Apr 7 03:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Badhri Jagan Sridharan X-Patchwork-Id: 80643 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp17525vqo; Thu, 6 Apr 2023 20:28:54 -0700 (PDT) X-Google-Smtp-Source: AKy350b5NpAK7ScBWNl+785Cvmo+4pPHHSwv8+sBwCoT9B3JPmnfzJAuD/JSGCCSj+vedIOe4LLp X-Received: by 2002:a17:903:294e:b0:1a2:185f:f199 with SMTP id li14-20020a170903294e00b001a2185ff199mr1063469plb.63.1680838133841; Thu, 06 Apr 2023 20:28:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680838133; cv=none; d=google.com; s=arc-20160816; b=IYY5/6bWQw21BaDTe6SbliGLUAR4kbEQMBzOcua+UaEovqnLOoXOZREkH450w4TNQG FmQJWJi12hwzh/9kGLw1wvE+LNUp/ngofNGtw4ThYt7cI5wTa32F65IU13nyeo0/cOXc eR5KP7bfK55olHTY/UgcMx8/5UKGuoKg3rvAxQ07THytL2oDsS26hHREDdsWJS+6+68J NaUdIcf2fjE+iaG3t3oLaLaJmlApEUcU5ebqC7T8IfvhA1p2g1cRWaCQe5RUl5h9KpeH Se9tcsbrGJ0hsdAj533rgy7c5pBthScrWRltZVcJeMzQA04zxpvcP2T2jemrysqSA5Lb DNfQ== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s17-20020a170902c65100b001a1c5d7f9a5si2914030pls.14.2023.04.06.20.28.37; Thu, 06 Apr 2023 20:28:53 -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 S232056AbjDGDHy (ORCPT + 99 others); Thu, 6 Apr 2023 23:07:54 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762486526953704586?= X-GMAIL-MSGID: =?utf-8?q?1762486526953704586?= 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.