Skip to content

Commit

Permalink
hwmon: (acpi_power_meter) Fix update the power trip points on failure
Browse files Browse the repository at this point in the history
The power trip points maintained in local should not be updated when '_PTP'
method fails to evaluate.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Link: https://lore.kernel.org/r/20250109081708.27366-3-lihuisong@huawei.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Huisong Li authored and Guenter Roeck committed Jan 9, 2025
1 parent 7532e68 commit 02f1a59
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions drivers/hwmon/acpi_power_meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,22 +293,24 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct acpi_device *acpi_dev = to_acpi_device(dev);
struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
unsigned long temp, trip_bk;
int res;
unsigned long temp;

res = kstrtoul(buf, 10, &temp);
if (res)
return res;

temp = DIV_ROUND_CLOSEST(temp, 1000);

mutex_lock(&resource->lock);
guard(mutex)(&resource->lock);

trip_bk = resource->trip[attr->index - 7];
resource->trip[attr->index - 7] = temp;
res = set_acpi_trip(resource);
mutex_unlock(&resource->lock);

if (res)
if (res) {
resource->trip[attr->index - 7] = trip_bk;
return res;
}

return count;
}
Expand Down

0 comments on commit 02f1a59

Please sign in to comment.