linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Jack Pham <jackp@codeaurora.org>,
	Peter Chen <peter.chen@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: [PATCH 4.19 080/109] usb: dwc3: debugfs: Add and remove endpoint dirs dynamically
Date: Mon, 28 Jun 2021 10:32:36 -0400	[thread overview]
Message-ID: <20210628143305.32978-81-sashal@kernel.org> (raw)
In-Reply-To: <20210628143305.32978-1-sashal@kernel.org>

From: Jack Pham <jackp@codeaurora.org>

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 <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>
---
 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(-)

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index 4f75ab3505b7..069db13f3a10 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -653,9 +653,12 @@ static inline const char *dwc3_gadget_generic_cmd_status_string(int status)
 
 
 #ifdef CONFIG_DEBUG_FS
+extern void dwc3_debugfs_create_endpoint_dir(struct dwc3_ep *dep);
 extern void dwc3_debugfs_init(struct dwc3 *);
 extern void dwc3_debugfs_exit(struct dwc3 *);
 #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)
diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 04ce7c01a09e..58a2479d8e6a 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -725,30 +725,14 @@ static void dwc3_debugfs_create_endpoint_files(struct dwc3_ep *dep,
 	}
 }
 
-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;
@@ -777,7 +761,6 @@ void dwc3_debugfs_init(struct dwc3 *dwc)
 				    &dwc3_testmode_fops);
 		debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root, dwc,
 				    &dwc3_link_state_fops);
-		dwc3_debugfs_create_endpoint_dirs(dwc, root);
 	}
 }
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 1396ee529792..c93bed41d988 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2255,6 +2255,8 @@ static int dwc3_gadget_init_endpoint(struct dwc3 *dwc, u8 epnum)
 	INIT_LIST_HEAD(&dep->started_list);
 	INIT_LIST_HEAD(&dep->cancelled_list);
 
+	dwc3_debugfs_create_endpoint_dir(dep);
+
 	return 0;
 }
 
@@ -2298,6 +2300,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
 			list_del(&dep->endpoint.ep_list);
 		}
 
+		debugfs_remove_recursive(debugfs_lookup(dep->name, dwc->root));
 		kfree(dep);
 	}
 }
-- 
2.30.2


  parent reply	other threads:[~2021-06-28 15:03 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 14:31 [PATCH 4.19 000/109] 4.19.196-rc1 review Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 001/109] net: ieee802154: fix null deref in parse dev addr Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 002/109] HID: quirks: Set INCREMENT_USAGE_ON_DUPLICATE for Saitek X65 Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 003/109] HID: hid-sensor-hub: Return error for hid_set_field() failure Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 004/109] HID: Add BUS_VIRTUAL to hid_connect logging Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 005/109] HID: usbhid: fix info leak in hid_submit_ctrl Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 006/109] ARM: OMAP2+: Fix build warning when mmc_omap is not built Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 007/109] gfs2: Prevent direct-I/O write fallback errors from getting lost Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 008/109] HID: gt683r: add missing MODULE_DEVICE_TABLE Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 009/109] gfs2: Fix use-after-free in gfs2_glock_shrink_scan Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 010/109] scsi: target: core: Fix warning on realtime kernels Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 011/109] ethernet: myri10ge: Fix missing error code in myri10ge_probe() Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 012/109] scsi: scsi_devinfo: Add blacklist entry for HPE OPEN-V Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 013/109] nvme-loop: reset queue count to 1 in nvme_loop_destroy_io_queues() Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 014/109] nvme-loop: clear NVME_LOOP_Q_LIVE when nvme_loop_configure_admin_queue() fails Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 015/109] nvme-loop: check for NVME_LOOP_Q_LIVE in nvme_loop_destroy_admin_queue() Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 016/109] net: ipconfig: Don't override command-line hostnames or domains Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 017/109] rtnetlink: Fix missing error code in rtnl_bridge_notify() Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 018/109] net/x25: Return the correct errno code Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 019/109] net: " Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 020/109] fib: " Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 021/109] dmaengine: ALTERA_MSGDMA depends on HAS_IOMEM Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 022/109] dmaengine: QCOM_HIDMA_MGMT " Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 023/109] dmaengine: stedma40: add missing iounmap() on error in d40_probe() Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 024/109] afs: Fix an IS_ERR() vs NULL check Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 025/109] mm/memory-failure: make sure wait for page writeback in memory_failure Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 026/109] batman-adv: Avoid WARN_ON timing related checks Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 027/109] net: ipv4: fix memory leak in netlbl_cipsov4_add_std Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 028/109] net: rds: fix memory leak in rds_recvmsg Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 029/109] udp: fix race between close() and udp_abort() Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 030/109] rtnetlink: Fix regression in bridge VLAN configuration Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 031/109] net/mlx5e: Remove dependency in IPsec initialization flows Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 032/109] net/mlx5e: Block offload of outer header csum for UDP tunnels Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 033/109] netfilter: synproxy: Fix out of bounds when parsing TCP options Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 034/109] sch_cake: Fix out of bounds when parsing TCP options and header Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 035/109] alx: Fix an error handling path in 'alx_probe()' Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 036/109] net: stmmac: dwmac1000: Fix extended MAC address registers definition Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 037/109] net: add documentation to socket.c Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 038/109] net: make get_net_ns return error if NET_NS is disabled Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 039/109] qlcnic: Fix an error handling path in 'qlcnic_probe()' Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 040/109] netxen_nic: Fix an error handling path in 'netxen_nic_probe()' Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 041/109] net: qrtr: fix OOB Read in qrtr_endpoint_post Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 042/109] ptp: ptp_clock: Publish scaled_ppm_to_ppb Sasha Levin
2021-06-28 14:31 ` [PATCH 4.19 043/109] ptp: improve max_adj check against unreasonable values Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 044/109] net: cdc_ncm: switch to eth%d interface naming Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 045/109] net: usb: fix possible use-after-free in smsc75xx_bind Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 046/109] net: fec_ptp: fix issue caused by refactor the fec_devtype Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 047/109] net: ipv4: fix memory leak in ip_mc_add1_src Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 048/109] net/af_unix: fix a data-race in unix_dgram_sendmsg / unix_release_sock Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 049/109] be2net: Fix an error handling path in 'be_probe()' Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 050/109] net: hamradio: fix memory leak in mkiss_close Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 051/109] net: cdc_eem: fix tx fixup skb leak Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 052/109] icmp: don't send out ICMP messages with a source address of 0.0.0.0 Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 053/109] net: ethernet: fix potential use-after-free in ec_bhf_remove Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 054/109] ASoC: rt5659: Fix the lost powers for the HDA header Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 055/109] pinctrl: ralink: rt2880: avoid to error in calls is pin is already enabled Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 056/109] radeon: use memcpy_to/fromio for UVD fw upload Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 057/109] hwmon: (scpi-hwmon) shows the negative temperature properly Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 058/109] can: bcm: fix infoleak in struct bcm_msg_head Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 059/109] can: mcba_usb: fix memory leak in mcba_usb Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 060/109] usb: core: hub: Disable autosuspend for Cypress CY7C65632 Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 061/109] tracing: Do not stop recording cmdlines when tracing is off Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 062/109] tracing: Do not stop recording comms if the trace file is being read Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 063/109] tracing: Do no increment trace_clock_global() by one Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 064/109] PCI: Mark TI C667X to avoid bus reset Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 065/109] PCI: Mark some NVIDIA GPUs " Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 066/109] PCI: Add ACS quirk for Broadcom BCM57414 NIC Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 067/109] PCI: Work around Huawei Intelligent NIC VF FLR erratum Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 068/109] ARCv2: save ABI registers across signal handling Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 069/109] dmaengine: pl330: fix wrong usage of spinlock flags in dma_cyclc Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 070/109] cfg80211: make certificate generation more robust Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 071/109] net: bridge: fix vlan tunnel dst null pointer dereference Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 072/109] net: bridge: fix vlan tunnel dst refcnt when egressing Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 073/109] mm/slub: clarify verification reporting Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 074/109] mm/slub.c: include swab.h Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 075/109] net: fec_ptp: add clock rate zero check Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 076/109] tools headers UAPI: Sync linux/in.h copy with the kernel sources Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 077/109] KVM: arm/arm64: Fix KVM_VGIC_V3_ADDR_TYPE_REDIST read Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 078/109] can: bcm/raw/isotp: use per module netdevice notifier Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 079/109] inet: use bigger hash table for IP ID generation Sasha Levin
2021-06-28 14:32 ` Sasha Levin [this message]
2021-06-28 14:32 ` [PATCH 4.19 081/109] usb: dwc3: core: fix kernel panic when do reboot Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 082/109] x86/fpu: Reset state for all signal restore failures Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 083/109] module: limit enabling module.sig_enforce Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 084/109] drm/nouveau: wait for moving fence after pinning v2 Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 085/109] drm/radeon: wait for moving fence after pinning Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 086/109] ARM: 9081/1: fix gcc-10 thumb2-kernel regression Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 087/109] Makefile: Move -Wno-unused-but-set-variable out of GCC only block Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 088/109] MIPS: generic: Update node names to avoid unit addresses Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 089/109] Revert "PCI: PM: Do not read power state in pci_enable_device_flags()" Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 090/109] mac80211: remove warning in ieee80211_get_sband() Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 091/109] cfg80211: call cfg80211_leave_ocb when switching away from OCB Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 092/109] mac80211: drop multicast fragments Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 093/109] net: ethtool: clear heap allocations for ethtool function Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 094/109] ping: Check return value of function 'ping_queue_rcv_skb' Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 095/109] inet: annotate date races around sk->sk_txhash Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 096/109] net: caif: fix memory leak in ldisc_open Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 097/109] net/packet: annotate accesses to po->bind Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 098/109] net/packet: annotate accesses to po->ifindex Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 099/109] r8152: Avoid memcpy() over-reading of ETH_SS_STATS Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 100/109] sh_eth: " Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 101/109] r8169: " Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 102/109] KVM: selftests: Fix kvm_check_cap() assertion Sasha Levin
2021-06-28 14:32 ` [PATCH 4.19 103/109] net: qed: Fix memcpy() overflow of qed_dcbx_params() Sasha Levin
2021-06-28 14:33 ` [PATCH 4.19 104/109] PCI: Add AMD RS690 quirk to enable 64-bit DMA Sasha Levin
2021-06-28 14:33 ` [PATCH 4.19 105/109] net: ll_temac: Avoid ndo_start_xmit returning NETDEV_TX_BUSY Sasha Levin
2021-06-28 14:33 ` [PATCH 4.19 106/109] pinctrl: stm32: fix the reported number of GPIO lines per bank Sasha Levin
2021-06-28 14:33 ` [PATCH 4.19 107/109] nilfs2: fix memory leak in nilfs_sysfs_delete_device_group Sasha Levin
2021-06-28 14:33 ` [PATCH 4.19 108/109] i2c: robotfuzz-osif: fix control-request directions Sasha Levin
2021-06-28 14:33 ` [PATCH 4.19 109/109] Linux 4.19.196-rc1 Sasha Levin
2021-06-29 10:08 ` [PATCH 4.19 000/109] 4.19.196-rc1 review Naresh Kamboju
2021-06-29 12:11 ` Sudip Mukherjee
2021-06-29 18:19 ` Guenter Roeck
2021-06-30  1:00 ` Samuel Zou
2021-07-01 10:21 ` Pavel Machek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210628143305.32978-81-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jackp@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.chen@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).