OpenCloudOS-Kernel/drivers/usb/chipidea
Duoming Zhou 7a58b8d602 usb: chipidea: fix deadlock in ci_otg_del_timer
There is a deadlock in ci_otg_del_timer(), the process is
shown below:

    (thread 1)                  |        (thread 2)
ci_otg_del_timer()              | ci_otg_hrtimer_func()
  ...                           |
  spin_lock_irqsave() //(1)     |  ...
  ...                           |
  hrtimer_cancel()              |  spin_lock_irqsave() //(2)
  (block forever)

We hold ci->lock in position (1) and use hrtimer_cancel() to
wait ci_otg_hrtimer_func() to stop, but ci_otg_hrtimer_func()
also need ci->lock in position (2). As a result, the
hrtimer_cancel() in ci_otg_del_timer() will be blocked forever.

This patch extracts hrtimer_cancel() from the protection of
spin_lock_irqsave() in order that the ci_otg_hrtimer_func()
could obtain the ci->lock.

What`s more, there will be no race happen. Because the
"next_timer" is always under the protection of
spin_lock_irqsave() and we only check whether "next_timer"
equals to NUM_OTG_FSM_TIMERS in the following code.

Fixes: 3a316ec4c9 ("usb: chipidea: use hrtimer for otg fsm timers")
Cc: stable <stable@kernel.org>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/20220918033312.94348-1-duoming@zju.edu.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-11-09 12:34:18 +01:00
..
Kconfig usb: chipidea: make configs for glue drivers visible with EXPERT 2022-09-08 13:32:50 +02:00
Makefile usb: chipidea: add tracepoint support for udc 2020-12-10 08:45:26 +08:00
bits.h USB: chipidea: Use the correct style for SPDX License Identifier 2020-03-16 11:13:47 +08:00
ci.h usb: chipidea: udc: implement get_frame 2022-06-21 16:40:51 +02:00
ci_hdrc_imx.c usb: chipidea: ci_hdrc_imx: use dev_err_probe() 2022-06-21 16:40:54 +02:00
ci_hdrc_imx.h USB: chipidea: fix typo in comment 2022-06-10 11:49:15 +02:00
ci_hdrc_msm.c usb: chipidea: msm: Ensure proper controller reset using role switch API 2020-05-07 08:46:35 +02:00
ci_hdrc_pci.c usb: chipidea: ci_hdrc_pci: Fix improper use of kerneldoc format 2020-07-09 17:19:56 +02:00
ci_hdrc_tegra.c usb: chipidea: tegra: Add runtime PM and OPP support 2021-12-16 14:05:23 +01:00
ci_hdrc_usb2.c usb: chipidea: Add support for VBUS control with PHY 2022-08-31 09:07:52 +02:00
core.c usb: chipidea: udc: implement get_frame 2022-06-21 16:40:51 +02:00
debug.c USB: chipidea: remove dentry storage for debugfs file 2021-05-27 09:34:34 +02:00
host.c usb: chipidea: Add support for VBUS control with PHY 2022-08-31 09:07:52 +02:00
host.h usb: chipidea: add inline for ci_hdrc_host_driver_init if host is not defined 2020-01-22 07:54:27 +01:00
otg.c usb: Remove redundant 'flush_workqueue()' calls 2021-11-17 14:36:57 +01:00
otg.h USB: chipidea: Use the correct style for SPDX License Identifier 2020-03-16 11:13:47 +08:00
otg_fsm.c usb: chipidea: fix deadlock in ci_otg_del_timer 2022-11-09 12:34:18 +01:00
otg_fsm.h USB: chipidea: Use the correct style for SPDX License Identifier 2020-03-16 11:13:47 +08:00
trace.c usb: chipidea: add tracepoint support for udc 2020-12-10 08:45:26 +08:00
trace.h usb: chipidea: tracing: Use the new __vstring() helper 2022-07-15 17:44:40 -04:00
udc.c Linux 5.19-rc4 2022-06-27 10:03:28 +02:00
udc.h usb: chipidea: udc: add software sg list support 2020-05-06 09:42:35 +08:00
ulpi.c usb: chipidea: Always build ULPI code 2018-07-05 14:22:47 +08:00
usbmisc_imx.c usb: chipidea: imx: Fix Battery Charger 1.2 CDP detection 2021-06-16 09:04:22 +08:00