[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <b8e2c3ed-7db1-48ca-8dc8-64dfa437c595@foxido.dev>
Date: Fri, 9 Jan 2026 13:57:03 +0300
From: Gladyshev Ilya <foxido@...ido.dev>
To: Miguel Ojeda <miguel.ojeda.sandonis@...il.com>
Cc: Gary Guo <gary@...yguo.net>, "Rafael J. Wysocki" <rafael@...nel.org>,
Len Brown <lenb@...nel.org>, Miguel Ojeda <ojeda@...nel.org>,
Boqun Feng <boqun.feng@...il.com>, Benno Lossin <lossin@...nel.org>,
Andreas Hindborg <a.hindborg@...nel.org>, Alice Ryhl <aliceryhl@...gle.com>,
Trevor Gross <tmgross@...ch.edu>, Danilo Krummrich <dakr@...nel.org>,
Tamir Duberstein <tamird@...il.com>, Armin Wolf <W_Armin@....de>,
platform-driver-x86@...r.kernel.org, linux-kernel@...r.kernel.org,
rust-for-linux@...r.kernel.org, linux-acpi@...r.kernel.org, foxido@...ido.dev
Subject: Re: [PATCH 2/3] rust: implement wrapper for acpi_object
On 1/8/26 21:46, Miguel Ojeda wrote:
>> Using an enum would require keeping Rust's enum synced with the C side,
>> as well as implementing some simple but non-trivial checks that the
>> `type_` field is a valid enum value (and the valid range isn't
>> continuous). I think that keeping it as an integer is simpler and better
>> matches C side.
>
> If this refers to the `ACPI_TYPE_*` constants, there seems to be a
> comment in the C docs that requires it to be kept in sync already with
> elsewhere, so perhaps it could be reasonable to add one more place to
> sync? (Though I don't see the mentioned arrays from a quick grep?)
>
> * NOTE: Types must be kept in sync with the global acpi_ns_properties
> * and acpi_ns_type_names arrays.
>
> [...snip about bindgen...]
If I understand correctly, acpi_object is something untrusted in general
and broken hardware can provide arbitrary _type value. So ergonomics of
enum solution would be kinda strange:
```
type_id() -> Result<Enum> // Result because it can be invalid
// ...
// '?' here makes it look like non-trivial operation
if x.type_id()? == Enum::Buffer
```
And it's unclear should ACPI_TYPE_INVALID be Ok(INVALID) or Err...
Also users of AcpiObject generally doesn't care if received object has
valid, but unexpected type or invalid type, so this conversion int->enum
will introduce (small but) unneeded overhead.
That's why I preferred int-style approach, matching C side. Here is
alternative proposal from my side:
1. Enum with type values like you want
2. This Enum implements .id() method that returns underlying <int>
3. AcpiObject::type_id() still returns <int> value
4. There is method to convert int into enum (like TryFrom)
Probably you can 'newtype' <int> and implement TryFrom AcpiTypeId ->
Enum and write something like
```
match x.type_id().try_into()? /* or as_enum() or smth */ {
Enum::Integer => /* ... */,
Enum::String => /* ... */
}
```
---
Sorry for my chaotic explanations...
Powered by blists - more mailing lists