2020-06-26 17:38:58

by Andrzej Pietrasiewicz

[permalink] [raw]
Subject: [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function

The acpi_thermal_register_thermal_zone() is missing any error handling.
This needs to be fixed.

Signed-off-by: Andrzej Pietrasiewicz <[email protected]>
Reviewed-by: Guenter Roeck <[email protected]>
Reviewed-by: Bartlomiej Zolnierkiewicz <[email protected]>
---
drivers/acpi/thermal.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 19067a5e5293..6de8066ca1e7 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -901,23 +901,35 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
result = sysfs_create_link(&tz->device->dev.kobj,
&tz->thermal_zone->device.kobj, "thermal_zone");
if (result)
- return result;
+ goto unregister_tzd;

result = sysfs_create_link(&tz->thermal_zone->device.kobj,
&tz->device->dev.kobj, "device");
if (result)
- return result;
+ goto remove_tz_link;

status = acpi_bus_attach_private_data(tz->device->handle,
tz->thermal_zone);
- if (ACPI_FAILURE(status))
- return -ENODEV;
+ if (ACPI_FAILURE(status)) {
+ result = -ENODEV;
+ goto remove_dev_link;
+ }

tz->tz_enabled = 1;

dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
tz->thermal_zone->id);
+
return 0;
+
+remove_dev_link:
+ sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
+remove_tz_link:
+ sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
+unregister_tzd:
+ thermal_zone_device_unregister(tz->thermal_zone);
+
+ return result;
}

static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
--
2.17.1


2020-06-29 21:09:31

by Amit Kucheria

[permalink] [raw]
Subject: Re: [PATCH v5 01/11] acpi: thermal: Fix error handling in the register function

On Fri, Jun 26, 2020 at 11:08 PM Andrzej Pietrasiewicz
<[email protected]> wrote:
>
> The acpi_thermal_register_thermal_zone() is missing any error handling.
> This needs to be fixed.
>
> Signed-off-by: Andrzej Pietrasiewicz <[email protected]>
> Reviewed-by: Guenter Roeck <[email protected]>
> Reviewed-by: Bartlomiej Zolnierkiewicz <[email protected]>

Reviewed-by: Amit Kucheria <[email protected]>


> ---
> drivers/acpi/thermal.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
> index 19067a5e5293..6de8066ca1e7 100644
> --- a/drivers/acpi/thermal.c
> +++ b/drivers/acpi/thermal.c
> @@ -901,23 +901,35 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz)
> result = sysfs_create_link(&tz->device->dev.kobj,
> &tz->thermal_zone->device.kobj, "thermal_zone");
> if (result)
> - return result;
> + goto unregister_tzd;
>
> result = sysfs_create_link(&tz->thermal_zone->device.kobj,
> &tz->device->dev.kobj, "device");
> if (result)
> - return result;
> + goto remove_tz_link;
>
> status = acpi_bus_attach_private_data(tz->device->handle,
> tz->thermal_zone);
> - if (ACPI_FAILURE(status))
> - return -ENODEV;
> + if (ACPI_FAILURE(status)) {
> + result = -ENODEV;
> + goto remove_dev_link;
> + }
>
> tz->tz_enabled = 1;
>
> dev_info(&tz->device->dev, "registered as thermal_zone%d\n",
> tz->thermal_zone->id);
> +
> return 0;
> +
> +remove_dev_link:
> + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device");
> +remove_tz_link:
> + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone");
> +unregister_tzd:
> + thermal_zone_device_unregister(tz->thermal_zone);
> +
> + return result;
> }
>
> static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz)
> --
> 2.17.1
>