hwmon: (acpi_power_meter) Fix the fake power alarm reporting
authorHuisong Li <lihuisong@huawei.com>
Thu, 20 Feb 2025 03:08:32 +0000 (11:08 +0800)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 2 Mar 2025 18:31:26 +0000 (10:31 -0800)
We encountered a problem that a fake power alarm is reported to
user on the platform unsupported notifications at the second step
below:
1> Query 'power1_alarm' attribute when the power capping occurs.
2> Query 'power1_alarm' attribute when the power capping is over
   and the current average power is less then power cap value.

The root cause is that the resource->power_alarm is set to true
at the first step. And power meter use this old value to show
the power alarm state instead of the current the comparison value.

Signed-off-by: Huisong Li <lihuisong@huawei.com>
Link: https://lore.kernel.org/r/20250220030832.2976-1-lihuisong@huawei.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/acpi_power_meter.c

index 44afb07409a465b9762a537aa9960c667884a87c..f05986e4f3792acd67a74aa46deb7bd7ada74353 100644 (file)
@@ -437,9 +437,13 @@ static ssize_t show_val(struct device *dev,
                        ret = update_cap(resource);
                        if (ret)
                                return ret;
+                       resource->power_alarm = resource->power > resource->cap;
+                       val = resource->power_alarm;
+               } else {
+                       val = resource->power_alarm ||
+                                resource->power > resource->cap;
+                       resource->power_alarm = resource->power > resource->cap;
                }
-               val = resource->power_alarm || resource->power > resource->cap;
-               resource->power_alarm = resource->power > resource->cap;
                break;
        case 7:
        case 8: