Message ID | 20241211032812.210164-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive) |
---|---|
State | In Next |
Delegated to: | Rafael Wysocki |
Headers | show |
Series | [v2] ACPI: fan: cleanup resources in the error path of .probe() | expand |
On Wed, Dec 11, 2024 at 4:28 AM Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> wrote: > > 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: 05a83d972293 ("ACPI: register ACPI Fan as generic thermal cooling device") > Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> > --- > Changes in V2: > - Handle the case when the "thermal_cooling" symlink creation fails. > --- > drivers/acpi/fan_core.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c > index 3ea9cfcff46e..10016f52f4f4 100644 > --- a/drivers/acpi/fan_core.c > +++ b/drivers/acpi/fan_core.c > @@ -371,19 +371,25 @@ static int acpi_fan_probe(struct platform_device *pdev) > result = sysfs_create_link(&pdev->dev.kobj, > &cdev->device.kobj, > "thermal_cooling"); > - if (result) > + if (result) { > dev_err(&pdev->dev, "Failed to create sysfs link 'thermal_cooling'\n"); > + goto err_unregister; > + } > > result = sysfs_create_link(&cdev->device.kobj, > &pdev->dev.kobj, > "device"); > if (result) { > dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n"); > - goto err_end; > + goto err_remove_link; > } > > return 0; > > +err_remove_link: > + sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling"); > +err_unregister: > + thermal_cooling_device_unregister(cdev); > err_end: > if (fan->acpi4) > acpi_fan_delete_attributes(device); > -- Applied as 6.14 material, thanks!
diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c index 3ea9cfcff46e..10016f52f4f4 100644 --- a/drivers/acpi/fan_core.c +++ b/drivers/acpi/fan_core.c @@ -371,19 +371,25 @@ static int acpi_fan_probe(struct platform_device *pdev) result = sysfs_create_link(&pdev->dev.kobj, &cdev->device.kobj, "thermal_cooling"); - if (result) + if (result) { dev_err(&pdev->dev, "Failed to create sysfs link 'thermal_cooling'\n"); + goto err_unregister; + } result = sysfs_create_link(&cdev->device.kobj, &pdev->dev.kobj, "device"); if (result) { dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n"); - goto err_end; + goto err_remove_link; } return 0; +err_remove_link: + sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling"); +err_unregister: + thermal_cooling_device_unregister(cdev); err_end: if (fan->acpi4) acpi_fan_delete_attributes(device);
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: 05a83d972293 ("ACPI: register ACPI Fan as generic thermal cooling device") Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> --- Changes in V2: - Handle the case when the "thermal_cooling" symlink creation fails. --- drivers/acpi/fan_core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)