Skip to content

Commit 1fefca6

Browse files
Wer-Wolfgroeck
authored andcommitted
hwmon: (acpi_power_meter) Fix 4.29 MW bug
The ACPI specification says: "If an error occurs while obtaining the meter reading or if the value is not available then an Integer with all bits set is returned" Since the "integer" is 32 bits in case of the ACPI power meter, userspace will get a power reading of 2^32 * 1000 miliwatts (~4.29 MW) in case of such an error. This was discovered due to a lm_sensors bugreport (lm-sensors/lm-sensors#460). Fix this by returning -ENODATA instead. Tested-by: <[email protected]> Fixes: de584af ("hwmon driver for ACPI 4.0 power meters") Signed-off-by: Armin Wolf <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 58ebe7f commit 1fefca6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/hwmon/acpi_power_meter.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define POWER_METER_CAN_NOTIFY (1 << 3)
3232
#define POWER_METER_IS_BATTERY (1 << 8)
3333
#define UNKNOWN_HYSTERESIS 0xFFFFFFFF
34+
#define UNKNOWN_POWER 0xFFFFFFFF
3435

3536
#define METER_NOTIFY_CONFIG 0x80
3637
#define METER_NOTIFY_TRIP 0x81
@@ -348,6 +349,9 @@ static ssize_t show_power(struct device *dev,
348349
update_meter(resource);
349350
mutex_unlock(&resource->lock);
350351

352+
if (resource->power == UNKNOWN_POWER)
353+
return -ENODATA;
354+
351355
return sprintf(buf, "%llu\n", resource->power * 1000);
352356
}
353357

0 commit comments

Comments
 (0)