Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH 1/2] soc: apple: mailbox: fix device leak on lookup
       [not found] <20250926143132.6419-1-johan@kernel.org>
@ 2025-09-26 14:31 ` Johan Hovold
  2025-09-26 18:08   ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2025-09-26 14:31 UTC (permalink / raw)
  To: Sven Peter, Janne Grunau
  Cc: Neal Gompa, asahi, linux-kernel, Johan Hovold, stable

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>
---
 drivers/soc/apple/mailbox.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c
index 49a0955e82d6..1685da1da23d 100644
--- a/drivers/soc/apple/mailbox.c
+++ b/drivers/soc/apple/mailbox.c
@@ -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;
 }
-- 
2.49.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/2] soc: apple: mailbox: fix device leak on lookup
  2025-09-26 14:31 ` [PATCH 1/2] soc: apple: mailbox: fix device leak on lookup Johan Hovold
@ 2025-09-26 18:08   ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2025-09-26 18:08 UTC (permalink / raw)
  To: Johan Hovold, asahi; +Cc: stable, LKML, Janne Grunau, Neal Gompa, Sven Peter

> Make sure to drop the reference taken to the mbox platform device when
> looking up its driver data.
…

How do you think about to increase the application of scope-based resource management?
https://elixir.bootlin.com/linux/v6.17-rc7/source/include/linux/device.h#L1180
https://elixir.bootlin.com/linux/v6.17-rc7/source/include/linux/of.h#L138

Regards,
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-09-26 18:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250926143132.6419-1-johan@kernel.org>
2025-09-26 14:31 ` [PATCH 1/2] soc: apple: mailbox: fix device leak on lookup Johan Hovold
2025-09-26 18:08   ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox