]> git.baikalelectronics.ru Git - kernel.git/commit
usb: chipidea: fix deadlock in ci_otg_del_timer
authorDuoming Zhou <duoming@zju.edu.cn>
Sun, 18 Sep 2022 03:33:12 +0000 (11:33 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 25 Nov 2022 16:42:18 +0000 (17:42 +0100)
commit3896f841977048ab4df1f8b02feb7680229eeaf4
tree21722b4a3e5248923c30a23b90d11cf44a535fb5
parent4bfc0d5bcb2c02463f8b278c70c6b857bc699006
usb: chipidea: fix deadlock in ci_otg_del_timer

commit 4d7b845c6aa7378eac5d82274e16ce66ad5bf187 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: 167bfdb4df53 ("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>
drivers/usb/chipidea/otg_fsm.c