Re: [PATCH v4 3/3] rust: Add SoC Driver Sample
From: Matthew Maurer
Date: Sat Dec 27 2025 - 13:49:37 EST
On Sat, Dec 27, 2025 at 7:53 AM Kari Argillander
<kari.argillander@xxxxxxxxx> wrote:
>
> On Fri, 26 Dec 2025 at 22:18, Matthew Maurer <mmaurer@xxxxxxxxxx> wrote:
>
> > + fn probe(
> > + pdev: &platform::Device<Core>,
> > + _info: Option<&Self::IdInfo>,
> > + ) -> impl PinInit<Self, Error> {
> > + let dev = pdev.as_ref();
> > +
> > + dev_dbg!(dev, "Probe Rust SoC driver sample.\n");
> > +
> > + let pdev = pdev.into();
> > + pin_init_scope(move || {
> > + let machine = CString::try_from(c"My cool ACME15 dev board")?;
> > + let family = CString::try_from(c"ACME")?;
> > + let revision = CString::try_from(c"1.2")?;
> > + let serial_number = CString::try_from(c"12345")?;
> > + let soc_id = CString::try_from(c"ACME15")?;
> > +
> > + let attr = soc::Attributes {
> > + machine: Some(machine),
> > + family: Some(family),
> > + revision: Some(revision),
> > + serial_number: Some(serial_number),
> > + soc_id: Some(soc_id),
> > + };
>
> To me it seems little bit awkward that all needs to be CStrings. Maybe something
> like this could be used (basically cow)
>
> ```rust
> pub enum AttrStr {
> Static(&'static CStr),
> Owned(CString),
> None,
> }
> ```
>
> This will also take out Option with same time. Then some nice ergonomic way
> to use this. This is suggestion and I have nothing to do with soc layer.
IMO something like this should not be a SoC-specific special type.
Feel free to propose a `CowCStr` in `kernel::str`, or adding the more
general `Cow` and appropriate trait definitions to `kernel::alloc`,
and we could modify the API in the future. Basically, this seems like
a suggestion for a new vocabulary type rather than something for SoC.
We could technically also do a many-parameter'd struct and put `:
Deref<Target=CStr>` bounds on everything, but putting 6 type
parameters on something, which would then need explicit resolution
when `None` was used, seems potentially worse ergonomically.
>
> Argillander