Re: [PATCH 1/5] rust: of: add Node type

From: Albert Esteve

Date: Tue Aug 18 2026 - 03:21:07 EST


On Mon, Aug 17, 2026 at 5:18 PM Rob Herring <robh@xxxxxxxxxx> wrote:
>
> On Mon, Aug 17, 2026 at 01:40:46PM +0200, Albert Esteve wrote:
> > Add a Rust abstraction for `struct device_node`, the device
> > tree node type.
> >
> > `Node` wraps `device_node` type pointer and implements
> > `AlwaysRefCounted`, allowing owned references to device
> > tree nodes to be held. To do so, add C helpers to make
> > them always accesible from Rust bindings, independently
> > from the configuration.
>
> struct device_node being refcounted is a kconfig option
> (CONFIG_OF_DYNAMIC). What happens when that is disabled?

With CONFIG_OF_DYNAMIC=n, both refcount methods (inc_ref and dec_ref)
become no-ops. Same as with C code.

Since Bindgen does not generate bindings to inline functions, the
helper functions ensure that bindings::of_node_get/put are generated.
Otherwise it would fail to compile when CONFIG_OF_DYNAMIC is disabled.

>
> > This abstraction is needed for subsequent patches, in particular
> > for creating drm_panel instances from a `const struct device_node`
> > pointer argument.
>
> My intent is to make struct device_node opaque. We may never get there
> with C code, but please make sure Rust is that way from the start.

Got it. I will reduce the visibility of the raw pointer accessors by
making them pub(crate) for the next version. These are the only
accessors added in this series. Future methods accessing struct fields
for 'Node' will have to rely on C accessor functions.

BR,
Albert.

>
> Rob
>