All of lore.kernel.org
 help / color / mirror / Atom feed
* [BUG] usb: typec: ucsi: possible deadlock in ucsi_pr_swap() and ucsi_handle_connector_change()
@ 2022-02-09  3:50 Jia-Ju Bai
  2022-02-09 14:30 ` Heikki Krogerus
  0 siblings, 1 reply; 6+ messages in thread
From: Jia-Ju Bai @ 2022-02-09  3:50 UTC (permalink / raw)
  To: heikki.krogerus, Greg KH, kyletso, jackp, andy.shevchenko,
	unixbhaskar, subbaram, mrana
  Cc: linux-usb, linux-kernel

Hello,

My static analysis tool reports a possible deadlock in the ucsi driver 
in Linux 5.16:

ucsi_pr_swap()
   mutex_lock(&con->lock); --> Line 962 (Lock A)
   wait_for_completion_timeout(&con->complete, ...) --> Line 981 (Wait X)

ucsi_handle_connector_change()
   mutex_lock(&con->lock); --> Line 763 (Lock A)
   complete(&con->complete); --> Line 782 (Wake X)
   complete(&con->complete); --> Line 807 (Wake X)

When ucsi_pr_swap() is executed, "Wait X" is performed by holding "Lock 
A". If ucsi_handle_connector_change() is executed at this time, "Wake X" 
cannot be performed to wake up "Wait X" in 
ucsi_handle_connector_change(), because "Lock A" has been already held 
by ucsi_handle_connector_change(), causing a possible deadlock.
I find that "Wait X" is performed with a timeout, to relieve the 
possible deadlock; but I think this timeout can cause inefficient execution.

I am not quite sure whether this possible problem is real.
Any feedback would be appreciated, thanks :)


Best wishes,
Jia-Ju Bai

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-03-28  8:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09  3:50 [BUG] usb: typec: ucsi: possible deadlock in ucsi_pr_swap() and ucsi_handle_connector_change() Jia-Ju Bai
2022-02-09 14:30 ` Heikki Krogerus
2022-02-10  2:24   ` Jia-Ju Bai
2022-02-10 14:30     ` Heikki Krogerus
2022-03-25 20:39   ` Jack Pham
2022-03-28  8:28     ` Heikki Krogerus

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.