mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] bus: mhi: host: Fix uninitialized status handling on BHI/BHIe read errors
@ 2026-11-19 17:04 Ian Rogers
  0 siblings, 0 replies; only message in thread
From: Ian Rogers @ 2026-11-19 17:04 UTC (permalink / raw)
  To: Manivannan Sadhasivam
  Cc: Jeff Hugo, mhi, linux-arm-msm, linux-kernel, llvm, Elkin Cruz,
	Ian Rogers

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")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 drivers/bus/mhi/host/boot.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/mhi/host/boot.c b/drivers/bus/mhi/host/boot.c
index 19c84913cfb9..439bc9d0797f 100644
--- a/drivers/bus/mhi/host/boot.c
+++ b/drivers/bus/mhi/host/boot.c
@@ -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:
 
-- 
2.56.1.708.g77570a6a1d-goog


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-19 17:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 17:04 [PATCH] bus: mhi: host: Fix uninitialized status handling on BHI/BHIe read errors Ian Rogers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®