bus: mhi: host: Use mhi_tryset_pm_state() for setting fw error state
authorJeffrey Hugo <quic_jhugo@quicinc.com>
Mon, 10 Apr 2023 15:58:12 +0000 (09:58 -0600)
committerManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Mon, 10 Apr 2023 16:02:55 +0000 (21:32 +0530)
commit1d1493bdc25f498468a606a4ece947d155cfa3a9
tree81b018536d6a98844e16b83152956a92fd9d46b7
parentd469d9448a0f1a33c175d3280b1542fa0158ad7a
bus: mhi: host: Use mhi_tryset_pm_state() for setting fw error state

If firmware loading fails, the controller's pm_state is updated to
MHI_PM_FW_DL_ERR unconditionally.  This can corrupt the pm_state as the
update is not done under the proper lock, and also does not validate
the state transition.  The firmware loading can fail due to a detected
syserr, but if MHI_PM_FW_DL_ERR is unconditionally set as the pm_state,
the handling of the syserr can break when it attempts to transition from
syserr detect, to syserr process.

By grabbing the lock, we ensure we don't race with some other pm_state
update.  By using mhi_try_set_pm_state(), we check that the transition
to MHI_PM_FW_DL_ERR is valid via the state machine logic.  If it is not
valid, then some other transition is occurring like syserr processing, and
we assume that will resolve the firmware loading error.

Fixes: 12e050c77be0 ("bus: mhi: core: Move to an error state on any firmware load failure")
Cc: stable@vger.kernel.org
Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
Reviewed-by: Carl Vanderlip <quic_carlv@quicinc.com>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Link: https://lore.kernel.org/r/1681142292-27571-3-git-send-email-quic_jhugo@quicinc.com
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
drivers/bus/mhi/host/boot.c