* [PATCH v1] hwmon: (acpi_power_meter) Check ACPI_COMPANION() against NULL
@ 2026-05-11 19:54 Rafael J. Wysocki
2026-05-12 18:32 ` Guenter Roeck
2026-05-13 0:10 ` sashiko-bot
0 siblings, 2 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2026-05-11 19:54 UTC (permalink / raw)
To: Guenter Roeck; +Cc: linux-hwmon, LKML, Linux ACPI, Andy Shevchenko, Linux PM
From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
Every platform driver can be forced to match a device that doesn't match
its list of device IDs because of device_match_driver_override(), so
platform drivers that rely on the existence of a device's ACPI companion
object need to verify its presence.
Accordingly, add a requisite ACPI_COMPANION() check against NULL to the
acpi_power_meter hwmon driver.
Fixes: afc6c4aedea5 ("hwmon: (acpi_power_meter) Convert ACPI driver to a platform one")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/hwmon/acpi_power_meter.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -884,10 +884,14 @@ static void acpi_power_meter_notify(acpi
static int acpi_power_meter_probe(struct platform_device *pdev)
{
- struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
struct acpi_power_meter_resource *resource;
+ struct acpi_device *device;
int res;
+ device = ACPI_COMPANION(&pdev->dev);
+ if (!device)
+ return -ENODEV;
+
resource = kzalloc_obj(*resource);
if (!resource)
return -ENOMEM;
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v1] hwmon: (acpi_power_meter) Check ACPI_COMPANION() against NULL
2026-05-11 19:54 [PATCH v1] hwmon: (acpi_power_meter) Check ACPI_COMPANION() against NULL Rafael J. Wysocki
@ 2026-05-12 18:32 ` Guenter Roeck
2026-05-13 0:10 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: Guenter Roeck @ 2026-05-12 18:32 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: linux-hwmon, LKML, Linux ACPI, Andy Shevchenko, Linux PM
On Mon, May 11, 2026 at 09:54:51PM +0200, Rafael J. Wysocki wrote:
> From: "Rafael J. Wysocki" <rafael.j.wysocki@intel.com>
>
> Every platform driver can be forced to match a device that doesn't match
> its list of device IDs because of device_match_driver_override(), so
> platform drivers that rely on the existence of a device's ACPI companion
> object need to verify its presence.
>
> Accordingly, add a requisite ACPI_COMPANION() check against NULL to the
> acpi_power_meter hwmon driver.
>
> Fixes: afc6c4aedea5 ("hwmon: (acpi_power_meter) Convert ACPI driver to a platform one")
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v1] hwmon: (acpi_power_meter) Check ACPI_COMPANION() against NULL
2026-05-11 19:54 [PATCH v1] hwmon: (acpi_power_meter) Check ACPI_COMPANION() against NULL Rafael J. Wysocki
2026-05-12 18:32 ` Guenter Roeck
@ 2026-05-13 0:10 ` sashiko-bot
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-05-13 0:10 UTC (permalink / raw)
To: Rafael J. Wysocki; +Cc: linux-hwmon
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] Subsystem Guideline Violation / Data Race: Missing and incorrect locking for extra attributes.
- [High] Subsystem Guideline Violation: Integer overflow in DIV_ROUND_CLOSEST bypasses boundary checks.
- [High] Subsystem Guideline Violation: Integer truncation during 64-bit power calculations.
--
commit 20d683b13caf3ad1f2da04d46b6d0bb7dff30a02
Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
hwmon: (acpi_power_meter) Check ACPI_COMPANION() against NULL
Every platform driver can be forced to match a device that doesn't match
its list of device IDs because of device_match_driver_override(), so
platform drivers that rely on the existence of a device's ACPI companion
object need to verify its presence.
> diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
> index be7f702dcde9c..0c9b9f4180fb7 100644
> --- a/drivers/hwmon/acpi_power_meter.c
> +++ b/drivers/hwmon/acpi_power_meter.c
> @@ -884,10 +884,14 @@ static void acpi_power_meter_notify(acpi_handle handle, u32 event, void *data)
>
> static int acpi_power_meter_probe(struct platform_device *pdev)
> {
> - struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
> struct acpi_power_meter_resource *resource;
> + struct acpi_device *device;
> int res;
>
> + device = ACPI_COMPANION(&pdev->dev);
> + if (!device)
> + return -ENODEV;
> +
> resource = kzalloc_obj(*resource);
> if (!resource)
> return -ENOMEM;
These might not be regressions introduced by the new code, but the hwmon
subsystem guidelines explicitly mandate that drivers must implement locking
required for attributes registered by any other means, and should use
hwmon_lock() and hwmon_unlock() for this purpose.
Does this sysfs show function read the 64-bit res->trip array without
acquiring any locks?
drivers/hwmon/acpi_power_meter.c:power1_average_min_show() {
...
if (res->trip[POWER_METER_TRIP_AVERAGE_MIN_IDX] < 0)
return sysfs_emit(buf, "unknown\n");
return sysfs_emit(buf, "%lld\n",
res->trip[POWER_METER_TRIP_AVERAGE_MIN_IDX] * 1000);
}
On 32-bit architectures, can this lead to torn reads and expose corrupted
states to userspace if updated concurrently via store operations?
Also, is it incorrect to use the driver's own mutex_lock(&res->lock) instead
of the required hwmon_lock() API?
drivers/hwmon/acpi_power_meter.c:power1_average_min_store() {
...
mutex_lock(&res->lock);
ret = set_trip(res, POWER_METER_TRIP_AVERAGE_MIN_IDX, trip);
mutex_unlock(&res->lock);
...
}
Can these DIV_ROUND_CLOSEST macros overflow the integer width and wrap around
to a very small number if a mistakenly large value is provided?
drivers/hwmon/acpi_power_meter.c:set_trip() {
...
trip = DIV_ROUND_CLOSEST(trip, 1000);
...
}
drivers/hwmon/acpi_power_meter.c:set_cap() {
...
cap = DIV_ROUND_CLOSEST(cap, 1000);
...
}
Since the macro evaluates using the expression x + 500, does this silently
bypass boundary checks like min_cap and incorrectly program the underlying
ACPI hardware limits?
Finally, could the multiplication of the 64-bit attribute res->power
(measured in milliwatts) by 1000 severely overflow the 32-bit bound on 32-bit
architectures?
drivers/hwmon/acpi_power_meter.c:power_meter_read() {
...
case hwmon_power_average:
...
*val = res->power * 1000;
break;
...
}
Since *val is a long capable of representing up to ~2.14 billion on 32-bit
systems, can a power consumption of 3000 Watts result in returning
fundamentally incorrect, negative numbers to userspace due to the lack of
overflow clamping or checks?
--
Sashiko AI review · https://sashiko.dev/#/patchset/5068745.GXAFRqVoOG@rafael.j.wysocki?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-13 0:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11 19:54 [PATCH v1] hwmon: (acpi_power_meter) Check ACPI_COMPANION() against NULL Rafael J. Wysocki
2026-05-12 18:32 ` Guenter Roeck
2026-05-13 0:10 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox