Re: [RFC PATCH v8 3/4] rust: add minimal IIO subsystem abstractions

From: Andy Shevchenko

Date: Thu Dec 03 2026 - 05:53:43 EST


On Tue, Dec 01, 2026 at 11:55:07PM +0700, Muchamad Coirul Anwar wrote:
> Add minimal Rust abstractions needed to register direct-mode IIO
> devices exposing read_raw channel information.
>
> Provide a type-safe IioChanInfo selector, IioVal return types, and an
> IioDriver trait. Add a C callback trampoline that validates the channel
> information selector, invokes the Rust driver, and converts IioVal into
> the representation expected by the IIO core.
>
> Use typestate to distinguish unregistered and registered devices.
> Registration is unsafe because callers must not leak the returned device
> (e.g. via mem::forget). It returns an owned registered device bound to
> the parent lifetime, whose destructor unregisters it before destroying
> its Rust private data and releasing the allocation reference.
>
> Allow private data to borrow resources tied to the bound parent
> lifetime. This lets drivers capture bus-specific resources during probe
> and use them directly from subsystem callbacks without recovering them
> from a generic parent device.
>
> Accept only INDIO_DIRECT_MODE. Other modes require additional state and
> teardown handling not provided by this initial abstraction.
>
> The initial abstraction intentionally supports read_raw only. It does
> not expose write_raw, buffers, triggers, events, extended attributes, or
> available-value attributes.

...

> --- a/rust/bindings/bindings_helper.h
> +++ b/rust/bindings/bindings_helper.h
> @@ -64,6 +64,8 @@
> #include <linux/fwctl.h>
> #include <linux/fs.h>
> #include <linux/i2c.h>

> +#include <linux/iio/iio.h>

> +#include <linux/iio/types.h>

No need, this is separated header, but it's rarely needed standalone. iio.h
guarantees that it will provide necessary types.

> #include <linux/interrupt.h>
> #include <linux/io-pgtable.h>
> #include <linux/ioport.h>

I would like somebody to revisit this rather cumbersome list of headers here
and try to balance them for not including implied ones (yes, this is more
a guesswork, but feel free to Cc Joshua Crofts and me on the discussion mail
you can start with this matter).

--
With Best Regards,
Andy Shevchenko