mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Matt Porter <mporter@kernel.crashing.org>,
	Alexandre Bounine <alex.bou9@gmail.com>
Cc: linux-kernel@vger.kernel.org, llvm@lists.linux.dev,
	 Elkin Cruz <elkin@google.com>, Ian Rogers <irogers@google.com>
Subject: [PATCH] rapidio/rio_cm: Check rio_add_outb_message() return value in TX paths
Date: Thu, 19 Nov 2026 09:10:26 -0800	[thread overview]
Message-ID: <20261119171026.1535538-1-irogers@google.com> (raw)

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@google.com>
---
 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


                 reply	other threads:[~2026-11-19 17:10 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119171026.1535538-1-irogers@google.com \
    --to=irogers@google.com \
    --cc=alex.bou9@gmail.com \
    --cc=elkin@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mporter@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®