Skip to content

Commit 8d396bb

Browse files
jackp780gregkh
authored andcommitted
usb: dwc3: debugfs: Add and remove endpoint dirs dynamically
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 <[email protected]> Reviewed-by: Peter Chen <[email protected]> Signed-off-by: Jack Pham <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6490fa5 commit 8d396bb

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

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
@@ -886,30 +886,14 @@ static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
886886
}
887887
}
888888

889-
static void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep,
890-
struct dentry *parent)
889+
void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep)
891890
{
892891
struct dentry *dir;
893892

894-
dir = debugfs_create_dir(dep->name, parent);
893+
dir = debugfs_create_dir(dep->name, dep->dwc->root);
895894
dwc3_debugfs_create_endpoint_files(dep, dir);
896895
}
897896

898-
static void dwc3_debugfs_create_endpoint_dirs(struct dwc3 *dwc,
899-
struct dentry *parent)
900-
{
901-
int i;
902-
903-
for (i = 0; i < dwc->num_eps; i++) {
904-
struct dwc3_ep *dep = dwc->eps[i];
905-
906-
if (!dep)
907-
continue;
908-
909-
dwc3_debugfs_create_endpoint_dir(dep, parent);
910-
}
911-
}
912-
913897
void dwc3_debugfs_init(struct dwc3 *dwc)
914898
{
915899
struct dentry *root;
@@ -940,7 +924,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
940924
&dwc3_testmode_fops);
941925
debugfs_create_file("link_state", 0644, root, dwc,
942926
&dwc3_link_state_fops);
943-
dwc3_debugfs_create_endpoint_dirs(dwc, root);
944927
}
945928
}
946929

drivers/usb/dwc3/gadget.c

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

2756+
dwc3_debugfs_create_endpoint_dir(dep);
2757+
27562758
return 0;
27572759
}
27582760

@@ -2796,6 +2798,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
27962798
list_del(&dep->endpoint.ep_list);
27972799
}
27982800

2801+
debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root));
27992802
kfree(dep);
28002803
}
28012804
}

0 commit comments

Comments
 (0)