Re: [PATCH] drm: sti: fix device leaks at component probe
From: Raphaël Gallais-Pou
Date: Mon Nov 03 2025 - 13:57:21 EST
Le Mon, Sep 22, 2025 at 06:16:47PM +0200, Markus Elfring a écrit :
> > Make sure to drop the references taken to the vtg devices by
>
> VTG device?
Video Timing Generator. This IP creates a vsync pulse and synchonize
the components together.
>
>
> > of_find_device_by_node() when looking up their driver data during
> > component probe.
> …
>
> 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
Oh... I wasn't aware of this. FWIU it is a way to directly free an
allocated memory whenever a variable goes out of scope using the cleanup
attribute.
IMO this is also a clever solution to prevent the memory leak, and it
would be a shorter patch. So basically, instead of calling put_device()
as Johan did, you would suggest something like this ?
diff --git i/drivers/gpu/drm/sti/sti_vtg.c w/drivers/gpu/drm/sti/sti_vtg.c
index ee81691b3203..5193196d9291 100644
--- i/drivers/gpu/drm/sti/sti_vtg.c
+++ w/drivers/gpu/drm/sti/sti_vtg.c
@@ -142,7 +142,7 @@ struct sti_vtg {
struct sti_vtg *of_vtg_find(struct device_node *np)
{
- struct platform_device *pdev;
+ struct platform_device *pdev __free(put_device) = NULL;
Best regards,
Raphaël
>
> Can a summary phrase like “Prevent device leak in of_vtg_find()” be nicer?
>
> Regards,
> Markus