diff mbox series

ACPI: fan: cleanup resources in the error path of .probe()

Message ID 20241203033018.1023827-1-joe@pf.is.s.u-tokyo.ac.jp (mailing list archive)
State Changes Requested, archived
Headers show
Series ACPI: fan: cleanup resources in the error path of .probe() | expand

Commit Message

Joe Hattori Dec. 3, 2024, 3:30 a.m. UTC
Call thermal_cooling_device_unregister() and sysfs_remove_link() in the
error path of acpi_fan_probe() to fix possible memory leak.

Fixes: 05a83d972293 ("ACPI: register ACPI Fan as generic thermal cooling device")
Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
---
 drivers/acpi/fan_core.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Rafael J. Wysocki Dec. 10, 2024, 6:42 p.m. UTC | #1
On Tue, Dec 3, 2024 at 4:30 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.
>
> Fixes: 05a83d972293 ("ACPI: register ACPI Fan as generic thermal cooling device")
> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
> ---
>  drivers/acpi/fan_core.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c
> index 3ea9cfcff46e..8e3f62a3745e 100644
> --- a/drivers/acpi/fan_core.c
> +++ b/drivers/acpi/fan_core.c
> @@ -379,11 +379,14 @@ static int acpi_fan_probe(struct platform_device *pdev)
>                                    "device");
>         if (result) {
>                 dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n");
> -               goto err_end;
> +               goto err_unregister;
>         }
>
>         return 0;
>
> +err_unregister:
> +       sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
> +       thermal_cooling_device_unregister(cdev);
>  err_end:
>         if (fan->acpi4)
>                 acpi_fan_delete_attributes(device);
> --

What if the creation of the "thermal_cooling" symlink fails?
Joe Hattori Dec. 11, 2024, 3:30 a.m. UTC | #2
Hi Rafael,

Thank you for your review.

On 12/11/24 03:42, Rafael J. Wysocki wrote:
> On Tue, Dec 3, 2024 at 4:30 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.
>>
>> Fixes: 05a83d972293 ("ACPI: register ACPI Fan as generic thermal cooling device")
>> Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
>> ---
>>   drivers/acpi/fan_core.c | 5 ++++-
>>   1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c
>> index 3ea9cfcff46e..8e3f62a3745e 100644
>> --- a/drivers/acpi/fan_core.c
>> +++ b/drivers/acpi/fan_core.c
>> @@ -379,11 +379,14 @@ static int acpi_fan_probe(struct platform_device *pdev)
>>                                     "device");
>>          if (result) {
>>                  dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n");
>> -               goto err_end;
>> +               goto err_unregister;
>>          }
>>
>>          return 0;
>>
>> +err_unregister:
>> +       sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
>> +       thermal_cooling_device_unregister(cdev);
>>   err_end:
>>          if (fan->acpi4)
>>                  acpi_fan_delete_attributes(device);
>> --
> 
> What if the creation of the "thermal_cooling" symlink fails?

Should have handled that case as well. Fixed in the V2 patch.

Best,
Joe
diff mbox series

Patch

diff --git a/drivers/acpi/fan_core.c b/drivers/acpi/fan_core.c
index 3ea9cfcff46e..8e3f62a3745e 100644
--- a/drivers/acpi/fan_core.c
+++ b/drivers/acpi/fan_core.c
@@ -379,11 +379,14 @@  static int acpi_fan_probe(struct platform_device *pdev)
 				   "device");
 	if (result) {
 		dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n");
-		goto err_end;
+		goto err_unregister;
 	}
 
 	return 0;
 
+err_unregister:
+	sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
+	thermal_cooling_device_unregister(cdev);
 err_end:
 	if (fan->acpi4)
 		acpi_fan_delete_attributes(device);