Skip to content

Commit c759bc8

Browse files
joehattorirafaeljw
authored andcommitted
ACPI: fan: cleanup resources in the error path of .probe()
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>
1 parent 78d4f34 commit c759bc8

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
@@ -371,19 +371,25 @@ static int acpi_fan_probe(struct platform_device *pdev)
371371
result = sysfs_create_link(&pdev->dev.kobj,
372372
&cdev->device.kobj,
373373
"thermal_cooling");
374-
if (result)
374+
if (result) {
375375
dev_err(&pdev->dev, "Failed to create sysfs link 'thermal_cooling'\n");
376+
goto err_unregister;
377+
}
376378

377379
result = sysfs_create_link(&cdev->device.kobj,
378380
&pdev->dev.kobj,
379381
"device");
380382
if (result) {
381383
dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n");
382-
goto err_end;
384+
goto err_remove_link;
383385
}
384386

385387
return 0;
386388

389+
err_remove_link:
390+
sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
391+
err_unregister:
392+
thermal_cooling_device_unregister(cdev);
387393
err_end:
388394
if (fan->acpi4)
389395
acpi_fan_delete_attributes(device);

0 commit comments

Comments
 (0)