]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
soc: apple: mailbox: fix device leak on lookup
authorJohan Hovold <johan@kernel.org>
Fri, 26 Sep 2025 14:31:31 +0000 (16:31 +0200)
committerSven Peter <sven@kernel.org>
Mon, 13 Oct 2025 16:32:53 +0000 (18:32 +0200)
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>
drivers/soc/apple/mailbox.c

index 8f29108dc69ac964236121d439e86c923a441265..5c48455185c9baed7a6bd8638e939d0a931bde25 100644 (file)
@@ -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;
 }