mhi: core: Add NULL check in mhi_get_exec_env

In case power up failed due to incorrect bhi offset
bhi pointer in mhi controller remains NULL. Later if
MHI controller forces RDDM it checks the execution
environment by accessing the BHI offset. This results
into NULL pointer dereference. Fix this by adding NULL
check for both mhi controller and bhi pointer before
reading the BHI offset.

Change-Id: I93f8918d7d595a77a5c8bcb6fd610f1a2b484fc4
Signed-off-by: Hemant Kumar <hemantk@codeaurora.org>
This commit is contained in:
Hemant Kumar 2020-08-17 13:19:25 -07:00
commit 6e8d77cd33

View file

@ -244,8 +244,13 @@ static enum mhi_ee mhi_translate_dev_ee(struct mhi_controller *mhi_cntrl,
enum mhi_ee mhi_get_exec_env(struct mhi_controller *mhi_cntrl)
{
int ret;
u32 exec;
int ret = mhi_read_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_EXECENV, &exec);
if (!mhi_cntrl || !mhi_cntrl->bhi)
return MHI_EE_MAX;
ret = mhi_read_reg(mhi_cntrl, mhi_cntrl->bhi, BHI_EXECENV, &exec);
return (ret) ? MHI_EE_MAX : mhi_translate_dev_ee(mhi_cntrl, exec);
}