mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Evgenii Shatokhin <e.shatokhin@yadro.com>
To: Jassi Brar <jassisinghbrar@gmail.com>
Cc: <linux-kernel@vger.kernel.org>, Ilya Kuznetsov <ilya@yadro.com>,
	<linux@yadro.com>, Evgenii Shatokhin <e.shatokhin@yadro.com>
Subject: [PATCH 1/2] mailbox: Propagate errors from .send_data() callback to mbox_send_message()
Date: Thu, 15 Sep 2022 19:47:29 +0300	[thread overview]
Message-ID: <20220915164730.515767-2-e.shatokhin@yadro.com> (raw)
In-Reply-To: <20220915164730.515767-1-e.shatokhin@yadro.com>

msg_submit() calls .send_data() function from the mailbox controller driver
to place the first of the queued messages to the mailbox. Depending on the
actual driver used, this operation could fail.

In this case, if mbox_send_message() is called in blocking mode, it will
always return -ETIME rather than the actual error reported by the
underlying driver. This could be confusing, so let us propagate the
error from msg_submit() to mbox_send_message().

The errors from msg_submit() called in tx_tick() should be handled in a
subsequent patch.

Signed-off-by: Evgenii Shatokhin <e.shatokhin@yadro.com>
---
 drivers/mailbox/mailbox.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 4229b9b5da98..04db5ef58f93 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -50,17 +50,24 @@ static int add_to_rbuf(struct mbox_chan *chan, void *mssg)
 	return idx;
 }
 
-static void msg_submit(struct mbox_chan *chan)
+static int msg_submit(struct mbox_chan *chan)
 {
 	unsigned count, idx;
 	unsigned long flags;
 	void *data;
-	int err = -EBUSY;
+	int err = 0;
 
 	spin_lock_irqsave(&chan->lock, flags);
 
-	if (!chan->msg_count || chan->active_req)
+	if (!chan->msg_count) {
+		spin_unlock_irqrestore(&chan->lock, flags);
+		return 0;
+	}
+
+	if (chan->active_req) {
+		err = -EBUSY;
 		goto exit;
+	}
 
 	count = chan->msg_count;
 	idx = chan->msg_free;
@@ -88,6 +95,7 @@ static void msg_submit(struct mbox_chan *chan)
 		hrtimer_start(&chan->mbox->poll_hrt, 0, HRTIMER_MODE_REL);
 		spin_unlock_irqrestore(&chan->mbox->poll_hrt_lock, flags);
 	}
+	return err;
 }
 
 static void tx_tick(struct mbox_chan *chan, int r)
@@ -256,6 +264,7 @@ EXPORT_SYMBOL_GPL(mbox_client_peek_data);
 int mbox_send_message(struct mbox_chan *chan, void *mssg)
 {
 	int t;
+	int err;
 
 	if (!chan || !chan->cl)
 		return -EINVAL;
@@ -266,7 +275,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
 		return t;
 	}
 
-	msg_submit(chan);
+	err = msg_submit(chan);
 
 	if (chan->cl->tx_block) {
 		unsigned long wait;
@@ -284,7 +293,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg)
 		}
 	}
 
-	return t;
+	return (err < 0) ? err : t;
 }
 EXPORT_SYMBOL_GPL(mbox_send_message);
 
-- 
2.34.1


  reply	other threads:[~2022-09-15 16:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15 16:47 [PATCH 0/2] mailbox: Fix error handling in mbox_send_message() Evgenii Shatokhin
2022-09-15 16:47 ` Evgenii Shatokhin [this message]
2022-09-16 15:57   ` [PATCH 1/2] mailbox: Propagate errors from .send_data() callback to mbox_send_message() Jassi Brar
2022-09-15 16:47 ` [PATCH 2/2] mailbox: Error out early if the mbox driver has failed to submit the message Evgenii Shatokhin
2022-09-16 17:04   ` Jassi Brar
2022-09-18 16:32     ` Evgeny Shatokhin
2022-10-05 12:11       ` Evgeny Shatokhin

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=20220915164730.515767-2-e.shatokhin@yadro.com \
    --to=e.shatokhin@yadro.com \
    --cc=ilya@yadro.com \
    --cc=jassisinghbrar@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@yadro.com \
    /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®