Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3931851pxj; Mon, 21 Jun 2021 09:38:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzu9jKtc7V3vZPSEufOiipBv5J1GwkvyEXjMai5RQFqX5AxSqpwRRKO1v6zCd4aeILu4Whf X-Received: by 2002:a17:906:6d59:: with SMTP id a25mr17483272ejt.83.1624293494038; Mon, 21 Jun 2021 09:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293494; cv=none; d=google.com; s=arc-20160816; b=Q3F1bHX266FCLl6HjIo4NzvEPYrcs9XVUza27D7dpap0D1wYKHVKIusoATfxjX2XlA vR2E+ecf47HnHyX2NO+fPMUxvlc/cyaqtGk6FUhQ07dUVKmdoy2NJ+nVel6tE9olTVEV xfmF2JiqhsuCmUXw2wS+tce3y+QW2Km5bL/AJtq3G1n4IVVGJChSGP2m+YSzjlZ9vHUW ZELIpQIceqjvETQwaswEpVFW8lW5pn6t9EEDBomPdGrYzh7OPApcw29N+q8gKUVThxAE ar1282OdoDPfgg2Xcmz5v7NQL23vp/S0b/sF2b/mPtLAw5gaVqlXvd6fiGkJSE7hLAE3 pkxg== 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=uUSpuGrTbXR8JT7/LG7KRKUmCX9QigfGo8AUZtBSiME=; b=ve65KlmTDECjU0IT7ZGkoxzvpeKywzhmjykhAySnAwZMLi2eJIQ0RtlBaZC6Mcv2sK OsXcYC5rsyWeU3eSprtztHS0gL62sTBVALTCnbxxvgm3P1tCoHO+RK9FvijBonbk09BW 5/gVU2WC57ddBJ+6RA6GkpEiZgcFrzgOVopiOSgbmL+ih1LDijMdR8P4c6rCM+1nx9+v KaRJNWTt8qCBDQ+AP42nFfNH/HeANrWJI1k6rKwTSV4mJCt64QNphcgTlsu2gyKaFnD/ c0CbaQqAb9VA7B1T1S6BkapiJXvYQDSe/cFwiGiY/iIYYm12KcLsYi7G1iF4gsPCtuJo UY8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GAM91Ygx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp16si13071320ejc.164.2021.06.21.09.37.50; Mon, 21 Jun 2021 09:38:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GAM91Ygx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S230429AbhFUQij (ORCPT + 99 others); Mon, 21 Jun 2021 12:38:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:56006 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232870AbhFUQeu (ORCPT ); Mon, 21 Jun 2021 12:34:50 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 54603613D5; Mon, 21 Jun 2021 16:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292829; bh=jQEeaVpPnD6zkNVkg1xGkBB1fSQSXQa9IVa78TSTjxk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GAM91Ygx+INeFv35N0upTGU677HhpvYtcXgzp15yEexgGLqagryqRbvJJPZ8aKLql xYp6tUEGN1e6F2m1NVQaA2olPTSysWW0fGJUsTstD5w5swRLUPvLsA00FRpu5HsriE MU4ZblzZq8s2L9E8L2gxjyJ/IVnc/d+gK3F0ymNU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Chen , Jack Pham Subject: [PATCH 5.10 145/146] usb: dwc3: debugfs: Add and remove endpoint dirs dynamically Date: Mon, 21 Jun 2021 18:16:15 +0200 Message-Id: <20210621154920.820697815@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jack Pham commit 8d396bb0a5b62b326f6be7594d8bd46b088296bd upstream. The DWC3 DebugFS directory and files are currently created once during probe. This includes creation of subdirectories for each of the gadget's endpoints. This works fine for peripheral-only controllers, as dwc3_core_init_mode() calls dwc3_gadget_init() just prior to calling dwc3_debugfs_init(). However, for dual-role controllers, dwc3_core_init_mode() will instead call dwc3_drd_init() which is problematic in a few ways. First, the initial state must be determined, then dwc3_set_mode() will have to schedule drd_work and by then dwc3_debugfs_init() could have already been invoked. Even if the initial mode is peripheral, dwc3_gadget_init() happens after the DebugFS files are created, and worse so if the initial state is host and the controller switches to peripheral much later. And secondly, even if the gadget endpoints' debug entries were successfully created, if the controller exits peripheral mode, its dwc3_eps are freed so the debug files would now hold stale references. So it is best if the DebugFS endpoint entries are created and removed dynamically at the same time the underlying dwc3_eps are. Do this by calling dwc3_debugfs_create_endpoint_dir() as each endpoint is created, and conversely remove the DebugFS entry when the endpoint is freed. Fixes: 41ce1456e1db ("usb: dwc3: core: make dwc3_set_mode() work properly") Cc: stable Reviewed-by: Peter Chen Signed-off-by: Jack Pham Link: https://lore.kernel.org/r/20210529192932.22912-1-jackp@codeaurora.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/dwc3/debug.h | 3 +++ drivers/usb/dwc3/debugfs.c | 21 ++------------------- drivers/usb/dwc3/gadget.c | 3 +++ 3 files changed, 8 insertions(+), 19 deletions(-) --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h @@ -413,9 +413,12 @@ static inline const char *dwc3_gadget_ge #ifdef CONFIG_DEBUG_FS +extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep); extern void dwc3_debugfs_init(struct dwc3 *d); extern void dwc3_debugfs_exit(struct dwc3 *d); #else +static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep) +{ } static inline void dwc3_debugfs_init(struct dwc3 *d) { } static inline void dwc3_debugfs_exit(struct dwc3 *d) --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c @@ -890,30 +890,14 @@ static void dwc3_debugfs_create_endpoint } } -static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep, - struct dentry *parent) +void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep) { struct dentry *dir; - dir = debugfs_create_dir(dep->name, parent); + dir = debugfs_create_dir(dep->name, dep->dwc->root); dwc3_debugfs_create_endpoint_files(dep, dir); } -static void dwc3_debugfs_create_endpoint_dirs(struct dwc3 *dwc, - struct dentry *parent) -{ - int i; - - for (i = 0; i < dwc->num_eps; i++) { - struct dwc3_ep *dep = dwc->eps[i]; - - if (!dep) - continue; - - dwc3_debugfs_create_endpoint_dir(dep, parent); - } -} - void dwc3_debugfs_init(struct dwc3 *dwc) { struct dentry *root; @@ -944,7 +928,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc) &dwc3_testmode_fops); debugfs_create_file("link_state", 0644, root, dwc, &dwc3_link_state_fops); - dwc3_debugfs_create_endpoint_dirs(dwc, root); } } --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2664,6 +2664,8 @@ static int dwc3_gadget_init_endpoint(str INIT_LIST_HEAD(&dep->started_list); INIT_LIST_HEAD(&dep->cancelled_list); + dwc3_debugfs_create_endpoint_dir(dep); + return 0; } @@ -2707,6 +2709,7 @@ static void dwc3_gadget_free_endpoints(s list_del(&dep->endpoint.ep_list); } + debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root)); kfree(dep); } }