Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: kr494167@gmail.com
To: jassisinghbrar@gmail.com, gary.yang@cixtech.com, fugang.duan@cixtech.com
Cc: cix-kernel-upstream@cixtech.com, peter.chen@cixtech.com,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	Surendra Singh Chouhan <kr494167@gmail.com>
Subject: [PATCH] mailbox: cix: validate channel parameters early and convert to dev_err_probe
Date: Fri, 24 Jul 2026 14:12:15 +0530	[thread overview]
Message-ID: <20260724084215.51749-1-kr494167@gmail.com> (raw)

From: Surendra Singh Chouhan <kr494167@gmail.com>

cix_mbox_startup() checked fast channel index constraints (index < 0 ||
index > CIX_MBOX_FAST_IDX) inside the channel switch block after
calling request_irq(). If validation failed, it triggered a free_irq()
cleanup path. Validating channel parameters prior to request_irq()
avoids unnecessary IRQ registration/teardown churn.

In addition, cix_mbox_probe() logged property errors referencing
"cix,mbox_dir" (with an underscore) instead of the actual DT property
name "cix,mbox-dir". Convert cix_mbox_probe() error paths to use
dev_err_probe() and fix the DT property string spelling.

Fixes: fe2aa2361ddb ("mailbox: add CIX mailbox driver")
Signed-off-by: Surendra Singh Chouhan <kr494167@gmail.com>
---
 drivers/mailbox/cix-mailbox.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/mailbox/cix-mailbox.c b/drivers/mailbox/cix-mailbox.c
index 43c76cdab24a..24cea67c407d 100644
--- a/drivers/mailbox/cix-mailbox.c
+++ b/drivers/mailbox/cix-mailbox.c
@@ -403,6 +403,13 @@ static int cix_mbox_startup(struct mbox_chan *chan)
 	int index = cp->index, ret;
 	u32 val;
 
+	if (cp->type == CIX_MBOX_TYPE_FAST && priv->dir == CIX_MBOX_RX) {
+		if (index < 0 || index > CIX_MBOX_FAST_IDX) {
+			dev_err(priv->dev, "Invalid index %d\n", index);
+			return -EINVAL;
+		}
+	}
+
 	ret = request_irq(priv->irq, cix_mbox_isr, IRQF_NO_SUSPEND,
 			  dev_name(priv->dev), chan);
 	if (ret) {
@@ -448,11 +455,6 @@ static int cix_mbox_startup(struct mbox_chan *chan)
 	case CIX_MBOX_TYPE_FAST:
 		/* Only RX channel has intterupt */
 		if (priv->dir == CIX_MBOX_RX) {
-			if (index < 0 || index > CIX_MBOX_FAST_IDX) {
-				dev_err(priv->dev, "Invalid index %d\n", index);
-				ret = -EINVAL;
-				goto failed;
-			}
 			/* enable fast channel interrupt */
 			val = cix_mbox_read(priv, CIX_INT_ENABLE_SIDE_B);
 			val |= CIX_FAST_CH_INT(index);
@@ -587,19 +589,18 @@ static int cix_mbox_probe(struct platform_device *pdev)
 	if (priv->irq < 0)
 		return priv->irq;
 
-	if (device_property_read_string(dev, "cix,mbox-dir", &dir_str)) {
-		dev_err(priv->dev, "cix,mbox_dir property not found\n");
-		return -EINVAL;
-	}
+	if (device_property_read_string(dev, "cix,mbox-dir", &dir_str))
+		return dev_err_probe(dev, -EINVAL,
+				     "cix,mbox-dir property not found\n");
 
 	if (!strcmp(dir_str, "tx"))
 		priv->dir = 0;
 	else if (!strcmp(dir_str, "rx"))
 		priv->dir = 1;
-	else {
-		dev_err(priv->dev, "cix,mbox_dir=%s is not expected\n", dir_str);
-		return -EINVAL;
-	}
+	else
+		return dev_err_probe(dev, -EINVAL,
+				     "cix,mbox-dir=%s is not expected\n",
+				     dir_str);
 
 	cix_mbox_init(priv);
 
@@ -613,9 +614,9 @@ static int cix_mbox_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, priv);
 	ret = devm_mbox_controller_register(dev, &priv->mbox);
 	if (ret)
-		dev_err(dev, "Failed to register mailbox %d\n", ret);
+		return dev_err_probe(dev, ret, "Failed to register mailbox\n");
 
-	return ret;
+	return 0;
 }
 
 static const struct of_device_id cix_mbox_dt_ids[] = {
-- 
2.55.0



                 reply	other threads:[~2026-07-24  8:42 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=20260724084215.51749-1-kr494167@gmail.com \
    --to=kr494167@gmail.com \
    --cc=cix-kernel-upstream@cixtech.com \
    --cc=fugang.duan@cixtech.com \
    --cc=gary.yang@cixtech.com \
    --cc=jassisinghbrar@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.chen@cixtech.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