Skip to content

Commit 09627b5

Browse files
joehattorimehmetb0
authored andcommitted
ACPI: fan: cleanup resources in the error path of .probe()
BugLink: https://bugs.launchpad.net/bugs/2111953 [ Upstream commit c759bc8 ] Call thermal_cooling_device_unregister() and sysfs_remove_link() in the error path of acpi_fan_probe() to fix possible memory leak. This bug was found by an experimental static analysis tool that I am developing. Fixes: 05a83d9 ("ACPI: register ACPI Fan as generic thermal cooling device") Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> Link: https://patch.msgid.link/20241211032812.210164-1-joe@pf.is.s.u-tokyo.ac.jp Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
1 parent 61729da commit 09627b5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/acpi/fan_core.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,19 +367,25 @@ static int acpi_fan_probe(struct platform_device *pdev)
367367
result = sysfs_create_link(&pdev->dev.kobj,
368368
&cdev->device.kobj,
369369
"thermal_cooling");
370-
if (result)
370+
if (result) {
371371
dev_err(&pdev->dev, "Failed to create sysfs link 'thermal_cooling'\n");
372+
goto err_unregister;
373+
}
372374

373375
result = sysfs_create_link(&cdev->device.kobj,
374376
&pdev->dev.kobj,
375377
"device");
376378
if (result) {
377379
dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n");
378-
goto err_end;
380+
goto err_remove_link;
379381
}
380382

381383
return 0;
382384

385+
err_remove_link:
386+
sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
387+
err_unregister:
388+
thermal_cooling_device_unregister(cdev);
383389
err_end:
384390
if (fan->acpi4)
385391
acpi_fan_delete_attributes(device);

0 commit comments

Comments
 (0)