Re: [PATCH v2 2/3] rust: configfs: introduce rust support for configfs
From: Andreas Hindborg
Date: Mon Feb 17 2025 - 06:09:16 EST
"Charalampos Mitrodimas" <charmitro@xxxxxxxxxx> writes:
> Andreas Hindborg <a.hindborg@xxxxxxxxxx> writes:
>
>> diff --git a/samples/rust/rust_configfs.rs b/samples/rust/rust_configfs.rs
>> new file mode 100644
>> index 0000000000000..fe896e66efb41
>> --- /dev/null
>> +++ b/samples/rust/rust_configfs.rs
>> @@ -0,0 +1,186 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +
>> +//! Rust configfs sample.
>> +
>> +use kernel::alloc::flags;
>> +use kernel::c_str;
>
> [...snip...]
>
>> +impl Configuration {
>> + fn new() -> impl PinInit<Self, Error> {
>> + try_pin_init!(Self {
>> + message: c_str!("Hello World\n"),
>> + bar <- new_mutex!((KBox::new([0;4096], flags::GFP_KERNEL)?,0)),
>> + })
>> + }
>> +}
>> +
>> +impl kernel::InPlaceModule for RustConfigfs {
>> + fn init(_module: &'static ThisModule) -> impl PinInit<Self, Error> {
>> + pr_info!("Rust configfs sample (init)\n");
>> +
>> + let item_type = configfs_attrs! {
>> + container: configfs::Subsystem<Configuration>,
>> + data: Configuration,
>> + child: Child,
>> + attributes: [
>> + message: 0,
>> + bar: 1,
>> + ],
>> + };
>> +
>> + try_pin_init!(Self {
>> + config <- configfs::Subsystem::new(
>> + kernel::c_str!("rust_configfs"), item_type, Configuration::new()
>
> Hi Andreas,
>
> One more nit I found, "kernel::c_str" is already imported in the
> sample. So this can be changed to "c_str!("rust_configfs")".
Thanks!
Best regards,
Andreas Hindborg