Skip to content

Commit e52d43c

Browse files
jackp780gregkh
authored andcommitted
usb: dwc3: debugfs: Add and remove endpoint dirs dynamically
commit 8d396bb 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: 41ce145 ("usb: dwc3: core: make dwc3_set_mode() work properly") Cc: stable <stable@vger.kernel.org> Reviewed-by: Peter Chen <peter.chen@kernel.org> Signed-off-by: Jack Pham <jackp@codeaurora.org> Link: https://lore.kernel.org/r/20210529192932.22912-1-jackp@codeaurora.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1b5fbb6 commit e52d43c

3 files changed

Lines changed: 8 additions & 19 deletions

File tree

drivers/usb/dwc3/debug.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,12 @@ static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
413413

414414

415415
#ifdef CONFIG_DEBUG_FS
416+
extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
416417
extern void dwc3_debugfs_init(struct dwc3 *d);
417418
extern void dwc3_debugfs_exit(struct dwc3 *d);
418419
#else
420+
static inline void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
421+
{ }
419422
static inline void dwc3_debugfs_init(struct dwc3 *d)
420423
{ }
421424
static inline void dwc3_debugfs_exit(struct dwc3 *d)

drivers/usb/dwc3/debugfs.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -890,30 +890,14 @@ static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
890890
}
891891
}
892892

893-
static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep,
894-
struct dentry *parent)
893+
void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
895894
{
896895
struct dentry *dir;
897896

898-
dir = debugfs_create_dir(dep->name, parent);
897+
dir = debugfs_create_dir(dep->name, dep->dwc->root);
899898
dwc3_debugfs_create_endpoint_files(dep, dir);
900899
}
901900

902-
static void dwc3_debugfs_create_endpoint_dirs(struct dwc3 *dwc,
903-
struct dentry *parent)
904-
{
905-
int i;
906-
907-
for (i = 0; i < dwc->num_eps; i++) {
908-
struct dwc3_ep *dep = dwc->eps[i];
909-
910-
if (!dep)
911-
continue;
912-
913-
dwc3_debugfs_create_endpoint_dir(dep, parent);
914-
}
915-
}
916-
917901
void dwc3_debugfs_init(struct dwc3 *dwc)
918902
{
919903
struct dentry *root;
@@ -944,7 +928,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
944928
&dwc3_testmode_fops);
945929
debugfs_create_file("link_state", 0644, root, dwc,
946930
&dwc3_link_state_fops);
947-
dwc3_debugfs_create_endpoint_dirs(dwc, root);
948931
}
949932
}
950933

drivers/usb/dwc3/gadget.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,6 +2664,8 @@ static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum)
26642664
INIT_LIST_HEAD(&dep->started_list);
26652665
INIT_LIST_HEAD(&dep->cancelled_list);
26662666

2667+
dwc3_debugfs_create_endpoint_dir(dep);
2668+
26672669
return 0;
26682670
}
26692671

@@ -2707,6 +2709,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
27072709
list_del(&dep->endpoint.ep_list);
27082710
}
27092711

2712+
debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root));
27102713
kfree(dep);
27112714
}
27122715
}

0 commit comments

Comments
 (0)