Skip to contentSkip to conversation

soc: apple: fix device leak on mbox lookup

PATCH In review Johan Hovold 4 participants 6 messages Sep 26, 2025 – Oct 13, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover soc: apple: fix device leak on mbox lookup

This series fixes a device reference leak when looking up mboxes and simplifies the sart lookup by dropping the corresponding reference sooner.

Johan

Johan Hovold (2):
soc: apple: mailbox: fix device leak on lookup
soc: apple: sart: drop device reference after lookup

 drivers/soc/apple/mailbox.c | 15 +++++++++++----
 drivers/soc/apple/sart.c    | 13 ++-----------
 2 files changed, 13 insertions(+), 15 deletions(-)
Signature · 1 line
2.49.1
#1 lore raw

PATCH 1/2 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")
---
 drivers/soc/apple/mailbox.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/soc/apple/mailbox.c +11 -4
index 49a0955e82d6..1685da1da23d 100644
@@ -299,11 +299,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;
 }
Signature · 1 line
2.49.1
#3 lore raw

PATCH 2/2 soc: apple: sart: drop device reference after lookup

In reply to Johan Hovold

Holding a reference to a device does not prevent its driver data from going away so there is no point in keeping the reference after looking up the sart device.

---
 drivers/soc/apple/sart.c | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)
drivers/soc/apple/sart.c +2 -11
index afa111736899..6952afc41308 100644
@@ -164,17 +164,11 @@ static int apple_sart_probe(struct platform_device *pdev)
 	return 0;
 }
 
-static void apple_sart_put_device(void *dev)
-{
-	put_device(dev);
-}
-
 struct apple_sart *devm_apple_sart_get(struct device *dev)
 {
 	struct device_node *sart_node;
 	struct platform_device *sart_pdev;
 	struct apple_sart *sart;
-	int ret;
 
 	sart_node = of_parse_phandle(dev->of_node, "apple,sart", 0);
 	if (!sart_node)
@@ -192,14 +186,11 @@ struct apple_sart *devm_apple_sart_get(struct device *dev)
 		return ERR_PTR(-EPROBE_DEFER);
 	}
 
-	ret = devm_add_action_or_reset(dev, apple_sart_put_device,
-				       &sart_pdev->dev);
-	if (ret)
-		return ERR_PTR(ret);
-
 	device_link_add(dev, &sart_pdev->dev,
 			DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE_SUPPLIER);
 
+	put_device(&sart_pdev->dev);
+
 	return sart;
 }
 EXPORT_SYMBOL_GPL(devm_apple_sart_get);
Signature · 1 line
2.49.1
reviewer Reviewed-by on the v1 series
#4 lore raw
In reply to Johan Hovold
Quoted 12 lines · Johan Hovold

This series fixes a device reference leak when looking up mboxes and simplifies the sart lookup by dropping the corresponding reference sooner.

Johan

Johan Hovold (2):
soc: apple: mailbox: fix device leak on lookup
soc: apple: sart: drop device reference after lookup

Quoted 7 lines
 drivers/soc/apple/mailbox.c | 15 +++++++++++----
 drivers/soc/apple/sart.c    | 13 ++-----------
 2 files changed, 13 insertions(+), 15 deletions(-)

--
2.49.1

These patches look reasonable to me.

Signature · 1 line
真実はいつも一つ!/ Always, there's only one truth!
maintainer
#5 lore raw
In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

This series fixes a device reference leak when looking up mboxes and simplifies the sart lookup by dropping the corresponding reference sooner.

Johan

[...]

Applied to local tree (apple-soc/drivers-6.19), thanks!

[1/2] soc: apple: mailbox: fix device leak on lookup

      https://github.com/AsahiLinux/linux/commit/f401671e90cc

[2/2] soc: apple: sart: drop device reference after lookup
https://github.com/AsahiLinux/linux/commit/f95f3bceade2

Best regards,

Signature · 1 line
Sven Peter <[email protected]>