From: sashiko-bot@kernel.org
To: "Rafael J. Wysocki" <rafael@kernel.org>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v1] hwmon: (acpi_power_meter) Check ACPI_COMPANION() against NULL
Date: Wed, 13 May 2026 00:10:00 +0000 [thread overview]
Message-ID: <20260513001000.F0800C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <5068745.GXAFRqVoOG@rafael.j.wysocki>
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
prev parent reply other threads:[~2026-05-13 0:10 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260513001000.F0800C2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox