android_kernel_xiaomi_sm8450/drivers/usb/chipidea
Duoming Zhou efaab05520 usb: chipidea: fix deadlock in ci_otg_del_timer
commit 7a58b8d6021426b796eebfae80983374d9a80a75 upstream.

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-25 17:45:51 +01:00
..
bits.h
ci_hdrc_imx.c usb: chipidea: ci_hdrc_imx: fix potential error pointer dereference in probe 2021-12-01 09:18:59 +01:00
ci_hdrc_imx.h
ci_hdrc_msm.c
ci_hdrc_pci.c
ci_hdrc_tegra.c
ci_hdrc_usb2.c
ci.h
core.c USB: chipidea: fix interrupt deadlock 2021-11-18 14:03:52 +01:00
debug.c
host.c usb: chipidea: host: fix port index underflow and UBSAN complains 2021-09-18 13:40:30 +02:00
host.h
Kconfig
Makefile
otg_fsm.c usb: chipidea: fix deadlock in ci_otg_del_timer 2022-11-25 17:45:51 +01:00
otg_fsm.h
otg.c
otg.h
udc.c usb: chipidea: udc: check request status before setting device address 2022-06-29 08:59:51 +02:00
udc.h
ulpi.c
usbmisc_imx.c