Re: [PATCH v2 2/3] rust: configfs: introduce rust support for configfs

From: Charalampos Mitrodimas
Date: Sun Feb 16 2025 - 11:13:13 EST


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")".

C. Mitrodimas

> + ),
> + })
> + }
> +}
> +