From: Alexandre Rapaille via B4 Relay <devnull+arapaille.atlr-engineering.com@kernel.org>
To: Jassi Brar <jassisinghbrar@gmail.com>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Abel Vesa <abelvesa@kernel.org>, Luca Weiss <luca@lucaweiss.eu>
Cc: linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org,
Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>,
Alexandre Rapaille <arapaille@atlr-engineering.com>
Subject: [PATCH v2 1/2] mailbox: Add mbox_request_channel_optional()
Date: Thu, 03 Dec 2026 11:57:00 +0100 [thread overview]
Message-ID: <20261203-smsm-null-mbox-v2-1-b4b6e224b127@atlr-engineering.com> (raw)
In-Reply-To: <20261203-smsm-null-mbox-v2-0-b4b6e224b127@atlr-engineering.com>
From: Alexandre Rapaille <arapaille@atlr-engineering.com>
Some clients have mailboxes for only some of their 'mboxes' indexes and
fall back to another doorbell for the rest. mbox_request_channel() logs
an error for each missing or empty entry before the client can fall back.
Add an _optional variant that returns NULL for such an entry, like the
other *_get_optional() helpers.
Suggested-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
Signed-off-by: Alexandre Rapaille <arapaille@atlr-engineering.com>
---
drivers/mailbox/mailbox.c | 62 ++++++++++++++++++++++++++++++------------
include/linux/mailbox_client.h | 1 +
2 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index efacd24a085d..2702367a34d0 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -408,24 +408,8 @@ int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)
}
EXPORT_SYMBOL_GPL(mbox_bind_client);
-/**
- * mbox_request_channel - Request a mailbox channel.
- * @cl: Identity of the client requesting the channel.
- * @index: Index of mailbox specifier in 'mboxes' property.
- *
- * The Client specifies its requirements and capabilities while asking for
- * a mailbox channel. It can't be called from atomic context.
- * The channel is exclusively allocated and can't be used by another
- * client before the owner calls mbox_free_channel.
- * After assignment, any packet received on this channel will be
- * handed over to the client via the 'rx_callback'.
- * The framework holds reference to the client, so the mbox_client
- * structure shouldn't be modified until the mbox_free_channel returns.
- *
- * Return: Pointer to the channel assigned to the client if successful.
- * ERR_PTR for request failure.
- */
-struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
+static struct mbox_chan *__mbox_request_channel(struct mbox_client *cl, int index,
+ bool optional)
{
struct fwnode_reference_args fwspec;
struct fwnode_handle *fwnode;
@@ -451,6 +435,8 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
ret = fwnode_property_get_reference_args(fwnode, "mboxes", "#mbox-cells",
0, index, &fwspec);
if (ret) {
+ if (optional && ret == -ENOENT)
+ return NULL;
dev_err(dev, "%s: can't parse \"%s\" property\n", __func__, "mboxes");
return ERR_PTR(ret);
}
@@ -488,8 +474,48 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
return chan;
}
+
+/**
+ * mbox_request_channel - Request a mailbox channel.
+ * @cl: Identity of the client requesting the channel.
+ * @index: Index of mailbox specifier in 'mboxes' property.
+ *
+ * The Client specifies its requirements and capabilities while asking for
+ * a mailbox channel. It can't be called from atomic context.
+ * The channel is exclusively allocated and can't be used by another
+ * client before the owner calls mbox_free_channel.
+ * After assignment, any packet received on this channel will be
+ * handed over to the client via the 'rx_callback'.
+ * The framework holds reference to the client, so the mbox_client
+ * structure shouldn't be modified until the mbox_free_channel returns.
+ *
+ * Return: Pointer to the channel assigned to the client if successful.
+ * ERR_PTR for request failure.
+ */
+struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index)
+{
+ return __mbox_request_channel(cl, index, false);
+}
EXPORT_SYMBOL_GPL(mbox_request_channel);
+/**
+ * mbox_request_channel_optional - Request a mailbox channel that may be absent.
+ * @cl: Identity of the client requesting the channel.
+ * @index: Index of mailbox specifier in 'mboxes' property.
+ *
+ * Like mbox_request_channel(), but a missing or empty 'mboxes' entry at
+ * @index is not an error.
+ *
+ * Return: Pointer to the channel assigned to the client if successful,
+ * NULL if there is no entry at @index,
+ * ERR_PTR for request failure.
+ */
+struct mbox_chan *mbox_request_channel_optional(struct mbox_client *cl, int index)
+{
+ return __mbox_request_channel(cl, index, true);
+}
+EXPORT_SYMBOL_GPL(mbox_request_channel_optional);
+
struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
const char *name)
{
diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h
index e5997120f45c..042bc0e19158 100644
--- a/include/linux/mailbox_client.h
+++ b/include/linux/mailbox_client.h
@@ -41,6 +41,7 @@ int mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl);
struct mbox_chan *mbox_request_channel_byname(struct mbox_client *cl,
const char *name);
struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index);
+struct mbox_chan *mbox_request_channel_optional(struct mbox_client *cl, int index);
int mbox_send_message(struct mbox_chan *chan, void *mssg);
int mbox_flush(struct mbox_chan *chan, unsigned long timeout);
void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */
--
2.43.0
next prev parent reply other threads:[~2026-12-03 10:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 10:56 [PATCH v2 0/2] soc: qcom: smsm: Don't log an error for hosts without a mailbox Alexandre Rapaille via B4 Relay
2026-12-03 10:57 ` Alexandre Rapaille via B4 Relay [this message]
2026-12-03 11:37 ` [PATCH v2 1/2] mailbox: Add mbox_request_channel_optional() Konrad Dybcio
2026-12-03 10:57 ` [PATCH v2 2/2] soc: qcom: smsm: Don't log an error for hosts without a mailbox Alexandre Rapaille via B4 Relay
2026-12-03 11:45 ` Konrad Dybcio
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=20261203-smsm-null-mbox-v2-1-b4b6e224b127@atlr-engineering.com \
--to=devnull+arapaille.atlr-engineering.com@kernel.org \
--cc=abelvesa@kernel.org \
--cc=andersson@kernel.org \
--cc=arapaille@atlr-engineering.com \
--cc=jassisinghbrar@gmail.com \
--cc=konrad.dybcio@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca@lucaweiss.eu \
/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®