[PATCH] rapidio/rio_cm: Check rio_add_outb_message() return value in TX paths
From: Ian Rogers
Date: Thu Nov 19 2026 - 12:12:08 EST
Both rio_txcq_handler() and riocm_post_send() call
rio_add_outb_message() and unconditionally record cm->tx_buf[tx_slot]
and increment cm->tx_cnt and cm->tx_slot even when queuing fails
(rc != 0). Because no outbound message was queued to the mport
hardware, no TX completion event will ever arrive for that slot,
permanently leaking a TX ring entry in cm->tx_cnt (and leaving a freed
req->buffer pointer in cm->tx_buf[] in rio_txcq_handler()).
Only update cm->tx_buf[], cm->tx_cnt, and cm->tx_slot when
rio_add_outb_message() succeeds, and clear cm->tx_buf[tx_slot] to NULL
in rio_txcq_handler() since req->buffer is immediately freed.
Found via Clang -Wunused-but-set-variable on an x86_64 allyesconfig
build. Verified by building drivers/rapidio/rio_cm.o with LLVM=1 W=1
(-Werror) and -Wunused-but-set-variable, and with a standalone C
reproducer under ASan/UBSan; not runtime-tested on RapidIO hardware.
Fixes: b6e8d4aa1110 ("rapidio: add RapidIO channelized messaging driver")
Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
---
drivers/rapidio/rio_cm.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/drivers/rapidio/rio_cm.c b/drivers/rapidio/rio_cm.c
index c55af5924da2..5b88df79ff53 100644
--- a/drivers/rapidio/rio_cm.c
+++ b/drivers/rapidio/rio_cm.c
@@ -670,12 +670,14 @@ static void rio_txcq_handler(struct cm_dev *cm, int slot)
list_for_each_entry_safe(req, _req, &cm->tx_reqs, node) {
list_del(&req->node);
- cm->tx_buf[cm->tx_slot] = req->buffer;
rc = rio_add_outb_message(cm->mport, req->rdev, cmbox,
req->buffer, req->len);
kfree(req->buffer);
kfree(req);
+ if (rc)
+ continue;
+ cm->tx_buf[cm->tx_slot] = NULL;
++cm->tx_cnt;
++cm->tx_slot;
cm->tx_slot &= (RIOCM_TX_RING_SIZE - 1);
@@ -745,8 +747,11 @@ static int riocm_post_send(struct cm_dev *cm, struct rio_dev *rdev,
goto err_out;
}
- cm->tx_buf[cm->tx_slot] = buffer;
rc = rio_add_outb_message(cm->mport, rdev, cmbox, buffer, len);
+ if (rc)
+ goto err_out;
+
+ cm->tx_buf[cm->tx_slot] = buffer;
riocm_debug(TX, "Add buf@%p destid=%x tx_slot=%d tx_cnt=%d",
buffer, rdev->destid, cm->tx_slot, cm->tx_cnt);
--
2.56.1.708.g77570a6a1d-goog