Skip to content

Commit 02f1a59

Browse files
LiHuiSong1groeck
authored andcommitted
hwmon: (acpi_power_meter) Fix update the power trip points on failure
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>
1 parent 7532e68 commit 02f1a59

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/hwmon/acpi_power_meter.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,24 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
293293
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
294294
struct acpi_device *acpi_dev = to_acpi_device(dev);
295295
struct acpi_power_meter_resource *resource = acpi_dev->driver_data;
296+
unsigned long temp, trip_bk;
296297
int res;
297-
unsigned long temp;
298298

299299
res = kstrtoul(buf, 10, &temp);
300300
if (res)
301301
return res;
302302

303303
temp = DIV_ROUND_CLOSEST(temp, 1000);
304304

305-
mutex_lock(&resource->lock);
305+
guard(mutex)(&resource->lock);
306+
307+
trip_bk = resource->trip[attr->index - 7];
306308
resource->trip[attr->index - 7] = temp;
307309
res = set_acpi_trip(resource);
308-
mutex_unlock(&resource->lock);
309-
310-
if (res)
310+
if (res) {
311+
resource->trip[attr->index - 7] = trip_bk;
311312
return res;
313+
}
312314

313315
return count;
314316
}

0 commit comments

Comments
 (0)