Commit e13f16ab authored by Huisong Li's avatar Huisong Li Committed by Lifeng Zheng
Browse files

hwmon: (acpi_power_meter) Fix update the power trip points on failure

mainline inclusion
from mainline-v6.13-rc2
commit 02f1a5911550bd6b39526d18282b10d441e04ed1
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBVB4K
CVE: NA

Reference: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=02f1a5911550bd6b39526d18282b10d441e04ed1



--------------------------------------------------------------------

The power trip points maintained in local should not be updated when '_PTP'
method fails to evaluate.

Signed-off-by: default avatarHuisong Li <lihuisong@huawei.com>
Link: https://lore.kernel.org/r/20250109081708.27366-3-lihuisong@huawei.com


Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarXinghai Cen <cenxinghai@h-partners.com>
parent 67891a7f
Loading
Loading
Loading
Loading
+7 −5
Original line number Diff line number Diff line
@@ -293,8 +293,8 @@ 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)
@@ -302,13 +302,15 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,

	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;
}