public inbox for linux-modules@vger.kernel.org
 help / color / mirror / Atom feed
From: Matthew Wood <thepacketgeek@gmail.com>
To: Miguel Ojeda <ojeda@kernel.org>,
	Luis Chamberlain <mcgrof@kernel.org>,
	Petr Pavlu <petr.pavlu@suse.com>,
	Daniel Gomez <da.gomez@kernel.org>,
	Sami Tolvanen <samitolvanen@google.com>
Cc: "Aaron Tomlin" <atomlin@atomlin.com>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"David Gow" <davidgow@google.com>,
	"José Expósito" <jose.exposito89@gmail.com>,
	linux-modules@vger.kernel.org, rust-for-linux@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/8] samples: rust_minimal: demonstrate string module parameter
Date: Thu, 26 Feb 2026 15:47:29 -0800	[thread overview]
Message-ID: <20260226234736.428341-4-thepacketgeek@gmail.com> (raw)
In-Reply-To: <20260226234736.428341-1-thepacketgeek@gmail.com>

Add a `test_str` string parameter alongside the existing integer
parameter (renamed from `test_parameter` to `test_int` for clarity)
in the rust_minimal sample module.

The init function now prints both parameters to the kernel log,
showing how string parameters are declared, defaulted, and read
back via StringParam::as_cstr().

Also add module-level documentation showing usage via insmod and
kernel command-line with dotted notation.

Signed-off-by: Matthew Wood <thepacketgeek@gmail.com>
---
 samples/rust/rust_minimal.rs | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/samples/rust/rust_minimal.rs b/samples/rust/rust_minimal.rs
index 8eb9583571d7..59955e95e31a 100644
--- a/samples/rust/rust_minimal.rs
+++ b/samples/rust/rust_minimal.rs
@@ -1,6 +1,23 @@
 // SPDX-License-Identifier: GPL-2.0
 
 //! Rust minimal sample.
+//!
+//! This is a sample module written in Rust. It is intended to be a minimal
+//! example of how to write a module in Rust. It does not do anything useful,
+//! except print a message when it is loaded and unloaded.
+//!
+//! It provides examples of how to receive module parameters, which can be provided
+//! by the user when the module is loaded:
+//!
+//! ```
+//! insmod /lib/modules/$(uname -r)/kernel/samples/rust/rust_minimal.ko test_int=2 test_str=world
+//! ```
+//!
+//! or via kernel cmdline with module dotted notation (when built-in and not built as a module):
+//!
+//! ```
+//! ... rust_minimal.test_int=2 rust_minimal.test_str=world ...
+//! ```
 
 use kernel::prelude::*;
 
@@ -11,10 +28,14 @@
     description: "Rust minimal sample",
     license: "GPL",
     params: {
-        test_parameter: i64 {
+        test_int: i64 {
             default: 1,
             description: "This parameter has a default of 1",
         },
+        test_str: string {
+            default: "hello",
+            description: "This parameter has a default of hello",
+        }
     },
 }
 
@@ -26,9 +47,13 @@ impl kernel::Module for RustMinimal {
     fn init(_module: &'static ThisModule) -> Result<Self> {
         pr_info!("Rust minimal sample (init)\n");
         pr_info!("Am I built-in? {}\n", !cfg!(MODULE));
+        pr_info!("test_int: {}\n", *module_parameters::test_int.value());
         pr_info!(
-            "test_parameter: {}\n",
-            *module_parameters::test_parameter.value()
+            "test_str: {}\n",
+            module_parameters::test_str
+                .value()
+                .as_cstr()
+                .expect("test_str has a default value")
         );
 
         let mut numbers = KVec::new();
-- 
2.52.0


  parent reply	other threads:[~2026-02-26 23:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26 23:47 [PATCH 0/8] rust: module parameter extensions Matthew Wood
2026-02-26 23:47 ` [PATCH 1/8] rust: module_param: add StringParam type for C string parameters Matthew Wood
2026-02-28  1:32   ` Miguel Ojeda
2026-03-05 12:47   ` Petr Pavlu
2026-02-26 23:47 ` [PATCH 2/8] rust: module_param: wire StringParam into the module! macro Matthew Wood
2026-03-04  8:13   ` Petr Pavlu
2026-03-09  2:24     ` Matthew Wood
2026-03-06 19:27   ` Sami Tolvanen
2026-03-09  2:27     ` Matthew Wood
2026-02-26 23:47 ` Matthew Wood [this message]
2026-02-26 23:47 ` [PATCH 4/8] rust: module_param: add ObsKernelParam type Matthew Wood
2026-02-26 23:47 ` [PATCH 5/8] rust: module_param: add from_setup_arg() to ModuleParam trait Matthew Wood
2026-02-26 23:47 ` [PATCH 6/8] rust: macros: add early_param support to module! macro Matthew Wood
2026-03-06 17:22   ` Petr Pavlu
2026-02-26 23:47 ` [PATCH 7/8] samples: rust_minimal: demonstrate early_param usage Matthew Wood
2026-02-26 23:47 ` [PATCH 8/8] rust: macros: add configurable initcall levels to module! macro Matthew Wood
2026-02-27 13:27 ` [PATCH 0/8] rust: module parameter extensions Matthew Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260226234736.428341-4-thepacketgeek@gmail.com \
    --to=thepacketgeek@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=aliceryhl@google.com \
    --cc=atomlin@atomlin.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=da.gomez@kernel.org \
    --cc=dakr@kernel.org \
    --cc=davidgow@google.com \
    --cc=gary@garyguo.net \
    --cc=jose.exposito89@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-modules@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=mcgrof@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=petr.pavlu@suse.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=samitolvanen@google.com \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox