Unknown values check in acpi_power_meter
Hi all,
I have a concern about the following construct found in the acpi_power_meter driver:
Quoted 8 lines
/*
* ACPI integers can either be 32-bit or 64-bit wide, so
* we have to check for both values.
*/
static boolacpi_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?
Thanks,
Signature · 2 lines
Jean Delvare SUSE L3 Support
Guenter Roeck
maintainerHi Jean,
Quoted 14 lines · Jean Delvare
Hi all,
I have a concern about the following construct found in the
acpi_power_meterdriver:Quoted 8 lines
/*
* ACPI integers can either be 32-bit or 64-bit wide, so
* we have to check for both values.
*/
static boolacpi_power_meter_is_unknown(u64 val){ return val == U32_MAX || val == U64_MAX; }
Quoted 8 lines
If the implementation is returning 64-bit values on a given system, then only
U64_MAXmeans that a value is unknown;U32_MAXis 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.
If you or anyone else has a better idea, please let me know.
Thanks,
Guenter
Guenter Roeck
maintainerQuoted 31 lines · Guenter Roeck
Hi Jean,
Quoted 14 lines · Jean Delvare
Hi all,
I have a concern about the following construct found in the
acpi_power_meterdriver:Quoted 8 lines
/*
* ACPI integers can either be 32-bit or 64-bit wide, so
* we have to check for both values.
*/
static boolacpi_power_meter_is_unknown(u64 val){
return val ==U32_MAX|| val ==U64_MAX;
}Quoted 8 lines
If the implementation is returning 64-bit values on a given system, then only
U64_MAXmeans that a value is unknown;U32_MAXis 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.
Quoted 5 lines
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-ENODATAonly 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
Am 23.11.26 um 17:23 schrieb Guenter Roeck:
Quoted 36 lines
Hi Jean,
Quoted 14 lines · Jean Delvare
Hi all,
I have a concern about the following construct found in the
acpi_power_meterdriver:Quoted 8 lines
/*
* ACPI integers can either be 32-bit or 64-bit wide, so
* we have to check for both values.
*/
static boolacpi_power_meter_is_unknown(u64 val){
return val ==U32_MAX|| val ==U64_MAX;
}Quoted 8 lines
If the implementation is returning 64-bit values on a given system, then only
U64_MAXmeans that a value is unknown;U32_MAXis 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-ENODATAonly if the power is exactly 4,294,967,295 mW, which I found to be an acceptable trade-off.
Quoted 6 lines
If you or anyone else has a better idea, please let me know.
Thanks,
Guenter
Hi,
if i remember correctly then the ACPI spec says that the results are 32-bit integers, so they should newer exceed U32_MAX. We only check for U64_MAX because some 64-bit ACPI firmware is using the 64-bit Ones contant (0xFFFFFFFFFFFFFFFF) without masking the upper 32 bits.
Thanks,
Armin Wolf