usb: dwc3: otg: Avoid unbalanced runtime PM
In dwc3_ext_event_notify() the pm_runtime_status_suspended() call will only check the momentary status of the device, but does not consider that it could be currently active and may be in the middle of or will soon enter a suspended state. In those cases, it would skip an important call to pm_runtime_get(), leaving the usage_counter as 0, the result of which could allow a suspend to trigger prematurely after kicking the OTG state machine. If the controller's suspend routine is completed while later execution assumes the device is not suspended, the system may crash due to invalid unclocked register access. Further, a pm_runtime_put() from otg_sm_work may even exacerbate by allowing the usage_counter to go below 0. The previous commit 48263195 "usb: dwc3: otg: Prevent negative runtime PM count in host mode" tried to fix this by using pm_runtime_put_noidle() to keep from going past 0, but that is only a band-aid. Fix this by checking not just runtime_status but also the current usage_counter. If it's 0, it surely needs to be incremented with the subsequent pm_runtime_get() call. The exit points from the state machine function that allow suspend will then call pm_runtime_put() which would be balanced. Change-Id: Iffe83f022a9128dcb846f2acb26d510f1c611eea Signed-off-by:Jack Pham <jackp@codeaurora.org>
Loading
Please register or sign in to comment