* [PATCH 1/2] soc: apple: mailbox: fix device leak on lookup
2025-09-26 14:31 [PATCH 0/2] soc: apple: fix device leak on mbox lookup Johan Hovold
@ 2025-09-26 14:31 ` Johan Hovold
2025-09-26 18:08 ` Markus Elfring
2025-09-26 14:31 ` [PATCH 2/2] soc: apple: sart: drop device reference after lookup Johan Hovold
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ 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] 6+ messages in thread* [PATCH 2/2] soc: apple: sart: drop device reference after lookup
2025-09-26 14:31 [PATCH 0/2] soc: apple: fix device leak on mbox lookup Johan Hovold
2025-09-26 14:31 ` [PATCH 1/2] soc: apple: mailbox: fix device leak on lookup Johan Hovold
@ 2025-09-26 14:31 ` Johan Hovold
2025-10-03 21:43 ` [PATCH 0/2] soc: apple: fix device leak on mbox lookup Neal Gompa
2025-10-13 16:34 ` Sven Peter
3 siblings, 0 replies; 6+ 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
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.
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/soc/apple/sart.c | 13 ++-----------
1 file changed, 2 insertions(+), 11 deletions(-)
diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c
index afa111736899..6952afc41308 100644
--- a/drivers/soc/apple/sart.c
+++ b/drivers/soc/apple/sart.c
@@ -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);
--
2.49.1
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 0/2] soc: apple: fix device leak on mbox lookup
2025-09-26 14:31 [PATCH 0/2] soc: apple: fix device leak on mbox lookup Johan Hovold
2025-09-26 14:31 ` [PATCH 1/2] soc: apple: mailbox: fix device leak on lookup Johan Hovold
2025-09-26 14:31 ` [PATCH 2/2] soc: apple: sart: drop device reference after lookup Johan Hovold
@ 2025-10-03 21:43 ` Neal Gompa
2025-10-13 16:34 ` Sven Peter
3 siblings, 0 replies; 6+ messages in thread
From: Neal Gompa @ 2025-10-03 21:43 UTC (permalink / raw)
To: Johan Hovold; +Cc: Sven Peter, Janne Grunau, asahi, linux-kernel
On Fri, Sep 26, 2025 at 10:31 AM Johan Hovold <johan@kernel.org> wrote:
>
> 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(-)
>
> --
> 2.49.1
>
These patches look reasonable to me.
Reviewed-by: Neal Gompa <neal@gompa.dev>
--
真実はいつも一つ!/ Always, there's only one truth!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] soc: apple: fix device leak on mbox lookup
2025-09-26 14:31 [PATCH 0/2] soc: apple: fix device leak on mbox lookup Johan Hovold
` (2 preceding siblings ...)
2025-10-03 21:43 ` [PATCH 0/2] soc: apple: fix device leak on mbox lookup Neal Gompa
@ 2025-10-13 16:34 ` Sven Peter
3 siblings, 0 replies; 6+ messages in thread
From: Sven Peter @ 2025-10-13 16:34 UTC (permalink / raw)
To: Janne Grunau, Johan Hovold; +Cc: Sven Peter, Neal Gompa, asahi, linux-kernel
On Fri, 26 Sep 2025 16:31:30 +0200, Johan Hovold wrote:
> 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,
--
Sven Peter <sven@kernel.org>
^ permalink raw reply [flat|nested] 6+ messages in thread