Re: [RFC PATCH] rust: hwmon: add basic hwmon abstractions

From: Guenter Roeck

Date: Tue May 12 2026 - 12:34:07 EST


On 5/12/26 08:57, Donjuanplatinum wrote:
Add a minimal Rust abstraction for the Hardware Monitoring (hwmon)
subsystem.

Currently, this abstraction supports a Minimum Viable Product (MVP) scope:
registering a single temperature sensor with the read-only `temp1_input`
attribute. Support for multi-channel, additional sensor types, and
writable attributes is deferred to future patches to keep this initial
foundation reviewable.

The primary architectural challenge in wrapping hwmon is initializing
`struct hwmon_chip_info`, which requires stable, self-referential
pointers to nested NULL-terminated arrays. Instead of relying on complex
macro generation for static allocation, this implementation leverages
a single heap allocation (`KBox`). It safely wires the self-referential
raw pointers using unaliased `&raw mut` during the allocation's
exclusive ownership phase, and then securely seals it by pinning
(`Pin::new_unchecked`).

For resource management, this implementation uses standard Rust RAII
(calling `hwmon_device_unregister` in `Drop`) rather than `devm_`
variants, ensuring natural drop ordering and avoiding complex C-side
trampolines for generic types.

Signed-off-by: Donjuanplatinum <donplat@xxxxxxxxxxxxx>

Sorry, rust support in the hardware monitoring subsystem will have to wait
for someone else to pick up maintainership.

Guenter