summaryrefslogtreecommitdiff
path: root/drivers/soc/apple/mailbox.c
diff options
context:
space:
mode:
authorJohan Hovold <johan@kernel.org>2025-09-26 16:31:31 +0200
committerSven Peter <sven@kernel.org>2025-10-13 18:32:53 +0200
commitf401671e90ccc26b3022f177c4156a429c024f6c (patch)
tree6928691dfe647458589827c485ac7f51d06a3734 /drivers/soc/apple/mailbox.c
parent3a8660878839faadb4f1a6dd72c3179c1df56787 (diff)
soc: apple: mailbox: fix device leak on lookup
Make sure to drop the reference taken to the mbox platform device when looking up its driver data. Note that holding a reference to a device does not prevent its driver data from going away so there is no point in keeping the reference. Fixes: 6e1457fcad3f ("soc: apple: mailbox: Add ASC/M3 mailbox driver") Cc: stable@vger.kernel.org # 6.8 Signed-off-by: Johan Hovold <johan@kernel.org> Reviewed-by: Neal Gompa <neal@gompa.dev> Signed-off-by: Sven Peter <sven@kernel.org>
Diffstat (limited to 'drivers/soc/apple/mailbox.c')
-rw-r--r--drivers/soc/apple/mailbox.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c
index 8f29108dc69a..5c48455185c9 100644
--- a/drivers/soc/apple/mailbox.c
+++ b/drivers/soc/apple/mailbox.c
@@ -302,11 +302,18 @@ struct apple_mbox *apple_mbox_get(struct device *dev, int index)
return ERR_PTR(-EPROBE_DEFER);
mbox = platform_get_drvdata(pdev);
- if (!mbox)
- return ERR_PTR(-EPROBE_DEFER);
+ if (!mbox) {
+ mbox = ERR_PTR(-EPROBE_DEFER);
+ goto out_put_pdev;
+ }
+
+ if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) {
+ mbox = ERR_PTR(-ENODEV);
+ goto out_put_pdev;
+ }
- if (!device_link_add(dev, &pdev->dev, DL_FLAG_AUTOREMOVE_CONSUMER))
- return ERR_PTR(-ENODEV);
+out_put_pdev:
+ put_device(&pdev->dev);
return mbox;
}