macintosh: windfarm_core: fix reference leak on failed device registration
Subsystems (2)
PATCH 1/1 macintosh: windfarm_core: fix reference leak on failed device registration
When platform_device_register() fails in windfarm_core_init(), the embedded struct device in wf_platform_device has already been initialized by device_initialize(), but the failure path does not drop the device reference for the current platform device:
windfarm_core_init()
platform_device_register(&wf_platform_device)
device_initialize(&wf_platform_device.dev) setup_pdev_dma_masks(&wf_platform_device) return platform_device_add(&wf_platform_device)
This leads to a reference leak when platform_device_register() fails. Fix this by checking the return value and calling platform_device_put().
The issue was identified by a static analysis tool I developed and confirmed by manual review.
--- drivers/macintosh/windfarm_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/macintosh/windfarm_core.c +6 -1
@@ -436,9 +436,14 @@ EXPORT_SYMBOL_GPL(wf_clear_overtemp);static int __init windfarm_core_init (void ) { +int err; +DBG ("wf: core loaded\n" ); -platform_device_register (&wf_platform_device); + err =platform_device_register (&wf_platform_device); +if (err) +platform_device_put (&wf_platform_device); +return 0 ; }
Signature · 1 line
2.43.0
Hi,
Please disregard this patch.
Quoted 46 lines · Guangshuo Li
When
platform_device_register()fails inwindfarm_core_init(), the embedded struct device inwf_platform_devicehas already been initialized bydevice_initialize(), but the failure path does not drop the device reference for the current platform device:
windfarm_core_init()
platform_device_register(&wf_platform_device)
device_initialize(&wf_platform_device.dev)setup_pdev_dma_masks(&wf_platform_device)returnplatform_device_add(&wf_platform_device)This leads to a reference leak when
platform_device_register()fails. Fix this by checking the return value and callingplatform_device_put().The issue was identified by a static analysis tool I developed and confirmed by manual review.
Fixes 75722d3992f57 ("[PATCH] ppc64: Thermal control for SMU based machines")Signed-off-by Guangshuo Li <[email protected]>--- drivers/macintosh/windfarm_core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)drivers/macintosh/windfarm_core.c +6
-2@@ -436,9 +436,14 @@ EXPORT_SYMBOL_GPL(wf_clear_overtemp);static int __init windfarm_core_init (void ) { +int err; +DBG ("wf: core loaded\n" ); -platform_device_register (&wf_platform_device); + err =platform_device_register (&wf_platform_device); +if (err) +platform_device_put (&wf_platform_device); +return 0 ; } --
Quoted 2 lines
2.43.0
After re-checking it, wf_platform_device is a static platform_device and it does not provide a dev.release callback. Therefore calling platform_device_put() on the platform_device_register() failure path is not appropriate here and can trigger the missing release callback warning.
This falls into the same static platform_device pattern pointed out in the other reviews, so I will drop this patch.
Sorry for the noise.
Best regards,
Guangshuo Li