soc: apple: fix device leak on mbox lookup
Subsystems (2)
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
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.
--- drivers/soc/apple/mailbox.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/soc/apple/mailbox.c +11 -4
@@ -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
Re: [PATCH 1/2] soc: apple: mailbox: fix device leak on lookup
Quoted 2 lines
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
PATCH 2/2 soc: apple: sart: drop device reference after lookup
In reply to Johan HovoldHolding 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
@@ -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
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!
Sven Peter
maintainerQuoted 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]>