Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Jean Delvare <jdelvare@suse.de>, linux-hwmon@vger.kernel.org
Subject: Re: Unknown values check in acpi_power_meter
Date: Mon, 23 Nov 2026 08:28:24 -0800	[thread overview]
Message-ID: <47778357-5449-41a4-9def-e539653b97aa@roeck-us.net> (raw)
In-Reply-To: <f248e88c-e328-4118-9282-09f6829ebcc7@roeck-us.net>

On 11/23/26 08:23, Guenter Roeck wrote:
> Hi Jean,
> 
> On 11/23/26 02:06, Jean Delvare wrote:
>> Hi all,
>>
>> I have a concern about the following construct found in the
>> acpi_power_meter driver:
>>
>>> /*
>>>   * ACPI integers can either be 32-bit or 64-bit wide, so
>>>   * we have to check for both values.
>>>   */
>>> static bool acpi_power_meter_is_unknown(u64 val)
>>> {
>>>     return val == U32_MAX || val == U64_MAX;
>>> }
>>
>> If the implementation is returning 64-bit values on a given system,
>> then only U64_MAX means that a value is unknown; U32_MAX is a regular
>> number as any other and should not be handled as an error case.
>>
>> Don't we have a way to figure out whether a given ACPI integer object
>> is a 32-bit or 64-bit value, and only compare the result with the one
>> appropriate special value which means unknown for that integer size?
>>
> 
> I didn't like it either, but I asked Google search. There is
> acpi_gbl_integer_byte_width, but it is not exported. It recommends
> to use the above code for modules. I don't know of a different
> mechanism.
> 
> In practice, the value is checked for properties which should never
> be even close to U32_MAX, except for the power value. For power it
> returns -ENODATA only if the power is exactly 4,294,967,295 mW,
> which I found to be an acceptable trade-off.
> 

Actually, this didn't really change for the power attribute when I
introduced the above code:

-       if (ret ||
-           resource->power == UNKNOWN_POWER_32 ||
-           resource->power == UNKNOWN_POWER_64)
+       if (ret || acpi_power_meter_is_unknown(resource->power))

...

-               if (res->power == UNKNOWN_POWER_32 || res->power == UNKNOWN_POWER_64)
+               if (acpi_power_meter_is_unknown(res->power))

It appears that the original driver author was aware of the problem and
didn't know a better method either.

Thanks,
Guenter


      reply	other threads:[~2026-11-23 16:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 10:06 Unknown values check in acpi_power_meter Jean Delvare
2026-11-23 16:23 ` Guenter Roeck
2026-11-23 16:28   ` Guenter Roeck [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=47778357-5449-41a4-9def-e539653b97aa@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=jdelvare@suse.de \
    --cc=linux-hwmon@vger.kernel.org \
    /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