Skip to contentSkip to conversation

bus: mhi: host: Fix uninitialized status handling on BHI/BHIe read errors

PATCH New Ian Rogers 1 participant 1 message Nov 19

Subsystems (2)
lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 bus: mhi: host: Fix uninitialized status handling on BHI/BHIe read errors

mhi_download_rddm_image(), mhi_fw_load_bhie(), and mhi_fw_load_bhi() poll BHI/BHIe status registers inside wait_event_timeout() using:

  mhi_read_reg_field(..., &status) || status

When mhi_read_reg_field() returns a non-zero error code before ever writing *out, the short-circuit OR wakes wait_event_timeout() with a positive return value while leaving status uninitialized on the stack:

- In mhi_fw_load_bhi(), only tx_status == BHI_STATUS_ERROR (0x3) is treated as an error after wait_event_timeout(), so any register read error where stack garbage is not 0x3 causes mhi_fw_load_bhi() to return 0 (success) despite failing to read BHI_STATUS.
- In mhi_download_rddm_image() and mhi_fw_load_bhie(), status is compared against BHIE_*_STATUS_XFER_COMPL (0x2), reading uninitialized stack memory if the first register read fails.

Initialize rx_status and tx_status to their *_RESET (0) constants and require tx_status == BHI_STATUS_SUCCESS after a non-timeout wakeup in mhi_fw_load_bhi() so register read failures reliably return -EIO while genuine timeouts still return -ETIMEDOUT.

Found by enabling Clang's -Wconditional-uninitialized on an x86_64 allyesconfig build, with AI coding assistant help to audit the warning and prepare the fix. Build-tested with Clang; not runtime-tested on MHI hardware.

Fixes cd457afb1667 ("bus: mhi: core: Add support for downloading firmware over BHIe")
Fixes 6fdfdd27328c ("bus: mhi: core: Add support for downloading RDDM image during panic")
---
 drivers/bus/mhi/host/boot.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/bus/mhi/host/boot.c +7 -4
index 19c84913cfb9..439bc9d0797f 100644
@@ -158,7 +158,7 @@ int mhi_download_rddm_image(struct mhi_controller *mhi_cntrl, bool in_panic)
 {
 	void __iomem *base = mhi_cntrl->bhie;
 	struct device *dev = &mhi_cntrl->mhi_dev->dev;
-	u32 rx_status;
+	u32 rx_status = BHIE_RXVECSTATUS_STATUS_RESET;
 
 	if (in_panic)
 		return __mhi_download_rddm_in_panic(mhi_cntrl);
@@ -213,7 +213,7 @@ static int mhi_fw_load_bhie(struct mhi_controller *mhi_cntrl,
 	void __iomem *base = mhi_cntrl->bhie;
 	struct device *dev = &mhi_cntrl->mhi_dev->dev;
 	rwlock_t *pm_lock = &mhi_cntrl->pm_lock;
-	u32 tx_status, sequence_id;
+	u32 tx_status = BHIE_TXVECSTATUS_STATUS_RESET, sequence_id;
 	int ret;
 
 	read_lock_bh(pm_lock);
@@ -261,7 +261,7 @@ static int mhi_fw_load_bhi(struct mhi_controller *mhi_cntrl,
 	struct device *dev = &mhi_cntrl->mhi_dev->dev;
 	rwlock_t *pm_lock = &mhi_cntrl->pm_lock;
 	void __iomem *base = mhi_cntrl->bhi;
-	u32 tx_status, session_id;
+	u32 tx_status = BHI_STATUS_RESET, session_id;
 	int ret;
 
 	read_lock_bh(pm_lock);
@@ -295,7 +295,10 @@ static int mhi_fw_load_bhi(struct mhi_controller *mhi_cntrl,
 		goto invalid_pm_state;
 	}
 
-	return (!ret) ? -ETIMEDOUT : 0;
+	if (!ret)
+		return -ETIMEDOUT;
+
+	return (tx_status == BHI_STATUS_SUCCESS) ? 0 : -EIO;
 
 invalid_pm_state:
 
Signature · 1 line
2.56.1.708.g77570a6a1d-goog