soc: apple: mailbox: fix error handling in apple_mbox_get()

Message ID 20240122180117.2862027-1-harshit.m.mogalapalli@oracle.com
State New
Headers
Series soc: apple: mailbox: fix error handling in apple_mbox_get() |

Commit Message

Harshit Mogalapalli Jan. 22, 2024, 6:01 p.m. UTC
  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@gmail.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/r/202311300228.1rvmJjdA-lkp@intel.com/
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
---
This is only compile tested.
---
 drivers/soc/apple/mailbox.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
  

Patch

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;
 }