Skip to contentSkip to conversation

hwmon: (acpi_power_meter) Fix 18.45 TW bug

PATCH Applied Armin Wolf 3 participants 4 messages Oct 6 – Oct 19 Hardware monitoring

lore
Share & tools
lore

Armin Wolf

author
#0 lore raw

PATCH 1/1 hwmon: (acpi_power_meter) Fix 18.45 TW 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"

This integer can also be 64-bit wide on ACPI 2.0 and later systems, so we have to check for that too.

Compile-tested only.

Fixes 1fefca6c57fb ("hwmon: (acpi_power_meter) Fix 4.29 MW bug")
---
 drivers/hwmon/acpi_power_meter.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/hwmon/acpi_power_meter.c +8 -2
index d8e871509405..3891962f03db 100644
@@ -10,6 +10,7 @@
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
 #include <linux/jiffies.h>
+#include <linux/limits.h>
 #include <linux/mutex.h>
 #include <linux/dmi.h>
 #include <linux/slab.h>
@@ -30,7 +31,12 @@
 #define POWER_METER_CAN_NOTIFY	(1 << 3)
 #define POWER_METER_IS_BATTERY	(1 << 8)
 #define UNKNOWN_HYSTERESIS	0xFFFFFFFF
-#define UNKNOWN_POWER		0xFFFFFFFF
+/*
+ * ACPI integers can either be 32-bit or 64-bit wide, so
+ * we have to check for both values.
+ */
+#define UNKNOWN_POWER_32	U32_MAX
+#define UNKNOWN_POWER_64	U64_MAX
 
 #define METER_NOTIFY_CONFIG	0x80
 #define METER_NOTIFY_TRIP	0x81
@@ -452,7 +458,7 @@ static int power_meter_read(struct device *dev, enum hwmon_sensor_types type,
 		ret = update_meter(res);
 		if (ret)
 			return ret;
-		if (res->power == UNKNOWN_POWER)
+		if (res->power == UNKNOWN_POWER_32 || res->power == UNKNOWN_POWER_64)
 			return -ENODATA;
 		*val = res->power * 1000;
 		break;
Signature · 1 line
2.55.0
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 8 lines

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"

This integer can also be 64-bit wide on ACPI 2.0 and later systems, so we have to check for that too.

Quoted 6 lines

Compile-tested only.

Fixes 1fefca6c57fb ("hwmon: (acpi_power_meter) Fix 4.29 MW bug")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw
In reply to Armin Wolf
Quoted 8 lines · Armin Wolf

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"

This integer can also be 64-bit wide on ACPI 2.0 and later systems, so we have to check for that too.

Quoted 6 lines

Compile-tested only.

Fixes 1fefca6c57fb ("hwmon: (acpi_power_meter) Fix 4.29 MW bug")

Applied.

Thanks,
Guenter

author
#3 lore raw

Am 19.10.26 um 22:53 schrieb Guenter Roeck:

Quoted 11 lines · Armin Wolf
Quoted 10 lines

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"

This integer can also be 64-bit wide on ACPI 2.0 and later systems, so we have to check for that too.

Compile-tested only.

Quoted 8 lines
Quoted 4 lines
Fixes 1fefca6c57fb ("hwmon: (acpi_power_meter) Fix 4.29 MW bug")

Applied.

Thanks,
Guenter

Thank you :)