diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 383c7029d3cee04b60fa3de395cad5b683e7cf8c..2fe83c126914b725701b2e9ed95ee3b69649a5a9 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -856,6 +856,30 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .notify = thermal_notify, }; +static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz) +{ + int ret; + ret = sysfs_create_link(&tz->device->dev.kobj, + &tz->thermal_zone->device.kobj, "thermal_zone"); + + if (ret) + return ret; + + ret = sysfs_create_link(&tz->thermal_zone->device.kobj, + &tz->device->dev.kobj, "device"); + + if (ret) + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); + + return ret; +} + +static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz) +{ + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); + sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); +} + static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) { int trips = 0; @@ -889,32 +913,32 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (IS_ERR(tz->thermal_zone)) return -ENODEV; - result = sysfs_create_link(&tz->device->dev.kobj, - &tz->thermal_zone->device.kobj, "thermal_zone"); - if (result) - return result; - - result = sysfs_create_link(&tz->thermal_zone->device.kobj, - &tz->device->dev.kobj, "device"); + result = acpi_thermal_zone_sysfs_add(tz); if (result) return result; status = acpi_bus_attach_private_data(tz->device->handle, - tz->thermal_zone); - if (ACPI_FAILURE(status)) - return -ENODEV; + tz->thermal_zone); + if (ACPI_FAILURE(status)) { + result = -ENODEV; + goto remove_links; + } tz->tz_enabled = 1; dev_info(&tz->device->dev, "registered as thermal_zone%d\n", tz->thermal_zone->id); return 0; + +remove_links: + acpi_thermal_zone_sysfs_remove(tz); + + return result; } static void acpi_thermal_unregister_thermal_zone(struct acpi_thermal *tz) { - sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); - sysfs_remove_link(&tz->thermal_zone->device.kobj, "device"); + acpi_thermal_zone_sysfs_remove(tz); thermal_zone_device_unregister(tz->thermal_zone); tz->thermal_zone = NULL; acpi_bus_detach_private_data(tz->device->handle);