]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mailbox: Make mbox_send_message() return error code when tx fails
authorJoonwon Kang <joonwonkang@google.com>
Sun, 10 May 2026 05:41:11 +0000 (05:41 +0000)
committerJassi Brar <jassisinghbrar@gmail.com>
Mon, 18 May 2026 18:35:32 +0000 (13:35 -0500)
When the mailbox controller failed transmitting message, the error code
was only passed to the client's tx done handler and not to
mbox_send_message() in blocking mode. For this reason, the function could
return a false success. This commit resolves the issue by introducing the
tx status and checking it before mbox_send_message() returns.

This commit works with the premise that the multi-threads' access to a
channel in blocking mode is serialized by clients, not by the mailbox
APIs, since the current mbox_send_message() in blocking mode does not
support multi-threads.

Signed-off-by: Joonwon Kang <joonwonkang@google.com>
Reviewed-by: Sudeep Holla <sudeep.holla@kernel.org>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
drivers/mailbox/mailbox.c
include/linux/mailbox_controller.h

index b00f7a32e86613f57ddd41798fb7695c3efa7c72..066702e5a46f368fce34a6c52b95a1e9935f5361 100644 (file)
@@ -98,8 +98,10 @@ static void tx_tick(struct mbox_chan *chan, int r)
        if (chan->cl->tx_done)
                chan->cl->tx_done(chan->cl, mssg, r);
 
-       if (r != -ETIME && chan->cl->tx_block)
+       if (r != -ETIME && chan->cl->tx_block) {
+               chan->tx_status = r;
                complete(&chan->tx_complete);
+       }
 }
 
 static enum hrtimer_restart txdone_hrtimer(struct hrtimer *hrtimer)
@@ -295,6 +297,8 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
                if (ret == 0) {
                        t = -ETIME;
                        tx_tick(chan, t);
+               } else if (chan->tx_status < 0) {
+                       t = chan->tx_status;
                }
        }
 
index dc93287a2a01aeef7299f6b10846dd9058dba84f..26a238a6f941c6ba13c0bdd37151927393ad7428 100644 (file)
@@ -120,6 +120,7 @@ struct mbox_controller {
  * @txdone_method:     Way to detect TXDone chosen by the API
  * @cl:                        Pointer to the current owner of this channel
  * @tx_complete:       Transmission completion
+ * @tx_status:         Transmission status
  * @active_req:                Currently active request hook
  * @msg_count:         No. of mssg currently queued
  * @msg_free:          Index of next available mssg slot
@@ -132,6 +133,7 @@ struct mbox_chan {
        unsigned txdone_method;
        struct mbox_client *cl;
        struct completion tx_complete;
+       int tx_status;
        void *active_req;
        unsigned msg_count, msg_free;
        void *msg_data[MBOX_TX_QUEUE_LEN];