[PATCH v2] soc: qcom: rpmh: Preserve the first error from flush_batch()

From: Lee Youngjoon

Date: Sat Dec 05 2026 - 09:45:03 EST


A failed sleep or wake TCS write skips the rest of its cached batch.
If a later batch succeeds, flush_batch() can return success. Once the
individual cached requests also succeed, rpmh_flush() marks the cache
clean even though some batch commands were never programmed. The next
flush then skips those commands until the cache changes.

Keep the first write error and return it after walking the batch list.
Continue to try subsequent independent batches. A partial flush then
leaves the cache dirty so the next flush programs the cached requests
again.

Fixes: c8790cb6da58 ("drivers: qcom: rpmh: add support for batch RPMH request")
Signed-off-by: Lee Youngjoon <getfeus@xxxxxxxxx>
---
Changes in v2:
- Keep processing later cached batches after a write error, as Konrad
pointed out that they can target independent endpoints.
- Test the next rpmh_flush() with the failing batch first and last.

Link to v1: https://lore.kernel.org/r/CA+m4KrAaEbbZywwCq38BqvTuh9dn2+23br6N3FYxB-mix_+R6g@xxxxxxxxxxxxxx
Review: https://lore.kernel.org/r/7807a6d3-1bdf-4a5d-9f55-3a8c2f107aca@xxxxxxxxxxxxxxxx

OpenAI Codex assisted with the change, commit message and host tests.

drivers/soc/qcom/rpmh.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/soc/qcom/rpmh.c b/drivers/soc/qcom/rpmh.c
index 360242a31..a449dcb74 100644
--- a/drivers/soc/qcom/rpmh.c
+++ b/drivers/soc/qcom/rpmh.c
@@ -338,7 +338,8 @@ static int flush_batch(struct rpmh_ctrlr *ctrlr)
{
struct batch_cache_req *req;
const struct rpmh_request *rpm_msg;
- int ret = 0;
+ int first_error = 0;
+ int ret;
int i;

/* Send Sleep/Wake requests to the controller, expect no response */
@@ -347,12 +348,15 @@ static int flush_batch(struct rpmh_ctrlr *ctrlr)
rpm_msg = req->rpm_msgs + i;
ret = rpmh_rsc_write_ctrl_data(ctrlr_to_drv(ctrlr),
&rpm_msg->msg);
- if (ret)
+ if (ret) {
+ if (!first_error)
+ first_error = ret;
break;
+ }
}
}

- return ret;
+ return first_error;
}

/**

base-commit: 1e5bbf63105d0b367efc6df0bf87c7fde0f91995