[PATCH] soc: apple: mailbox: fix error handling in apple_mbox_get()

Harshit Mogalapalli harshit.m.mogalapalli at oracle.com
Mon Jan 22 10:01:16 PST 2024


When ret is 0 and args.np is not NULL, returning zero is success
which is incorrect.

Also fix error codes

Fixes: 6e1457fcad3f ("soc: apple: mailbox: Add ASC/M3 mailbox driver")
Reported-by: Dan Carpenter <error27 at gmail.com>
Reported-by: kernel test robot <lkp at intel.com>
Closes: https://lore.kernel.org/r/202311300228.1rvmJjdA-lkp@intel.com/
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli at oracle.com>
---
This is only compile tested.
---
 drivers/soc/apple/mailbox.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c
index 780199bf351e..8e8628182ac7 100644
--- a/drivers/soc/apple/mailbox.c
+++ b/drivers/soc/apple/mailbox.c
@@ -289,21 +289,23 @@ struct apple_mbox *apple_mbox_get(struct device *dev, int index)
 
 	ret = of_parse_phandle_with_args(dev->of_node, "mboxes", "#mbox-cells",
 					 index, &args);
-	if (ret || !args.np)
+	if (ret)
 		return ERR_PTR(ret);
+	if (!args.np)
+		return ERR_PTR(-EINVAL);
 
 	pdev = of_find_device_by_node(args.np);
 	of_node_put(args.np);
 
 	if (!pdev)
-		return ERR_PTR(EPROBE_DEFER);
+		return ERR_PTR(-EPROBE_DEFER);
 
 	mbox = platform_get_drvdata(pdev);
 	if (!mbox)
-		return ERR_PTR(EPROBE_DEFER);
+		return ERR_PTR(-EPROBE_DEFER);
 
 	if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER))
-		return ERR_PTR(ENODEV);
+		return ERR_PTR(-ENODEV);
 
 	return mbox;
 }
-- 
2.42.0




More information about the linux-arm-kernel mailing list