[PATCH v2 0/2] rust: Add abstractions for applying devicetree overlays

Ayush Singh posted 2 patches 1 month, 2 weeks ago
rust/bindings/bindings_helper.h |  1 +
rust/helpers/of.c               |  5 +++++
rust/kernel/device/property.rs  | 18 ++++++++++++++++
rust/kernel/of.rs               | 46 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 70 insertions(+)
[PATCH v2 0/2] rust: Add abstractions for applying devicetree overlays
Posted by Ayush Singh 1 month, 2 weeks ago
The following patch series adds abstractions required to apply
devicetree overlays from Rust code. To see how the bindings look in
usage, see my working tree [0] for a connector driver  I am working on.

Open Questions
***************

1. Removing overlay on drop

I my usecase (see [0]), I will only ever have 1 active overlay in the
driver, which I will be removing dynamically. So removing overlay on
drop works for it. But maybe there are some usecases I am missing.

2. Only enable bindings when CONFIG_OF_OVERLAY is set?

The kernel header currently seems to provide blank implementations of
these methods when `CONFIG_OF_OVERLAY` is not enabled. But I am not sure
what is rust-for-linux policy here.

Best Regards,
Ayush Singh

[0]: https://github.com/Ayush1325/linux/commits/beagle-cape-v2/

Changes in v2:
- Rebase on next-20250814
- Return error if buffer size too big instead of panic.
- Update the reference driver link.
- Use `to_of_node` on fwnode instead of getting of_node directly from
  struct device.
- Link to v1: https://lore.kernel.org/r/20250422-rust-overlay-abs-v1-0-85779c1b853d@beagleboard.org/

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
---
Ayush Singh (2):
      rust: kernel: of: Add DeviceNode abstraction
      rust: kernel: of: Add overlay id abstraction

 rust/bindings/bindings_helper.h |  1 +
 rust/helpers/of.c               |  5 +++++
 rust/kernel/device/property.rs  | 18 ++++++++++++++++
 rust/kernel/of.rs               | 46 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 70 insertions(+)
---
base-commit: 931e46dcbc7e6035a90e9c4a27a84b660e083f0a
change-id: 20250417-rust-overlay-abs-36aac8b9752a

Best regards,
-- 
Ayush Singh <ayush@beagleboard.org>
Re: [PATCH v2 0/2] rust: Add abstractions for applying devicetree overlays
Posted by Miguel Ojeda 1 month, 2 weeks ago
On Sat, Aug 16, 2025 at 7:58 AM Ayush Singh <ayush@beagleboard.org> wrote:
>
> The kernel header currently seems to provide blank implementations of
> these methods when `CONFIG_OF_OVERLAY` is not enabled. But I am not sure
> what is rust-for-linux policy here.

In general, if a kernel feature/API has stubs that do nothing when not
configured, i.e. the API is always present (typically to simplify
callers), then it is likely the Rust side should also be available
unconditionally for similar reasons. We had a similar discussion
around debugfs recently.

Cheers,
Miguel