On Tue, Apr 04, 2023 at 03:30:55PM +0530, Udipto Goswami wrote: > When the dwc3 device is runtime suspended, various required clocks would > get disabled and it is not guaranteed that access to any registers would > work. Depending on the SoC glue, a register read could be as benign as > returning 0 or be fatal enough to hang the system. > > In order to prevent such scenarios of fatal errors, bail out of debugfs > function is dwc3 is suspended. > > Signed-off-by: Oliver Neukum <oneukum@xxxxxxxx> > Signed-off-by: Udipto Goswami <quic_ugoswami@xxxxxxxxxxx> > --- > v4: Introduced pm_runtime_get_if_in_use in order to make sure dwc3 isn't > suspended while accessing the registers. > > drivers/usb/dwc3/debugfs.c | 191 ++++++++++++++++++++++++++++++++----- > 1 file changed, 169 insertions(+), 22 deletions(-) > > diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c > index 850df0e6bcab..e57cafb7da4b 100644 > --- a/drivers/usb/dwc3/debugfs.c > +++ b/drivers/usb/dwc3/debugfs.c > @@ -543,13 +543,25 @@ static int dwc3_link_state_show(struct seq_file *s, void *unused) > enum dwc3_link_state state; > u32 reg; > u8 speed; > + int ret = 0; > + > + ret = pm_runtime_get_if_in_use(dwc->dev); > + /* check if pm runtime get fails, bail out early */ > + if (ret < 0) > + goto err_nolock; > + > + if (!ret) { > + ret = -EINVAL; > + dev_err(dwc->dev, > + "Invalid operation, DWC3 suspended!"); > + goto err_nolock; > + } This is backwards. If you need the device to be active to access these registers then you should resume it unconditionally instead of failing. Johan