Skip to content

hwmon: (acpi_power_meter) Fix locking and unknown value handling

Guenter Roeck linux-hwmon 1 version New

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 0 repliesNew

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3hwmon: (acpi_power_meter) Fix missing locking in sysfs show callbacks and resumedrivers/hwmon/acpi_power_meter.c+29 -10 replies
2/3hwmon: (acpi_power_meter) Prevent spurious power alarm when power is unknowndrivers/hwmon/acpi_power_meter.c+14 -140 replies
3/3hwmon: (acpi_power_meter) Check for 32-bit and 64-bit unknown ACPI valuesdrivers/hwmon/acpi_power_meter.c+34 -150 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/3] hwmon: (acpi_power_meter) Fix locking and unknown value handling

Sashiko identified a number of issues in the acpi_power_meter driver. I used gemini-3-carbon to analyze the bug reports and to implement fixes. Subsequently, I used Sashiko again to review the fixes. This series is the result of this effort.

This series fixes locking races and incomplete handling of ACPI unknown sentinel values in the acpi_power_meter hwmon driver:

1. Fix missing locking in sysfs show callbacks and system resume. acpi_power_meter_resume() frees and reallocates capability strings without holding resource->lock, racing with concurrent METER_NOTIFY_CONFIG notifications (and sysfs readers when the freezer is disabled). In addition, the extra sysfs show callbacks read capability strings, capability integers, and 64-bit trip points without acquiring res->lock, exposing torn or uncommitted trip values when racing with set_trip(). Acquire resource->lock in resume and in all extra sysfs show callbacks, and return -ENODATA if a capability string pointer is NULL.

2. Prevent spurious power alarms when power is unknown.
When _PMM returns an unknown sentinel (U32_MAX or U64_MAX), update_meter() stores it in resource->power and returns 0, causing get_power_alarm_state() to evaluate resource->power > resource->cap as true and report a false alarm. Convert get_power_alarm_state() to return a boolean alarm state so reading power1_alarm never returns an error code, preserve and clear any latched METER_NOTIFY_CAPPING notification when notifications are supported, and otherwise report 0 (no alarm) when readings fail or power is unknown.

3. Check for both 32-bit and 64-bit unknown ACPI values across attributes. ACPI Power Meter objects report unknown or unavailable integer values as all-ones (U32_MAX or U64_MAX depending on DSDT revision), but most attributes in the driver either only checked 32-bit 0xffffffff or did not check for unknown sentinels at all. Introduce acpi_power_meter_is_unknown() and use it to return -ENODATA for unknown non-alarm numeric hwmon attributes, emit "unknown" in power1_cap_hyst_show() and power1_accuracy_show(), avoid comparing against an unknown cap in get_power_alarm_state(), and skip jiffies caching in update_meter() when sampling_time is unknown.

----------------------------------------------------------------
Guenter Roeck (3):
hwmon: (acpi_power_meter) Fix missing locking in sysfs show callbacks and resume
hwmon: (acpi_power_meter) Prevent spurious power alarm when power is unknown
hwmon: (acpi_power_meter) Check for 32-bit and 64-bit unknown ACPI values

 drivers/hwmon/acpi_power_meter.c | 101 ++++++++++++++++++++++++++++-----------
 1 file changed, 74 insertions(+), 27 deletions(-)